@onurege3467/zerohelper 4.1.1 → 4.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/database/newMySQL/index.js +31 -11
- package/package.json +1 -1
|
@@ -12,23 +12,43 @@ class MySQLDatabase {
|
|
|
12
12
|
* @param {number} [config.connectionLimit]
|
|
13
13
|
*/
|
|
14
14
|
constructor(config) {
|
|
15
|
-
this.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
this.config = config;
|
|
16
|
+
|
|
17
|
+
this.poolPromise = (async () => {
|
|
18
|
+
// İlk bağlantıyı veritabanı adı olmadan kur
|
|
19
|
+
const connection = await mysql.createConnection({
|
|
20
|
+
host: config.host,
|
|
21
|
+
port: config.port || 3306,
|
|
22
|
+
user: config.user,
|
|
23
|
+
password: config.password
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Veritabanı yoksa oluştur
|
|
27
|
+
await connection.query(`CREATE DATABASE IF NOT EXISTS \`${config.database}\``);
|
|
28
|
+
await connection.end();
|
|
29
|
+
|
|
30
|
+
// Artık veritabanı ile birlikte pool oluştur
|
|
31
|
+
return mysql.createPool({
|
|
32
|
+
host: config.host,
|
|
33
|
+
port: config.port || 3306,
|
|
34
|
+
user: config.user,
|
|
35
|
+
password: config.password,
|
|
36
|
+
database: config.database,
|
|
37
|
+
waitForConnections: true,
|
|
38
|
+
connectionLimit: config.connectionLimit || 10,
|
|
39
|
+
queueLimit: 0,
|
|
40
|
+
});
|
|
41
|
+
})();
|
|
25
42
|
}
|
|
43
|
+
|
|
26
44
|
|
|
27
45
|
// Genel sorgu çalıştırma (select, insert, update, delete, vs.)
|
|
28
46
|
async query(sql, params = []) {
|
|
29
|
-
const
|
|
47
|
+
const pool = await this.poolPromise;
|
|
48
|
+
const [rows] = await pool.execute(sql, params);
|
|
30
49
|
return rows;
|
|
31
50
|
}
|
|
51
|
+
|
|
32
52
|
|
|
33
53
|
async ensureTable(table, data) {
|
|
34
54
|
// Tablo adını escape et
|