gg-mysql-connector 1.0.23 → 1.0.25
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/GGMySQLConnector.d.ts +2 -0
- package/dist/GGMySQLConnector.js +15 -0
- package/dist/ModelGenerator.d.ts +2 -0
- package/dist/ModelGenerator.js +19 -3
- package/package.json +1 -1
- package/src/GGMySQLConnector.ts +15 -0
- package/src/ModelGenerator.ts +19 -3
|
@@ -33,6 +33,7 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
|
|
|
33
33
|
TABLE_NAME: string;
|
|
34
34
|
DATA_TYPE: string;
|
|
35
35
|
}[] | null;
|
|
36
|
+
isConnected: boolean;
|
|
36
37
|
constructor(DBInfo: DatabaseConfigInterface);
|
|
37
38
|
createDatabaseIfNotExist(tempConnection: mysql.Connection): Promise<void>;
|
|
38
39
|
selectBySearchTextInRow(tableName: string, textToSearch: string): Promise<mysql.RowDataPacket[]>;
|
|
@@ -65,6 +66,7 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
|
|
|
65
66
|
loadColumnListToCache(): Promise<void>;
|
|
66
67
|
getColumnList(tableName: string): Promise<string[]>;
|
|
67
68
|
getColumnFullList(tableName: string): Promise<mysql.RowDataPacket[]>;
|
|
69
|
+
waitUntilInitSuccess(interval: number): Promise<unknown>;
|
|
68
70
|
query<T>(statment: string, parameter?: any[], isPrint?: boolean): Promise<T | QueryResult>;
|
|
69
71
|
private printResultLength;
|
|
70
72
|
}
|
package/dist/GGMySQLConnector.js
CHANGED
|
@@ -20,6 +20,7 @@ class GGMySQLConnector {
|
|
|
20
20
|
this.tableAndViewNameList = [];
|
|
21
21
|
this.columnAndTableListCache = null;
|
|
22
22
|
this.DBInfo = DBInfo;
|
|
23
|
+
this.isConnected = false;
|
|
23
24
|
}
|
|
24
25
|
async createDatabaseIfNotExist(tempConnection) {
|
|
25
26
|
const currentDatabaseName = this.DBInfo.database;
|
|
@@ -242,7 +243,21 @@ class GGMySQLConnector {
|
|
|
242
243
|
const result = (await this.query(`SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '${this.DBInfo.database}' AND TABLE_NAME = '${tableName}'`, undefined, false));
|
|
243
244
|
return result;
|
|
244
245
|
}
|
|
246
|
+
waitUntilInitSuccess(interval) {
|
|
247
|
+
console.log("wait for database connection . . .");
|
|
248
|
+
return new Promise((resolve, reject) => {
|
|
249
|
+
setTimeout(() => {
|
|
250
|
+
if (this.isConnected === false) {
|
|
251
|
+
this.waitUntilInitSuccess(interval);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
return resolve(true);
|
|
255
|
+
}
|
|
256
|
+
}, interval);
|
|
257
|
+
});
|
|
258
|
+
}
|
|
245
259
|
async query(statment, parameter, isPrint) {
|
|
260
|
+
await this.waitUntilInitSuccess(1000);
|
|
246
261
|
return new Promise((resolve, reject) => {
|
|
247
262
|
const uniqueTime = `${(0, crypto_1.randomUUID)()} ${statment}`;
|
|
248
263
|
console.time(uniqueTime);
|
package/dist/ModelGenerator.d.ts
CHANGED
|
@@ -10,11 +10,13 @@ export default class ModelGenerator {
|
|
|
10
10
|
model: MyModel[];
|
|
11
11
|
dbInfo: DatabaseConfigInterface;
|
|
12
12
|
connection: mysql.Connection;
|
|
13
|
+
isConnected: boolean;
|
|
13
14
|
constructor(dbInfo: DatabaseConfigInterface, model: MyModel[]);
|
|
14
15
|
init(): Promise<void>;
|
|
15
16
|
private createDatabaseIfNotExist;
|
|
16
17
|
pushModelToDB(): Promise<void>;
|
|
17
18
|
pushViewToDB(viewDirectory: string): Promise<void>;
|
|
19
|
+
waitUntilInitSuccess(interval: number): Promise<unknown>;
|
|
18
20
|
query<T>(statment: string, parameter?: any[], isPrint?: boolean): Promise<T>;
|
|
19
21
|
private printResultLength;
|
|
20
22
|
getTableNameList(): Promise<string[]>;
|
package/dist/ModelGenerator.js
CHANGED
|
@@ -21,6 +21,7 @@ class ModelGenerator {
|
|
|
21
21
|
};
|
|
22
22
|
this.model = model;
|
|
23
23
|
this.dbInfo = dbInfo;
|
|
24
|
+
this.isConnected = false;
|
|
24
25
|
}
|
|
25
26
|
async init() {
|
|
26
27
|
console.log("init");
|
|
@@ -29,6 +30,7 @@ class ModelGenerator {
|
|
|
29
30
|
user: this.dbInfo.user,
|
|
30
31
|
password: this.dbInfo.password,
|
|
31
32
|
});
|
|
33
|
+
this.isConnected = true;
|
|
32
34
|
await this.createDatabaseIfNotExist();
|
|
33
35
|
}
|
|
34
36
|
async createDatabaseIfNotExist() {
|
|
@@ -44,7 +46,21 @@ class ModelGenerator {
|
|
|
44
46
|
const migrator = new MyDBMigration_1.default(this);
|
|
45
47
|
await migrator.migrateView(viewDirectory);
|
|
46
48
|
}
|
|
49
|
+
waitUntilInitSuccess(interval) {
|
|
50
|
+
console.log("wait for database connection . . .");
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
setTimeout(() => {
|
|
53
|
+
if (this.isConnected === false) {
|
|
54
|
+
this.waitUntilInitSuccess(interval);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return resolve(true);
|
|
58
|
+
}
|
|
59
|
+
}, interval);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
47
62
|
async query(statment, parameter, isPrint) {
|
|
63
|
+
await this.waitUntilInitSuccess(1000);
|
|
48
64
|
return new Promise((resolve, reject) => {
|
|
49
65
|
const uniqueTime = `${(0, crypto_1.randomUUID)()} ${statment}`;
|
|
50
66
|
console.time(uniqueTime);
|
|
@@ -155,11 +171,11 @@ class ModelGenerator {
|
|
|
155
171
|
}
|
|
156
172
|
const fileName = `${params.appName}_INF.ts`;
|
|
157
173
|
const code = `export default interface ${params.appName}_INF { ${array.join("\n")} }`;
|
|
158
|
-
params.outputDirectory
|
|
159
|
-
const serverFilePath = path_1.default.join(
|
|
174
|
+
for (let row of params.outputDirectory) {
|
|
175
|
+
const serverFilePath = path_1.default.join(row, fileName);
|
|
160
176
|
await fs_1.default.writeFileSync(serverFilePath, code);
|
|
161
177
|
console.log("save to ", serverFilePath);
|
|
162
|
-
}
|
|
178
|
+
}
|
|
163
179
|
console.log(`generate interface ${params.appName} ${chalk_1.default.bgGreen(" SUCCESS ")}`);
|
|
164
180
|
return code;
|
|
165
181
|
}
|
package/package.json
CHANGED
package/src/GGMySQLConnector.ts
CHANGED
|
@@ -59,12 +59,14 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
|
|
|
59
59
|
columnAndTableListCache:
|
|
60
60
|
| { COLUMN_NAME: string; TABLE_NAME: string; DATA_TYPE: string }[]
|
|
61
61
|
| null
|
|
62
|
+
isConnected: boolean
|
|
62
63
|
|
|
63
64
|
constructor(DBInfo: DatabaseConfigInterface) {
|
|
64
65
|
this.isPrintStatement = false
|
|
65
66
|
this.tableAndViewNameList = []
|
|
66
67
|
this.columnAndTableListCache = null
|
|
67
68
|
this.DBInfo = DBInfo
|
|
69
|
+
this.isConnected = false
|
|
68
70
|
}
|
|
69
71
|
async createDatabaseIfNotExist(
|
|
70
72
|
tempConnection: mysql.Connection
|
|
@@ -401,12 +403,25 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
|
|
|
401
403
|
)) as mysql.RowDataPacket[]
|
|
402
404
|
return result
|
|
403
405
|
}
|
|
406
|
+
waitUntilInitSuccess(interval: number) {
|
|
407
|
+
console.log("wait for database connection . . .")
|
|
408
|
+
return new Promise((resolve, reject) => {
|
|
409
|
+
setTimeout(() => {
|
|
410
|
+
if (this.isConnected === false) {
|
|
411
|
+
this.waitUntilInitSuccess(interval)
|
|
412
|
+
} else {
|
|
413
|
+
return resolve(true)
|
|
414
|
+
}
|
|
415
|
+
}, interval)
|
|
416
|
+
})
|
|
417
|
+
}
|
|
404
418
|
|
|
405
419
|
async query<T>(
|
|
406
420
|
statment: string,
|
|
407
421
|
parameter?: any[],
|
|
408
422
|
isPrint?: boolean
|
|
409
423
|
): Promise<T | QueryResult> {
|
|
424
|
+
await this.waitUntilInitSuccess(1000)
|
|
410
425
|
return new Promise((resolve, reject) => {
|
|
411
426
|
const uniqueTime = `${randomUUID()} ${statment}`
|
|
412
427
|
console.time(uniqueTime)
|
package/src/ModelGenerator.ts
CHANGED
|
@@ -16,9 +16,11 @@ export default class ModelGenerator {
|
|
|
16
16
|
model: MyModel[]
|
|
17
17
|
dbInfo: DatabaseConfigInterface
|
|
18
18
|
connection!: mysql.Connection
|
|
19
|
+
isConnected: boolean
|
|
19
20
|
constructor(dbInfo: DatabaseConfigInterface, model: MyModel[]) {
|
|
20
21
|
this.model = model
|
|
21
22
|
this.dbInfo = dbInfo
|
|
23
|
+
this.isConnected = false
|
|
22
24
|
}
|
|
23
25
|
async init() {
|
|
24
26
|
console.log("init")
|
|
@@ -27,6 +29,7 @@ export default class ModelGenerator {
|
|
|
27
29
|
user: this.dbInfo.user,
|
|
28
30
|
password: this.dbInfo.password,
|
|
29
31
|
})
|
|
32
|
+
this.isConnected = true
|
|
30
33
|
await this.createDatabaseIfNotExist()
|
|
31
34
|
}
|
|
32
35
|
private async createDatabaseIfNotExist() {
|
|
@@ -43,12 +46,25 @@ export default class ModelGenerator {
|
|
|
43
46
|
const migrator = new MyDBMigration(this)
|
|
44
47
|
await migrator.migrateView(viewDirectory)
|
|
45
48
|
}
|
|
49
|
+
waitUntilInitSuccess(interval: number) {
|
|
50
|
+
console.log("wait for database connection . . .")
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
setTimeout(() => {
|
|
53
|
+
if (this.isConnected === false) {
|
|
54
|
+
this.waitUntilInitSuccess(interval)
|
|
55
|
+
} else {
|
|
56
|
+
return resolve(true)
|
|
57
|
+
}
|
|
58
|
+
}, interval)
|
|
59
|
+
})
|
|
60
|
+
}
|
|
46
61
|
|
|
47
62
|
async query<T>(
|
|
48
63
|
statment: string,
|
|
49
64
|
parameter?: any[],
|
|
50
65
|
isPrint?: boolean
|
|
51
66
|
): Promise<T> {
|
|
67
|
+
await this.waitUntilInitSuccess(1000)
|
|
52
68
|
return new Promise((resolve, reject) => {
|
|
53
69
|
const uniqueTime = `${randomUUID()} ${statment}`
|
|
54
70
|
console.time(uniqueTime)
|
|
@@ -207,11 +223,11 @@ export default class ModelGenerator {
|
|
|
207
223
|
params.appName
|
|
208
224
|
}_INF { ${array.join("\n")} }`
|
|
209
225
|
|
|
210
|
-
params.outputDirectory
|
|
211
|
-
const serverFilePath = path.join(
|
|
226
|
+
for (let row of params.outputDirectory) {
|
|
227
|
+
const serverFilePath = path.join(row, fileName)
|
|
212
228
|
await fs.writeFileSync(serverFilePath, code)
|
|
213
229
|
console.log("save to ", serverFilePath)
|
|
214
|
-
}
|
|
230
|
+
}
|
|
215
231
|
|
|
216
232
|
console.log(
|
|
217
233
|
`generate interface ${params.appName} ${chalk.bgGreen(" SUCCESS ")}`
|