gg-mysql-connector 1.0.114 → 1.0.117
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.
- package/dist/src/GGMySQLConnector/GGMySQLConnector.d.ts +2 -2
- package/dist/src/GGMySQLConnector/GGMySQLConnector.js +33 -27
- package/dist/src/ModelGenerator/ModelGenerator.js +1 -1
- package/package.json +1 -1
- package/src/GGMySQLConnector/GGMySQLConnector.ts +41 -31
- package/src/ModelGenerator/ModelGenerator.ts +1 -1
- package/src/ModelGenerator/SeedGenerator.ts +0 -33
|
@@ -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;
|
|
@@ -219,15 +220,15 @@ class GGMySQLConnector {
|
|
|
219
220
|
return result;
|
|
220
221
|
}
|
|
221
222
|
async init() {
|
|
222
|
-
const
|
|
223
|
+
const tempConnection = mysql2_1.default.createPool({
|
|
223
224
|
host: this.DBInfo.host,
|
|
224
225
|
user: this.DBInfo.user,
|
|
225
226
|
password: this.DBInfo.password,
|
|
226
227
|
});
|
|
228
|
+
await this.createDatabaseIfNotExist(tempConnection);
|
|
229
|
+
await tempConnection.end();
|
|
230
|
+
this.connection = mysql2_1.default.createPool(Object.assign(Object.assign({}, this.DBInfo), { waitForConnections: true, connectionLimit: 10 }));
|
|
227
231
|
this.isConnected = true;
|
|
228
|
-
await this.createDatabaseIfNotExist(currentConnection);
|
|
229
|
-
// await currentConnection.end()
|
|
230
|
-
this.connection = mysql2_1.default.createPool(Object.assign({}, this.DBInfo));
|
|
231
232
|
// await this.query("SET global sql_mode=''")
|
|
232
233
|
// await this.query("SET global query_cache_type='ON'")
|
|
233
234
|
// await this.query("SET global query_cache_size=16777216")
|
|
@@ -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
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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
|
|
296
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
@@ -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
|
|
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,
|
|
@@ -377,16 +378,21 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
|
|
|
377
378
|
}
|
|
378
379
|
|
|
379
380
|
async init() {
|
|
380
|
-
const
|
|
381
|
+
const tempConnection = mysql.createPool({
|
|
381
382
|
host: this.DBInfo.host,
|
|
382
383
|
user: this.DBInfo.user,
|
|
383
384
|
password: this.DBInfo.password,
|
|
384
385
|
})
|
|
386
|
+
await this.createDatabaseIfNotExist(tempConnection)
|
|
387
|
+
await tempConnection.end()
|
|
388
|
+
|
|
389
|
+
this.connection = mysql.createPool({
|
|
390
|
+
...this.DBInfo,
|
|
391
|
+
waitForConnections: true,
|
|
392
|
+
connectionLimit: 10,
|
|
393
|
+
})
|
|
385
394
|
this.isConnected = true
|
|
386
|
-
await this.createDatabaseIfNotExist(currentConnection)
|
|
387
|
-
// await currentConnection.end()
|
|
388
395
|
|
|
389
|
-
this.connection = mysql.createPool({ ...this.DBInfo })
|
|
390
396
|
// await this.query("SET global sql_mode=''")
|
|
391
397
|
// await this.query("SET global query_cache_type='ON'")
|
|
392
398
|
// await this.query("SET global query_cache_size=16777216")
|
|
@@ -461,33 +467,37 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
|
|
|
461
467
|
const uniqueTime = `${randomUUID()} ${statment}`
|
|
462
468
|
console.time(uniqueTime)
|
|
463
469
|
const startTime = new Date()
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
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)
|
|
486
497
|
}
|
|
487
|
-
resolve(results)
|
|
488
498
|
}
|
|
489
|
-
|
|
490
|
-
|
|
499
|
+
)
|
|
500
|
+
}
|
|
491
501
|
})
|
|
492
502
|
}
|
|
493
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.
|
|
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
|
-
// }
|