gg-mysql-connector 1.0.115 → 1.0.118

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.
@@ -1,7 +1,7 @@
1
1
  import mysql, { QueryResult, RowDataPacket } from "mysql2";
2
2
  import { DatabaseConfigInterface } from "../ModelGenerator/ModelGenerator";
3
3
  export interface ClassDBInterface<Main> {
4
- connection: mysql.Pool;
4
+ connection: mysql.Pool | null;
5
5
  query<T>(statement: string, parameter?: object, isPrint?: boolean): Promise<T | QueryResult>;
6
6
  getColumnList(tableName: string): Promise<string[]>;
7
7
  select<T extends keyof Main>(tableName: T extends string ? T : string): Promise<Main[T][]>;
@@ -25,7 +25,7 @@ export interface ClassDBInterface<Main> {
25
25
  export type Unarray<T> = T extends Array<infer U> ? U : T;
26
26
  export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
27
27
  DBInfo: DatabaseConfigInterface;
28
- connection: mysql.Pool;
28
+ connection: mysql.Pool | null;
29
29
  isPrintStatement: boolean;
30
30
  tableAndViewNameList: string[];
31
31
  columnAndTableListCache: {
@@ -25,6 +25,7 @@ class GGMySQLConnector {
25
25
  this.columnAndTableListCache = null;
26
26
  this.DBInfo = DBInfo;
27
27
  this.isConnected = false;
28
+ this.connection = null;
28
29
  }
29
30
  async selectByDateRange(tableName, params) {
30
31
  const { columnName, endDate, startDate } = params;
@@ -273,31 +274,36 @@ class GGMySQLConnector {
273
274
  const uniqueTime = `${(0, crypto_1.randomUUID)()} ${statment}`;
274
275
  console.time(uniqueTime);
275
276
  const startTime = new Date();
276
- const queryResult = this.connection.query(statment, parameter, (error, results, fields) => {
277
- if (error) {
278
- // _getCallerFile()
279
- console.log(chalk_1.default.bgRed("Query Error"));
280
- console.log(chalk_1.default.bgRed(error));
281
- console.log(chalk_1.default.bgRed("Statement : "));
282
- console.log(statment);
283
- console.log(chalk_1.default.bgRed("Parameter : "));
284
- console.log(parameter);
285
- console.log("------------------------------------------------");
286
- console.log(chalk_1.default.bgRed(queryResult.sql));
287
- reject(error);
288
- }
289
- else {
290
- const endTime = new Date();
291
- const executionTime = endTime.getTime() - startTime.getTime();
292
- if (isPrint === true) {
293
- this.printResultLength(results, executionTime, queryResult);
277
+ if (this.connection === null) {
278
+ console.error("error : mysql connection not open.");
279
+ }
280
+ else if (this.connection) {
281
+ const queryResult = this.connection.query(statment, parameter, (error, results, fields) => {
282
+ if (error) {
283
+ // _getCallerFile()
284
+ console.log(chalk_1.default.bgRed("Query Error"));
285
+ console.log(chalk_1.default.bgRed(error));
286
+ console.log(chalk_1.default.bgRed("Statement : "));
287
+ console.log(statment);
288
+ console.log(chalk_1.default.bgRed("Parameter : "));
289
+ console.log(parameter);
290
+ console.log("------------------------------------------------");
291
+ console.log(chalk_1.default.bgRed(queryResult.sql));
292
+ reject(error);
294
293
  }
295
- else if (this.isPrintStatement) {
296
- this.printResultLength(results, executionTime, queryResult);
294
+ else {
295
+ const endTime = new Date();
296
+ const executionTime = endTime.getTime() - startTime.getTime();
297
+ if (isPrint === true) {
298
+ this.printResultLength(results, executionTime, queryResult);
299
+ }
300
+ else if (this.isPrintStatement) {
301
+ this.printResultLength(results, executionTime, queryResult);
302
+ }
303
+ resolve(results);
297
304
  }
298
- resolve(results);
299
- }
300
- });
305
+ });
306
+ }
301
307
  });
302
308
  }
303
309
  }
@@ -27,7 +27,7 @@ class ModelGenerator {
27
27
  }
28
28
  async init() {
29
29
  console.log("init");
30
- this.connection = await promise_1.default.createConnection({
30
+ this.connection = await promise_1.default.createPool({
31
31
  host: this.dbInfo.host,
32
32
  user: this.dbInfo.user,
33
33
  password: this.dbInfo.password,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gg-mysql-connector",
3
- "version": "1.0.115",
3
+ "version": "1.0.118",
4
4
  "description": "",
5
5
  "main": "dist/src/index.js",
6
6
  "scripts": {
@@ -13,7 +13,7 @@
13
13
  "app-root-path": "^3.1.0",
14
14
  "chalk": "^4.1.2",
15
15
  "fs": "^0.0.1-security",
16
- "mysql2": "^3.11.3",
16
+ "mysql2": "^3.16.0",
17
17
  "path": "^0.12.7",
18
18
  "sql-template-strings": "^2.2.2"
19
19
  },
@@ -12,7 +12,7 @@ function log(input: {
12
12
  }
13
13
 
14
14
  export interface ClassDBInterface<Main> {
15
- connection: mysql.Pool
15
+ connection: mysql.Pool | null
16
16
  query<T>(
17
17
  statement: string,
18
18
  parameter?: object,
@@ -61,7 +61,7 @@ export interface ClassDBInterface<Main> {
61
61
  export type Unarray<T> = T extends Array<infer U> ? U : T
62
62
  export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
63
63
  DBInfo: DatabaseConfigInterface
64
- connection!: mysql.Pool
64
+ connection: mysql.Pool | null
65
65
  isPrintStatement: boolean
66
66
  tableAndViewNameList: string[]
67
67
  columnAndTableListCache:
@@ -80,6 +80,7 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
80
80
  this.columnAndTableListCache = null
81
81
  this.DBInfo = DBInfo
82
82
  this.isConnected = false
83
+ this.connection = null
83
84
  }
84
85
  async selectByDateRange<T extends keyof Main>(
85
86
  tableName: T extends string ? T : never,
@@ -466,33 +467,37 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
466
467
  const uniqueTime = `${randomUUID()} ${statment}`
467
468
  console.time(uniqueTime)
468
469
  const startTime = new Date()
469
- const queryResult = this.connection.query(
470
- statment,
471
- parameter,
472
- (error, results, fields) => {
473
- if (error) {
474
- // _getCallerFile()
475
- console.log(chalk.bgRed("Query Error"))
476
- console.log(chalk.bgRed(error))
477
- console.log(chalk.bgRed("Statement : "))
478
- console.log(statment)
479
- console.log(chalk.bgRed("Parameter : "))
480
- console.log(parameter)
481
- console.log("------------------------------------------------")
482
- console.log(chalk.bgRed(queryResult.sql))
483
- reject(error)
484
- } else {
485
- const endTime = new Date()
486
- const executionTime = endTime.getTime() - startTime.getTime()
487
- if (isPrint === true) {
488
- this.printResultLength(results, executionTime, queryResult)
489
- } else if (this.isPrintStatement) {
490
- this.printResultLength(results, executionTime, queryResult)
470
+ if (this.connection === null) {
471
+ console.error("error : mysql connection not open.")
472
+ } else if (this.connection) {
473
+ const queryResult = this.connection.query(
474
+ statment,
475
+ parameter,
476
+ (error, results, fields) => {
477
+ if (error) {
478
+ // _getCallerFile()
479
+ console.log(chalk.bgRed("Query Error"))
480
+ console.log(chalk.bgRed(error))
481
+ console.log(chalk.bgRed("Statement : "))
482
+ console.log(statment)
483
+ console.log(chalk.bgRed("Parameter : "))
484
+ console.log(parameter)
485
+ console.log("------------------------------------------------")
486
+ console.log(chalk.bgRed(queryResult.sql))
487
+ reject(error)
488
+ } else {
489
+ const endTime = new Date()
490
+ const executionTime = endTime.getTime() - startTime.getTime()
491
+ if (isPrint === true) {
492
+ this.printResultLength(results, executionTime, queryResult)
493
+ } else if (this.isPrintStatement) {
494
+ this.printResultLength(results, executionTime, queryResult)
495
+ }
496
+ resolve(results)
491
497
  }
492
- resolve(results)
493
498
  }
494
- }
495
- )
499
+ )
500
+ }
496
501
  })
497
502
  }
498
503
  private printResultLength = (
@@ -28,7 +28,7 @@ export default class ModelGenerator {
28
28
  }
29
29
  async init() {
30
30
  console.log("init")
31
- this.connection = await mysql.createConnection({
31
+ this.connection = await mysql.createPool({
32
32
  host: this.dbInfo.host,
33
33
  user: this.dbInfo.user,
34
34
  password: this.dbInfo.password,
@@ -1,33 +0,0 @@
1
- // import { MyModel } from "../myModel"
2
-
3
- // function generateSeedInterfaceNoDBConnection(models: MyModel[]) {
4
- // for (const tableModel of models) {
5
- // const arrayOfColumnKeyValue = []
6
- // const arrayOfSeedColumnKeyValue = []
7
-
8
- // const columnList = tableModel.columns
9
-
10
- // let stringOfRawColumnKeyAndValue = ""
11
- // for (const cRow of columnList) {
12
- // const possibleValue = cRow.POSSIBLE_VALUE
13
- // if (possibleValue) {
14
- // stringOfRawColumnKeyAndValue = `${stringOfRawColumnKeyAndValue} \n ${
15
- // cRow.COLUMN_NAME
16
- // }: ${possibleValue.map((row) => `"${row}"`).join(" | ")};`
17
- // } else {
18
- // stringOfRawColumnKeyAndValue = `${stringOfRawColumnKeyAndValue} \n ${
19
- // cRow.COLUMN_NAME
20
- // }: ${convertDataType(cRow.DATA_TYPE)};`
21
- // }
22
- // }
23
-
24
- // // normal app model code
25
- // const str = ` ${tableName} : { ${stringOfRawColumnKeyAndValue} }`
26
- // arrayOfColumnKeyValue.push(str)
27
- // // only seed model code
28
- // const tempSeedModel = params.model.find(
29
- // (row) => row.tableName === tableName && row.isSeed
30
- // )
31
- // if (tempSeedModel) arrayOfSeedColumnKeyValue.push(str)
32
- // }
33
- // }