gg-mysql-connector 1.0.24 → 1.0.26

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.
@@ -33,6 +33,7 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
33
33
  TABLE_NAME: string;
34
34
  DATA_TYPE: string;
35
35
  }[] | null;
36
+ isConnected: boolean;
36
37
  constructor(DBInfo: DatabaseConfigInterface);
37
38
  createDatabaseIfNotExist(tempConnection: mysql.Connection): Promise<void>;
38
39
  selectBySearchTextInRow(tableName: string, textToSearch: string): Promise<mysql.RowDataPacket[]>;
@@ -65,6 +66,7 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
65
66
  loadColumnListToCache(): Promise<void>;
66
67
  getColumnList(tableName: string): Promise<string[]>;
67
68
  getColumnFullList(tableName: string): Promise<mysql.RowDataPacket[]>;
69
+ waitUntilInitSuccess(interval: number): Promise<unknown>;
68
70
  query<T>(statment: string, parameter?: any[], isPrint?: boolean): Promise<T | QueryResult>;
69
71
  private printResultLength;
70
72
  }
@@ -20,6 +20,7 @@ class GGMySQLConnector {
20
20
  this.tableAndViewNameList = [];
21
21
  this.columnAndTableListCache = null;
22
22
  this.DBInfo = DBInfo;
23
+ this.isConnected = false;
23
24
  }
24
25
  async createDatabaseIfNotExist(tempConnection) {
25
26
  const currentDatabaseName = this.DBInfo.database;
@@ -215,6 +216,7 @@ class GGMySQLConnector {
215
216
  user: this.DBInfo.user,
216
217
  password: this.DBInfo.password,
217
218
  });
219
+ this.isConnected = true;
218
220
  await this.createDatabaseIfNotExist(currentConnection);
219
221
  // await currentConnection.end()
220
222
  this.connection = mysql2_1.default.createConnection(Object.assign({}, this.DBInfo));
@@ -242,7 +244,21 @@ class GGMySQLConnector {
242
244
  const result = (await this.query(`SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '${this.DBInfo.database}' AND TABLE_NAME = '${tableName}'`, undefined, false));
243
245
  return result;
244
246
  }
