gg-mysql-connector 1.0.87 → 1.0.89

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.
@@ -36,6 +36,7 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
36
36
  }[] | null;
37
37
  isConnected: boolean;
38
38
  constructor(DBInfo: DatabaseConfigInterface);
39
+ selectByDateRange<T extends keyof Main>(tableName: T extends string ? T : string, params: object): Promise<Main[T][]>;
39
40
  createDatabaseIfNotExist(tempConnection: mysql.Connection): Promise<void>;
40
41
  selectBySearchTextInRow(tableName: string, textToSearch: string): Promise<mysql.RowDataPacket[]>;
41
42
  loadTableAndViewNameList(): Promise<string[]>;
@@ -22,6 +22,9 @@ class GGMySQLConnector {
22
22
  this.DBInfo = DBInfo;
23
23
  this.isConnected = false;
24
24
  }
25
+ selectByDateRange(tableName, params) {
26
+ throw new Error("Method not implemented.");
27
+ }
25
28
  async createDatabaseIfNotExist(tempConnection) {
26
29
  const currentDatabaseName = this.DBInfo.database;
27
30
  console.log("currentDatabaseName", currentDatabaseName);
@@ -11,6 +11,7 @@ export default class ModelGenerator {
11
11
  dbInfo: DatabaseConfigInterface;
12
12
  connection: mysql.Connection;
13
13
  isConnected: boolean;
14
+ isForcePrintSQLStatement: boolean;
14
15
  constructor(dbInfo: DatabaseConfigInterface, model: MyModel[]);
15
16
  init(): Promise<void>;
16
17
  private createDatabaseIfNotExist;
@@ -23,6 +23,7 @@ class ModelGenerator {
23
23
  this.model = model;
24
24
  this.dbInfo = dbInfo;
25
25
  this.isConnected = false;
26
+ this.isForcePrintSQLStatement = false;
26
27
  }
27
28
  async init() {
28
29
  console.log("init");
@@ -73,6 +74,9 @@ class ModelGenerator {
73
74
  .then((result) => {
74
75
  const endTime = new Date();
75
76
  const executionTime = endTime.getTime() - startTime.getTime();
77
+ if (this.isForcePrintSQLStatement === true) {
78
+ console.log("sql query > ", chalk_1.default.green(statment), parameter);
79
+ }
76
80
  if (isPrint === true)
77
81
  this.printResultLength(result, executionTime, queryResult);
78
82
  resolve(result[0]);
@@ -48,8 +48,8 @@ class MyDBMigrator {
48
48
  const compositeUniqueName = this.getCompositeUniqueName(compositeUniqueColumn);
49
49
  const sql = `SHOW INDEX FROM ${tableName} WHERE Non_unique = 0 AND Key_name like "${compositeUniqueName}"`;
50
50
  const data = (await this.MyDB.query(sql));
51
- console.log("sql", sql);
52
- console.log("isCompositeUniqueColumnExist", data.length, data);
51
+ // console.log("sql", sql)
52
+ // console.log("isCompositeUniqueColumnExist", data.length, data)
53
53
  return data.length ? true : false;
54
54
  }
55
55
  async alterForeignKey(tableName, col) {
@@ -71,7 +71,7 @@ class MyDBMigrator {
71
71
  }
72
72
  async alterUniqueColumnCombination(tableName, uniqueColumnCombination) {
73
73
  if (uniqueColumnCombination === null || uniqueColumnCombination === void 0 ? void 0 : uniqueColumnCombination.length) {
74
- uniqueColumnCombination.forEach(async (row) => {
74
+ for (let row of uniqueColumnCombination) {
75
75
  const isCompositeUniqueNameExist = await this.isCompositeUniqueColumnExist(tableName, row);
76
76
  // check is exist, then drop it first
77
77
  if (isCompositeUniqueNameExist) {
@@ -80,7 +80,7 @@ class MyDBMigrator {
80
80
  const compositeUniqueName = this.getCompositeUniqueName(row);
81
81
  const temp = row.columnName.join(",");
82
82
  await this.MyDB.query(`ALTER TABLE ${tableName} ADD UNIQUE KEY ${compositeUniqueName} (${temp})`);
83
- });
83
+ }
84
84
  }
85
85
  }
86
86
  async alterDataType(tableName, col) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gg-mysql-connector",
3
- "version": "1.0.87",
3
+ "version": "1.0.89",
4
4
  "description": "",
5
5
  "main": "dist/src/index.js",
6
6
  "scripts": {
@@ -73,6 +73,12 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
73
73
  this.DBInfo = DBInfo
74
74
  this.isConnected = false
75
75
  }
76
+ selectByDateRange<T extends keyof Main>(
77
+ tableName: T extends string ? T : string,
78
+ params: object
79
+ ): Promise<Main[T][]> {
80
+ throw new Error("Method not implemented.")
81
+ }
76
82
  async createDatabaseIfNotExist(
77
83
  tempConnection: mysql.Connection
78
84
  ): Promise<void> {
@@ -18,10 +18,12 @@ export default class ModelGenerator {
18
18
  dbInfo: DatabaseConfigInterface
19
19
  connection!: mysql.Connection
20
20
  isConnected: boolean
21
+ isForcePrintSQLStatement: boolean
21
22
  constructor(dbInfo: DatabaseConfigInterface, model: MyModel[]) {
22
23
  this.model = model
23
24
  this.dbInfo = dbInfo
24
25
  this.isConnected = false
26
+ this.isForcePrintSQLStatement = false
25
27
  }
26
28
  async init() {
27
29
  console.log("init")
@@ -78,6 +80,10 @@ export default class ModelGenerator {
78
80
  .then((result) => {
79
81
  const endTime = new Date()
80
82
  const executionTime = endTime.getTime() - startTime.getTime()
83
+
84
+ if (this.isForcePrintSQLStatement === true) {
85
+ console.log("sql query > ", chalk.green(statment), parameter)
86
+ }
81
87
  if (isPrint === true)
82
88
  this.printResultLength(result, executionTime, queryResult)
83
89
 
@@ -78,8 +78,8 @@ export default class MyDBMigrator {
78
78
  )
79
79
  const sql = `SHOW INDEX FROM ${tableName} WHERE Non_unique = 0 AND Key_name like "${compositeUniqueName}"`
80
80
  const data = (await this.MyDB.query(sql)) as any[]
81
- console.log("sql", sql)
82
- console.log("isCompositeUniqueColumnExist", data.length, data)
81
+ // console.log("sql", sql)
82
+ // console.log("isCompositeUniqueColumnExist", data.length, data)
83
83
  return data.length ? true : false
84
84
  }
85
85
 
@@ -111,7 +111,7 @@ export default class MyDBMigrator {
111
111
  uniqueColumnCombination: MyModel["compoisteUniqueColumn"]
112
112
  ) {
113
113
  if (uniqueColumnCombination?.length) {
114
- uniqueColumnCombination.forEach(async (row) => {
114
+ for (let row of uniqueColumnCombination) {
115
115
  const isCompositeUniqueNameExist =
116
116
  await this.isCompositeUniqueColumnExist(tableName, row)
117
117
  // check is exist, then drop it first
@@ -127,7 +127,7 @@ export default class MyDBMigrator {
127
127
  await this.MyDB.query(
128
128
  `ALTER TABLE ${tableName} ADD UNIQUE KEY ${compositeUniqueName} (${temp})`
129
129
  )
130
- })
130
+ }
131
131
  }
132
132
  }
133
133