gg-mysql-connector 1.0.107 → 1.0.108
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.
|
|
4
|
+
connection: mysql.Pool;
|
|
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][]>;
|
|
@@ -20,12 +20,12 @@ export interface ClassDBInterface<Main> {
|
|
|
20
20
|
getViewNameList(): Promise<string[]>;
|
|
21
21
|
getViewNameIfExist(tableName: string): Promise<string>;
|
|
22
22
|
loadTableAndViewNameList(): Promise<string[]>;
|
|
23
|
-
createDatabaseIfNotExist(tempConnection: mysql.
|
|
23
|
+
createDatabaseIfNotExist(tempConnection: mysql.Pool): Promise<void>;
|
|
24
24
|
}
|
|
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.
|
|
28
|
+
connection: mysql.Pool;
|
|
29
29
|
isPrintStatement: boolean;
|
|
30
30
|
tableAndViewNameList: string[];
|
|
31
31
|
columnAndTableListCache: {
|
|
@@ -37,7 +37,7 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
|
|
|
37
37
|
isConnected: boolean;
|
|
38
38
|
constructor(DBInfo: DatabaseConfigInterface);
|
|
39
39
|
selectByDateRange<T extends keyof Main>(tableName: T extends string ? T : string, params: object): Promise<Main[T][]>;
|
|
40
|
-
createDatabaseIfNotExist(tempConnection: mysql.
|
|
40
|
+
createDatabaseIfNotExist(tempConnection: mysql.Pool): Promise<void>;
|
|
41
41
|
selectBySearchTextInRow(tableName: string, textToSearch: string): Promise<mysql.RowDataPacket[]>;
|
|
42
42
|
loadTableAndViewNameList(): Promise<string[]>;
|
|
43
43
|
getViewNameIfExist(tableName: string): Promise<string>;
|
|
@@ -214,7 +214,7 @@ class GGMySQLConnector {
|
|
|
214
214
|
return result;
|
|
215
215
|
}
|
|
216
216
|
async init() {
|
|
217
|
-
const currentConnection = mysql2_1.default.
|
|
217
|
+
const currentConnection = mysql2_1.default.createPool({
|
|
218
218
|
host: this.DBInfo.host,
|
|
219
219
|
user: this.DBInfo.user,
|
|
220
220
|
password: this.DBInfo.password,
|
|
@@ -222,7 +222,7 @@ class GGMySQLConnector {
|
|
|
222
222
|
this.isConnected = true;
|
|
223
223
|
await this.createDatabaseIfNotExist(currentConnection);
|
|
224
224
|
// await currentConnection.end()
|
|
225
|
-
this.connection = mysql2_1.default.
|
|
225
|
+
this.connection = mysql2_1.default.createPool(Object.assign({}, this.DBInfo));
|
|
226
226
|
// await this.query("SET global sql_mode=''")
|
|
227
227
|
// await this.query("SET global query_cache_type='ON'")
|
|
228
228
|
// await this.query("SET global query_cache_size=16777216")
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ import mysql, { QueryResult, RowDataPacket } from "mysql2"
|
|
|
4
4
|
import { DatabaseConfigInterface } from "../ModelGenerator/ModelGenerator"
|
|
5
5
|
|
|
6
6
|
export interface ClassDBInterface<Main> {
|
|
7
|
-
connection: mysql.
|
|
7
|
+
connection: mysql.Pool
|
|
8
8
|
query<T>(
|
|
9
9
|
statement: string,
|
|
10
10
|
parameter?: object,
|
|
@@ -48,12 +48,12 @@ export interface ClassDBInterface<Main> {
|
|
|
48
48
|
getViewNameList(): Promise<string[]>
|
|
49
49
|
getViewNameIfExist(tableName: string): Promise<string>
|
|
50
50
|
loadTableAndViewNameList(): Promise<string[]>
|
|
51
|
-
createDatabaseIfNotExist(tempConnection: mysql.
|
|
51
|
+
createDatabaseIfNotExist(tempConnection: mysql.Pool): Promise<void>
|
|
52
52
|
}
|
|
53
53
|
export type Unarray<T> = T extends Array<infer U> ? U : T
|
|
54
54
|
export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
|
|
55
55
|
DBInfo: DatabaseConfigInterface
|
|
56
|
-
connection!: mysql.
|
|
56
|
+
connection!: mysql.Pool
|
|
57
57
|
isPrintStatement: boolean
|
|
58
58
|
tableAndViewNameList: string[]
|
|
59
59
|
columnAndTableListCache:
|
|
@@ -79,9 +79,7 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
|
|
|
79
79
|
): Promise<Main[T][]> {
|
|
80
80
|
throw new Error("Method not implemented.")
|
|
81
81
|
}
|
|
82
|
-
async createDatabaseIfNotExist(
|
|
83
|
-
tempConnection: mysql.Connection
|
|
84
|
-
): Promise<void> {
|
|
82
|
+
async createDatabaseIfNotExist(tempConnection: mysql.Pool): Promise<void> {
|
|
85
83
|
const currentDatabaseName = this.DBInfo.database
|
|
86
84
|
console.log("currentDatabaseName", currentDatabaseName)
|
|
87
85
|
return new Promise((resolve, reject) => {
|
|
@@ -362,7 +360,7 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
|
|
|
362
360
|
}
|
|
363
361
|
|
|
364
362
|
async init() {
|
|
365
|
-
const currentConnection = mysql.
|
|
363
|
+
const currentConnection = mysql.createPool({
|
|
366
364
|
host: this.DBInfo.host,
|
|
367
365
|
user: this.DBInfo.user,
|
|
368
366
|
password: this.DBInfo.password,
|
|
@@ -371,7 +369,7 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
|
|
|
371
369
|
await this.createDatabaseIfNotExist(currentConnection)
|
|
372
370
|
// await currentConnection.end()
|
|
373
371
|
|
|
374
|
-
this.connection = mysql.
|
|
372
|
+
this.connection = mysql.createPool({ ...this.DBInfo })
|
|
375
373
|
// await this.query("SET global sql_mode=''")
|
|
376
374
|
// await this.query("SET global query_cache_type='ON'")
|
|
377
375
|
// await this.query("SET global query_cache_size=16777216")
|