gg-mysql-connector 1.0.112 → 1.0.115
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,7 +36,11 @@ 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 :
|
|
39
|
+
selectByDateRange<T extends keyof Main>(tableName: T extends string ? T : never, params: {
|
|
40
|
+
columnName: keyof Main[T];
|
|
41
|
+
startDate: string;
|
|
42
|
+
endDate: string;
|
|
43
|
+
}): Promise<Main[T][]>;
|
|
40
44
|
createDatabaseIfNotExist(tempConnection: mysql.Pool): Promise<void>;
|
|
41
45
|
selectBySearchTextInRow(tableName: string, textToSearch: string): Promise<mysql.RowDataPacket[]>;
|
|
42
46
|
loadTableAndViewNameList(): Promise<string[]>;
|
|
@@ -26,8 +26,10 @@ class GGMySQLConnector {
|
|
|
26
26
|
this.DBInfo = DBInfo;
|
|
27
27
|
this.isConnected = false;
|
|
28
28
|
}
|
|
29
|
-
selectByDateRange(tableName, params) {
|
|
30
|
-
|
|
29
|
+
async selectByDateRange(tableName, params) {
|
|
30
|
+
const { columnName, endDate, startDate } = params;
|
|
31
|
+
const result = (await this.query(`SELECT * FROM ${tableName} WHERE ? <= ? AND ? <= ?`, [tableName, startDate, columnName, columnName, endDate], false));
|
|
32
|
+
return result;
|
|
31
33
|
}
|
|
32
34
|
async createDatabaseIfNotExist(tempConnection) {
|
|
33
35
|
const currentDatabaseName = this.DBInfo.database;
|
|
@@ -217,15 +219,15 @@ class GGMySQLConnector {
|
|
|
217
219
|
return result;
|
|
218
220
|
}
|
|
219
221
|
async init() {
|
|
220
|
-
const
|
|
222
|
+
const tempConnection = mysql2_1.default.createPool({
|
|
221
223
|
host: this.DBInfo.host,
|
|
222
224
|
user: this.DBInfo.user,
|
|
223
225
|
password: this.DBInfo.password,
|
|
224
226
|
});
|
|
227
|
+
await this.createDatabaseIfNotExist(tempConnection);
|
|
228
|
+
await tempConnection.end();
|
|
229
|
+
this.connection = mysql2_1.default.createPool(Object.assign(Object.assign({}, this.DBInfo), { waitForConnections: true, connectionLimit: 10 }));
|
|
225
230
|
this.isConnected = true;
|
|
226
|
-
await this.createDatabaseIfNotExist(currentConnection);
|
|
227
|
-
// await currentConnection.end()
|
|
228
|
-
this.connection = mysql2_1.default.createPool(Object.assign({}, this.DBInfo));
|
|
229
231
|
// await this.query("SET global sql_mode=''")
|
|
230
232
|
// await this.query("SET global query_cache_type='ON'")
|
|
231
233
|
// await this.query("SET global query_cache_size=16777216")
|
package/package.json
CHANGED
|
@@ -81,11 +81,21 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
|
|
|
81
81
|
this.DBInfo = DBInfo
|
|
82
82
|
this.isConnected = false
|
|
83
83
|
}
|
|
84
|
-
selectByDateRange<T extends keyof Main>(
|
|
85
|
-
tableName: T extends string ? T :
|
|
86
|
-
params:
|
|
84
|
+
async selectByDateRange<T extends keyof Main>(
|
|
85
|
+
tableName: T extends string ? T : never,
|
|
86
|
+
params: {
|
|
87
|
+
columnName: keyof Main[T]
|
|
88
|
+
startDate: string
|
|
89
|
+
endDate: string
|
|
90
|
+
}
|
|
87
91
|
): Promise<Main[T][]> {
|
|
88
|
-
|
|
92
|
+
const { columnName, endDate, startDate } = params
|
|
93
|
+
const result = (await this.query(
|
|
94
|
+
`SELECT * FROM ${tableName} WHERE ? <= ? AND ? <= ?`,
|
|
95
|
+
[tableName, startDate, columnName, columnName, endDate],
|
|
96
|
+
false
|
|
97
|
+
)) as Main[T][]
|
|
98
|
+
return result
|
|
89
99
|
}
|
|
90
100
|
async createDatabaseIfNotExist(tempConnection: mysql.Pool): Promise<void> {
|
|
91
101
|
const currentDatabaseName = this.DBInfo.database
|
|
@@ -367,16 +377,21 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
|
|
|
367
377
|
}
|
|
368
378
|
|
|
369
379
|
async init() {
|
|
370
|
-
const
|
|
380
|
+
const tempConnection = mysql.createPool({
|
|
371
381
|
host: this.DBInfo.host,
|
|
372
382
|
user: this.DBInfo.user,
|
|
373
383
|
password: this.DBInfo.password,
|
|
374
384
|
})
|
|
385
|
+
await this.createDatabaseIfNotExist(tempConnection)
|
|
386
|
+
await tempConnection.end()
|
|
387
|
+
|
|
388
|
+
this.connection = mysql.createPool({
|
|
389
|
+
...this.DBInfo,
|
|
390
|
+
waitForConnections: true,
|
|
391
|
+
connectionLimit: 10,
|
|
392
|
+
})
|
|
375
393
|
this.isConnected = true
|
|
376
|
-
await this.createDatabaseIfNotExist(currentConnection)
|
|
377
|
-
// await currentConnection.end()
|
|
378
394
|
|
|
379
|
-
this.connection = mysql.createPool({ ...this.DBInfo })
|
|
380
395
|
// await this.query("SET global sql_mode=''")
|
|
381
396
|
// await this.query("SET global query_cache_type='ON'")
|
|
382
397
|
// await this.query("SET global query_cache_size=16777216")
|