gg-mysql-connector 1.0.24 → 1.0.25

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;
@@ -242,7 +243,21 @@ class GGMySQLConnector {
242
243
  const result = (await this.query(`SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '${this.DBInfo.database}' AND TABLE_NAME = '${tableName}'`, undefined, false));
243
244
  return result;
244
245
  }
246
+ waitUntilInitSuccess(interval) {
247
+ console.log("wait for database connection . . .");
248
+ return new Promise((resolve, reject) => {
249
+ setTimeout(() => {
250
+ if (this.isConnected === false) {
251
+ this.waitUntilInitSuccess(interval);
252
+ }
253
+ else {
254
+ return resolve(true);
255
+ }
256
+ }, interval);
257
+ });
258
+ }
245
259
  async query(statment, parameter, isPrint) {
260
+ await this.waitUntilInitSuccess(1000);
246
261
  return new Promise((resolve, reject) => {
247
262
  const uniqueTime = `${(0, crypto_1.randomUUID)()} ${statment}`;
248
263
  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.25",
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
@@ -401,12 +403,25 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
401
403
  )) as mysql.RowDataPacket[]
402
404
  return result
403
405
  }
406
+ waitUntilInitSuccess(interval: number) {
407
+ console.log("wait for database connection . . .")
408
+ return new Promise((resolve, reject) => {
409
+ setTimeout(() => {
410
+ if (this.isConnected === false) {
411
+ this.waitUntilInitSuccess(interval)
412
+ } else {
413
+ return resolve(true)
414
+ }
415
+ }, interval)
416
+ })
417
+ }
404
418
 
405
419
  async query<T>(
406
420
  statment: string,
407
421
  parameter?: any[],
408
422
  isPrint?: boolean
409
423
  ): Promise<T | QueryResult> {
424
+ await this.waitUntilInitSuccess(1000)
410
425
  return new Promise((resolve, reject) => {
411
426
  const uniqueTime = `${randomUUID()} ${statment}`
412
427
  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)