@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.
@@ -12,23 +12,43 @@ class MySQLDatabase {
12
12
  * @param {number} [config.connectionLimit]
13
13
  */
14
14
  constructor(config) {
15
- this.pool = mysql.createPool({
16
- host: config.host,
17
- port: config.port || 3306,
18
- user: config.user,
19
- password: config.password,
20
- database: config.database,
21
- waitForConnections: true,
22
- connectionLimit: config.connectionLimit || 10,
23
- queueLimit: 0,
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 [rows, fields] = await this.pool.execute(sql, params);
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onurege3467/zerohelper",
3
- "version": "4.1.1",
3
+ "version": "4.1.3",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "node test.js"