247
+ waitUntilInitSuccess(interval) {
248
+ console.log("wait for database connection . . .");
249
+ return new Promise((resolve, reject) => {
250
+ setTimeout(() => {
251
+ if (this.isConnected === false) {
252
+ this.waitUntilInitSuccess(interval);
253
+ }
254
+ else {
255
+ return resolve(true);
256
+ }
257
+ }, interval);
258
+ });
259
+ }
245
260
  async query(statment, parameter, isPrint) {
261
+ await this.waitUntilInitSuccess(1000);
246
262
  return new Promise((resolve, reject) => {
247
263
  const uniqueTime = `${(0, crypto_1.randomUUID)()} ${statment}`;
248
264
  console.time(uniqueTime);
@@ -10,11 +10,13 @@ export default class ModelGenerator {
10
10
  model: MyModel[];
11
11
  dbInfo: DatabaseConfigInterface;
12
12
  connection: mysql.Connection;
13
+ isConnected: boolean;
13
14
  constructor(dbInfo: DatabaseConfigInterface, model: MyModel[]);
14
15
  init(): Promise<void>;
15
16
  private createDatabaseIfNotExist;
16
17
  pushModelToDB(): Promise<void>;
17
18
  pushViewToDB(viewDirectory: string): Promise<void>;
19
+ waitUntilInitSuccess(interval: number): Promise<unknown>;
18
20
  query<T>(statment: string, parameter?: any[], isPrint?: boolean): Promise<T>;
19
21
  private printResultLength;
20
22
  getTableNameList(): Promise<string[]>;
@@ -21,6 +21,7 @@ class ModelGenerator {
21
21
  };
22
22
  this.model = model;
23
23
  this.dbInfo = dbInfo;
24
+ this.isConnected = false;
24
25
  }
25
26
  async init() {
26
27
  console.log("init");
@@ -29,6 +30,7 @@ class ModelGenerator {
29
30
  user: this.dbInfo.user,
30
31
  password: this.dbInfo.password,
31
32
  });
33
+ this.isConnected = true;
32
34
  await this.createDatabaseIfNotExist();
33
35
  }
34
36
  async createDatabaseIfNotExist() {
@@ -44,7 +46,21 @@ class ModelGenerator {
44
46
  const migrator = new MyDBMigration_1.default(this);
45
47
  await migrator.migrateView(viewDirectory);
46
48
  }
49
+ waitUntilInitSuccess(interval) {
50
+ console.log("wait for database connection . . .");
51
+ return new Promise((resolve, reject) => {
52
+ setTimeout(() => {
53
+ if (this.isConnected === false) {
54
+ this.waitUntilInitSuccess(interval);
55
+ }
56
+ else {
57
+ return resolve(true);
58
+ }
59
+ }, interval);
60
+ });
61
+ }
47
62
  async query(statment, parameter, isPrint) {
63
+ await this.waitUntilInitSuccess(1000);
48
64
  return new Promise((resolve, reject) => {
49
65
  const uniqueTime = `${(0, crypto_1.randomUUID)()} ${statment}`;
50
66
  console.time(uniqueTime);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gg-mysql-connector",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -59,12 +59,14 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
59
59
  columnAndTableListCache:
60
60
  | { COLUMN_NAME: string; TABLE_NAME: string; DATA_TYPE: string }[]
61
61
  | null
62
+ isConnected: boolean
62
63
 
63
64
  constructor(DBInfo: DatabaseConfigInterface) {
64
65
  this.isPrintStatement = false
65
66
  this.tableAndViewNameList = []
66
67
  this.columnAndTableListCache = null
67
68
  this.DBInfo = DBInfo
69
+ this.isConnected = false
68
70
  }
69
71
  async createDatabaseIfNotExist(
70
72
  tempConnection: mysql.Connection
@@ -354,6 +356,7 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
354
356
  user: this.DBInfo.user,
355
357
  password: this.DBInfo.password,
356
358
  })
359
+ this.isConnected = true
357
360
  await this.createDatabaseIfNotExist(currentConnection)
358
361
  // await currentConnection.end()
359
362
 
@@ -401,12 +404,25 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
401
404
  )) as mysql.RowDataPacket[]
402
405
  return result
403
406
  }
407
+ waitUntilInitSuccess(interval: number) {
408
+ console.log("wait for database connection . . .")
409
+ return new Promise((resolve, reject) => {
410
+ setTimeout(() => {
411
+ if (this.isConnected === false) {
412
+ this.waitUntilInitSuccess(interval)
413
+ } else {
414
+ return resolve(true)
415
+ }
416
+ }, interval)
417
+ })
418
+ }
404
419
 
405
420
  async query<T>(
406
421
  statment: string,
407
422
  parameter?: any[],
408
423
  isPrint?: boolean
409
424
  ): Promise<T | QueryResult> {
425
+ await this.waitUntilInitSuccess(1000)
410
426
  return new Promise((resolve, reject) => {
411
427
  const uniqueTime = `${randomUUID()} ${statment}`
412
428
  console.time(uniqueTime)
@@ -16,9 +16,11 @@ export default class ModelGenerator {
16
16
  model: MyModel[]
17
17
  dbInfo: DatabaseConfigInterface
18
18
  connection!: mysql.Connection
19
+ isConnected: boolean
19
20
  constructor(dbInfo: DatabaseConfigInterface, model: MyModel[]) {
20
21
  this.model = model
21
22
  this.dbInfo = dbInfo
23
+ this.isConnected = false
22
24
  }
23
25
  async init() {
24
26
  console.log("init")
@@ -27,6 +29,7 @@ export default class ModelGenerator {
27
29
  user: this.dbInfo.user,
28
30
  password: this.dbInfo.password,
29
31
  })
32
+ this.isConnected = true
30
33
  await this.createDatabaseIfNotExist()
31
34
  }
32
35
  private async createDatabaseIfNotExist() {
@@ -43,12 +46,25 @@ export default class ModelGenerator {
43
46
  const migrator = new MyDBMigration(this)
44
47
  await migrator.migrateView(viewDirectory)
45
48
  }
49
+ waitUntilInitSuccess(interval: number) {
50
+ console.log("wait for database connection . . .")
51
+ return new Promise((resolve, reject) => {
52
+ setTimeout(() => {
53
+ if (this.isConnected === false) {
54
+ this.waitUntilInitSuccess(interval)
55
+ } else {
56
+ return resolve(true)
57
+ }
58
+ }, interval)
59
+ })
60
+ }
46
61
 
47
62
  async query<T>(
48
63
  statment: string,
49
64
  parameter?: any[],
50
65
  isPrint?: boolean
51
66
  ): Promise<T> {
67
+ await this.waitUntilInitSuccess(1000)
52
68
  return new Promise((resolve, reject) => {
53
69
  const uniqueTime = `${randomUUID()} ${statment}`
54
70
  console.time(uniqueTime)