gg-mysql-connector 1.0.108 → 1.0.112
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/app_model_const.ts +36 -24
- package/dist/app_model_const.d.ts +3 -3
- package/dist/app_model_const.js +14 -7
- package/dist/src/GGMySQLConnector/GGMySQLConnector.js +11 -8
- package/dist/src/ModelGenerator/ModelGenerator.js +7 -1
- package/dist/src/MyDBMigrator/MyDBMigrator.js +0 -7
- package/package.json +1 -1
- package/src/GGMySQLConnector/GGMySQLConnector.ts +15 -8
- package/src/ModelGenerator/ModelGenerator.ts +7 -1
- package/src/MyDBMigrator/MyDBMigrator.ts +0 -10
package/app_model_const.ts
CHANGED
|
@@ -1,24 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
export const app_model_const = {
|
|
2
|
+
item: {
|
|
3
|
+
id: "number",
|
|
4
|
+
name: ["pen", "ruler", "tiger"] as const,
|
|
5
|
+
price: "number",
|
|
6
|
+
description: "string",
|
|
7
|
+
amount: "number",
|
|
8
|
+
userId: "number",
|
|
9
|
+
},
|
|
10
|
+
item__stock: {
|
|
11
|
+
id: "number",
|
|
12
|
+
userId: "number",
|
|
13
|
+
itemId: "number",
|
|
14
|
+
amount: "number",
|
|
15
|
+
},
|
|
16
|
+
user: {
|
|
17
|
+
id: "number",
|
|
18
|
+
name: "string",
|
|
19
|
+
},
|
|
20
|
+
item__each_user: {
|
|
21
|
+
id: "number",
|
|
22
|
+
itemId: "number",
|
|
23
|
+
userId: "number",
|
|
24
|
+
},
|
|
25
|
+
test_view: {
|
|
26
|
+
id: "number",
|
|
27
|
+
name: "string",
|
|
28
|
+
itemName: ["pen", "ruler", "tiger"] as const,
|
|
29
|
+
},
|
|
30
|
+
item_view: {
|
|
31
|
+
id: "number",
|
|
32
|
+
name: ["pen", "ruler", "tiger"] as const,
|
|
33
|
+
amount: "number",
|
|
34
|
+
price: "number",
|
|
35
|
+
},
|
|
36
|
+
} as const
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const app_model_const: {
|
|
2
2
|
readonly item: {
|
|
3
3
|
readonly id: "number";
|
|
4
|
-
readonly name:
|
|
4
|
+
readonly name: readonly ["pen", "ruler", "tiger"];
|
|
5
5
|
readonly price: "number";
|
|
6
6
|
readonly description: "string";
|
|
7
7
|
readonly amount: "number";
|
|
@@ -25,11 +25,11 @@ export declare const app_model_const: {
|
|
|
25
25
|
readonly test_view: {
|
|
26
26
|
readonly id: "number";
|
|
27
27
|
readonly name: "string";
|
|
28
|
-
readonly itemName:
|
|
28
|
+
readonly itemName: readonly ["pen", "ruler", "tiger"];
|
|
29
29
|
};
|
|
30
30
|
readonly item_view: {
|
|
31
31
|
readonly id: "number";
|
|
32
|
-
readonly name:
|
|
32
|
+
readonly name: readonly ["pen", "ruler", "tiger"];
|
|
33
33
|
readonly amount: "number";
|
|
34
34
|
readonly price: "number";
|
|
35
35
|
};
|
package/dist/app_model_const.js
CHANGED
|
@@ -1,32 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.app_model_const = void 0;
|
|
4
|
-
exports.app_model_const = {
|
|
4
|
+
exports.app_model_const = {
|
|
5
|
+
item: {
|
|
5
6
|
id: "number",
|
|
6
7
|
name: ["pen", "ruler", "tiger"],
|
|
7
8
|
price: "number",
|
|
8
9
|
description: "string",
|
|
9
10
|
amount: "number",
|
|
10
11
|
userId: "number",
|
|
11
|
-
},
|
|
12
|
+
},
|
|
13
|
+
item__stock: {
|
|
12
14
|
id: "number",
|
|
13
15
|
userId: "number",
|
|
14
16
|
itemId: "number",
|
|
15
17
|
amount: "number",
|
|
16
|
-
},
|
|
18
|
+
},
|
|
19
|
+
user: {
|
|
17
20
|
id: "number",
|
|
18
21
|
name: "string",
|
|
19
|
-
},
|
|
22
|
+
},
|
|
23
|
+
item__each_user: {
|
|
20
24
|
id: "number",
|
|
21
25
|
itemId: "number",
|
|
22
26
|
userId: "number",
|
|
23
|
-
},
|
|
27
|
+
},
|
|
28
|
+
test_view: {
|
|
24
29
|
id: "number",
|
|
25
30
|
name: "string",
|
|
26
31
|
itemName: ["pen", "ruler", "tiger"],
|
|
27
|
-
},
|
|
32
|
+
},
|
|
33
|
+
item_view: {
|
|
28
34
|
id: "number",
|
|
29
35
|
name: ["pen", "ruler", "tiger"],
|
|
30
36
|
amount: "number",
|
|
31
37
|
price: "number",
|
|
32
|
-
}
|
|
38
|
+
},
|
|
39
|
+
};
|
|
@@ -6,6 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const chalk_1 = __importDefault(require("chalk"));
|
|
7
7
|
const crypto_1 = require("crypto");
|
|
8
8
|
const mysql2_1 = __importDefault(require("mysql2"));
|
|
9
|
+
function log(input) {
|
|
10
|
+
const { action, table } = input;
|
|
11
|
+
console.log(`${action} ${table}`);
|
|
12
|
+
}
|
|
9
13
|
class GGMySQLConnector {
|
|
10
14
|
constructor(DBInfo) {
|
|
11
15
|
this.printResultLength = (results, executionTime, queryResult) => {
|
|
@@ -27,7 +31,7 @@ class GGMySQLConnector {
|
|
|
27
31
|
}
|
|
28
32
|
async createDatabaseIfNotExist(tempConnection) {
|
|
29
33
|
const currentDatabaseName = this.DBInfo.database;
|
|
30
|
-
console.log("currentDatabaseName", currentDatabaseName)
|
|
34
|
+
// console.log("currentDatabaseName", currentDatabaseName)
|
|
31
35
|
return new Promise((resolve, reject) => {
|
|
32
36
|
tempConnection.query(`CREATE DATABASE IF NOT EXISTS ${currentDatabaseName}`, () => {
|
|
33
37
|
resolve();
|
|
@@ -131,7 +135,7 @@ class GGMySQLConnector {
|
|
|
131
135
|
let result = (await this.query(`DELETE FROM ${tableName} WHERE id = ?`, [
|
|
132
136
|
id,
|
|
133
137
|
]));
|
|
134
|
-
console.log(
|
|
138
|
+
// console.log(`table ${tableName} id ${id} => Delete Success`)
|
|
135
139
|
// this.webSocket.sendByURL("/websocket/watchTableChange", tableName)
|
|
136
140
|
return result;
|
|
137
141
|
}
|
|
@@ -162,26 +166,25 @@ class GGMySQLConnector {
|
|
|
162
166
|
}
|
|
163
167
|
valueArrayToInsertInQuery.push(valueListToInsert);
|
|
164
168
|
}
|
|
165
|
-
console.log(valueArrayToInsertInQuery.slice(0, 5));
|
|
166
169
|
const result = (await this.query(`INSERT INTO ${tableName} (${keyListToInsert.join(",")}) VALUES ?`, [valueArrayToInsertInQuery]));
|
|
167
|
-
console.log(
|
|
170
|
+
// console.log(`table ${tableName as string} => Insert Success`)
|
|
168
171
|
// this.webSocket.sendByURL("/websocket/watchTableChange", String(tableName))
|
|
169
172
|
return result;
|
|
170
173
|
}
|
|
171
174
|
async updateOnlyID(tableName, params) {
|
|
172
175
|
const isNewIdExist = await this.query(`SELECT * FROM ${tableName} WHERE id = ? `, [params.newID]);
|
|
173
176
|
if (isNewIdExist.length >= 1) {
|
|
174
|
-
console.
|
|
177
|
+
console.error(`error : newID (${params.newID}) is already exist`);
|
|
175
178
|
return null;
|
|
176
179
|
}
|
|
177
180
|
let result = (await this.query(`UPDATE ${tableName} SET id = ? WHERE id = ?`, [params.newID, params.oldID], false));
|
|
178
|
-
console.log("UpdateOnlyID Success")
|
|
181
|
+
// console.log("UpdateOnlyID Success")
|
|
179
182
|
// this.webSocket.sendByURL("/websocket/watchTableChange", String(tableName))
|
|
180
183
|
return result;
|
|
181
184
|
}
|
|
182
185
|
async update(tableName, parameter) {
|
|
183
186
|
const columnList = await this.getColumnList(tableName);
|
|
184
|
-
console.log(parameter)
|
|
187
|
+
// console.log(parameter)
|
|
185
188
|
const keyList = Object.keys(parameter);
|
|
186
189
|
const keyListToInsert = [];
|
|
187
190
|
const valueListToInsert = [];
|
|
@@ -209,7 +212,7 @@ class GGMySQLConnector {
|
|
|
209
212
|
index++;
|
|
210
213
|
}
|
|
211
214
|
let result = (await this.query(`UPDATE ${tableName} SET ${temp.join(",")} WHERE id = ${parameter.id}`, [], false));
|
|
212
|
-
console.log(
|
|
215
|
+
// console.log(`table : ${tableName} => Update Success`)
|
|
213
216
|
// this.webSocket.sendByURL("/websocket/watchTableChange", String(tableName))
|
|
214
217
|
return result;
|
|
215
218
|
}
|
|
@@ -264,6 +264,12 @@ class ModelGenerator {
|
|
|
264
264
|
if (columnChecker || tableName.search("_view") >= 0) {
|
|
265
265
|
const possibleValue = this.getPossibleColumnValue(params.model, cRow.TABLE_NAME, cRow.COLUMN_NAME, cRow.COLUMN_TYPE);
|
|
266
266
|
if (possibleValue) {
|
|
267
|
+
// value = `${value} \n ${cRow.COLUMN_NAME}: [${possibleValue
|
|
268
|
+
// .map((row) => {
|
|
269
|
+
// if (typeof row === "string") return `"${row}"`
|
|
270
|
+
// else if (typeof row === "number") return `${row}`
|
|
271
|
+
// })
|
|
272
|
+
// .join(" , ")}] as ${typeof possibleValue[0]}[],`
|
|
267
273
|
value = `${value} \n ${cRow.COLUMN_NAME}: [${possibleValue
|
|
268
274
|
.map((row) => {
|
|
269
275
|
if (typeof row === "string")
|
|
@@ -271,7 +277,7 @@ class ModelGenerator {
|
|
|
271
277
|
else if (typeof row === "number")
|
|
272
278
|
return `${row}`;
|
|
273
279
|
})
|
|
274
|
-
.join(" , ")}]
|
|
280
|
+
.join(" , ")}] as const,`;
|
|
275
281
|
}
|
|
276
282
|
else {
|
|
277
283
|
value = `${value} \n ${cRow.COLUMN_NAME}: "${(0, convertDataType_1.convertDataType)(cRow.DATA_TYPE)}",`;
|
|
@@ -27,13 +27,6 @@ class MyDBMigrator {
|
|
|
27
27
|
await this.alterDataType(row.tableName, col);
|
|
28
28
|
await this.alterUniqueKey(row.tableName, col.COLUMN_NAME, col.IS_UNIQUE, indexList);
|
|
29
29
|
await this.alterIndex(row.tableName, col.COLUMN_NAME, col.IS_INDEX, indexList);
|
|
30
|
-
//!! delete this next version. need to execute only 1 time on production
|
|
31
|
-
try {
|
|
32
|
-
await this.deleteOldIndexVersion(row.tableName, col.COLUMN_NAME, indexList);
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
console.log(error);
|
|
36
|
-
}
|
|
37
30
|
await this.alterPossibleEnum(row.tableName, col.COLUMN_NAME, col.POSSIBLE_VALUE, col.IS_NOT_NULL);
|
|
38
31
|
await this.alterForeignKey(row.tableName, col);
|
|
39
32
|
}
|
package/package.json
CHANGED
|
@@ -3,6 +3,14 @@ import { randomUUID } from "crypto"
|
|
|
3
3
|
import mysql, { QueryResult, RowDataPacket } from "mysql2"
|
|
4
4
|
import { DatabaseConfigInterface } from "../ModelGenerator/ModelGenerator"
|
|
5
5
|
|
|
6
|
+
function log(input: {
|
|
7
|
+
table: string
|
|
8
|
+
action: "select" | "update" | "delete" | "delete only id" | "delete by id"
|
|
9
|
+
}) {
|
|
10
|
+
const { action, table } = input
|
|
11
|
+
console.log(`${action} ${table}`)
|
|
12
|
+
}
|
|
13
|
+
|
|
6
14
|
export interface ClassDBInterface<Main> {
|
|
7
15
|
connection: mysql.Pool
|
|
8
16
|
query<T>(
|
|
@@ -81,7 +89,7 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
|
|
|
81
89
|
}
|
|
82
90
|
async createDatabaseIfNotExist(tempConnection: mysql.Pool): Promise<void> {
|
|
83
91
|
const currentDatabaseName = this.DBInfo.database
|
|
84
|
-
console.log("currentDatabaseName", currentDatabaseName)
|
|
92
|
+
// console.log("currentDatabaseName", currentDatabaseName)
|
|
85
93
|
return new Promise((resolve, reject) => {
|
|
86
94
|
tempConnection.query(
|
|
87
95
|
`CREATE DATABASE IF NOT EXISTS ${currentDatabaseName}`,
|
|
@@ -238,7 +246,7 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
|
|
|
238
246
|
let result = (await this.query(`DELETE FROM ${tableName} WHERE id = ?`, [
|
|
239
247
|
id,
|
|
240
248
|
])) as mysql.OkPacket
|
|
241
|
-
console.log(
|
|
249
|
+
// console.log(`table ${tableName} id ${id} => Delete Success`)
|
|
242
250
|
// this.webSocket.sendByURL("/websocket/watchTableChange", tableName)
|
|
243
251
|
return result
|
|
244
252
|
}
|
|
@@ -277,14 +285,13 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
|
|
|
277
285
|
}
|
|
278
286
|
valueArrayToInsertInQuery.push(valueListToInsert)
|
|
279
287
|
}
|
|
280
|
-
console.log(valueArrayToInsertInQuery.slice(0, 5))
|
|
281
288
|
const result = (await this.query(
|
|
282
289
|
`INSERT INTO ${tableName as string} (${keyListToInsert.join(
|
|
283
290
|
","
|
|
284
291
|
)}) VALUES ?`,
|
|
285
292
|
[valueArrayToInsertInQuery]
|
|
286
293
|
)) as mysql.OkPacket
|
|
287
|
-
console.log(
|
|
294
|
+
// console.log(`table ${tableName as string} => Insert Success`)
|
|
288
295
|
// this.webSocket.sendByURL("/websocket/watchTableChange", String(tableName))
|
|
289
296
|
return result
|
|
290
297
|
}
|
|
@@ -298,7 +305,7 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
|
|
|
298
305
|
[params.newID]
|
|
299
306
|
)
|
|
300
307
|
if (isNewIdExist.length >= 1) {
|
|
301
|
-
console.
|
|
308
|
+
console.error(`error : newID (${params.newID}) is already exist`)
|
|
302
309
|
return null
|
|
303
310
|
}
|
|
304
311
|
let result = (await this.query(
|
|
@@ -307,7 +314,7 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
|
|
|
307
314
|
false
|
|
308
315
|
)) as mysql.OkPacket
|
|
309
316
|
|
|
310
|
-
console.log("UpdateOnlyID Success")
|
|
317
|
+
// console.log("UpdateOnlyID Success")
|
|
311
318
|
// this.webSocket.sendByURL("/websocket/watchTableChange", String(tableName))
|
|
312
319
|
return result
|
|
313
320
|
}
|
|
@@ -319,7 +326,7 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
|
|
|
319
326
|
}>
|
|
320
327
|
) {
|
|
321
328
|
const columnList = await this.getColumnList(tableName)
|
|
322
|
-
console.log(parameter)
|
|
329
|
+
// console.log(parameter)
|
|
323
330
|
const keyList = Object.keys(parameter)
|
|
324
331
|
const keyListToInsert = []
|
|
325
332
|
const valueListToInsert = []
|
|
@@ -354,7 +361,7 @@ export default class GGMySQLConnector<Main> implements ClassDBInterface<Main> {
|
|
|
354
361
|
false
|
|
355
362
|
)) as mysql.OkPacket
|
|
356
363
|
|
|
357
|
-
console.log(
|
|
364
|
+
// console.log(`table : ${tableName} => Update Success`)
|
|
358
365
|
// this.webSocket.sendByURL("/websocket/watchTableChange", String(tableName))
|
|
359
366
|
return result
|
|
360
367
|
}
|
|
@@ -356,12 +356,18 @@ export default class ModelGenerator {
|
|
|
356
356
|
cRow.COLUMN_TYPE
|
|
357
357
|
)
|
|
358
358
|
if (possibleValue) {
|
|
359
|
+
// value = `${value} \n ${cRow.COLUMN_NAME}: [${possibleValue
|
|
360
|
+
// .map((row) => {
|
|
361
|
+
// if (typeof row === "string") return `"${row}"`
|
|
362
|
+
// else if (typeof row === "number") return `${row}`
|
|
363
|
+
// })
|
|
364
|
+
// .join(" , ")}] as ${typeof possibleValue[0]}[],`
|
|
359
365
|
value = `${value} \n ${cRow.COLUMN_NAME}: [${possibleValue
|
|
360
366
|
.map((row) => {
|
|
361
367
|
if (typeof row === "string") return `"${row}"`
|
|
362
368
|
else if (typeof row === "number") return `${row}`
|
|
363
369
|
})
|
|
364
|
-
.join(" , ")}]
|
|
370
|
+
.join(" , ")}] as const,`
|
|
365
371
|
} else {
|
|
366
372
|
value = `${value} \n ${cRow.COLUMN_NAME}: "${convertDataType(
|
|
367
373
|
cRow.DATA_TYPE
|
|
@@ -55,16 +55,6 @@ export default class MyDBMigrator {
|
|
|
55
55
|
col.IS_INDEX,
|
|
56
56
|
indexList
|
|
57
57
|
)
|
|
58
|
-
//!! delete this next version. need to execute only 1 time on production
|
|
59
|
-
try {
|
|
60
|
-
await this.deleteOldIndexVersion(
|
|
61
|
-
row.tableName,
|
|
62
|
-
col.COLUMN_NAME,
|
|
63
|
-
indexList
|
|
64
|
-
)
|
|
65
|
-
} catch (error) {
|
|
66
|
-
console.log(error)
|
|
67
|
-
}
|
|
68
58
|
|
|
69
59
|
await this.alterPossibleEnum(
|
|
70
60
|
row.tableName,
|