gg-mysql-connector 1.0.129 → 1.0.131

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.
@@ -129,7 +129,7 @@ class MyDBMigrator {
129
129
  async alterPrimaryKey(tableName, col) {
130
130
  // console.log("alterPrimaryKey()")
131
131
  if (col.COLUMN_NAME === "id" && col.AUTO_INCREMENT === true) {
132
- const isPrimaryKey = await this.checkIsPrimaryKey(tableName, col.COLUMN_NAME);
132
+ const isPrimaryKey = await this.checkIsPrimaryKey(this.MyDB.dbInfo.database, tableName, col.COLUMN_NAME);
133
133
  // recheck only id
134
134
  if (isPrimaryKey === false && col.COLUMN_NAME === "id")
135
135
  await this.MyDB.query(`ALTER TABLE ${tableName} ADD PRIMARY KEY(id);`);
@@ -274,15 +274,17 @@ class MyDBMigrator {
274
274
  loopCount++;
275
275
  }
276
276
  }
277
- async checkIsPrimaryKey(tableName, columnName) {
278
- // let result: any = await this.MyDB.query(`SELECT *
279
- // FROM INFORMATION_SCHEMA.COLUMNS
280
- // WHERE TABLE_SCHEMA='${databaseName}'
281
- // AND TABLE_NAME='${tableName}'
282
- // AND COLUMN_NAME='${columnName}'`)
283
- const result2 = this.onetimeLoadColumnContent.find((row) => row.TABLE_NAME === tableName && columnName === columnName);
284
- if (result2) {
285
- if (result2.COLUMN_KEY === "PRI")
277
+ async checkIsPrimaryKey(databaseName, tableName, columnName) {
278
+ let result = (await this.MyDB.query(`SELECT *
279
+ FROM INFORMATION_SCHEMA.COLUMNS
280
+ WHERE TABLE_SCHEMA='${databaseName}'
281
+ AND TABLE_NAME='${tableName}'
282
+ AND COLUMN_NAME='${columnName}'`));
283
+ // const result2 = this.onetimeLoadColumnContent.find(
284
+ // (row) => row.TABLE_NAME === tableName && columnName === columnName
285
+ // )
286
+ if (result.length) {
287
+ if (result[0].COLUMN_KEY === "PRI")
286
288
  return true;
287
289
  else
288
290
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gg-mysql-connector",
3
- "version": "1.0.129",
3
+ "version": "1.0.131",
4
4
  "description": "",
5
5
  "main": "dist/src/index.js",
6
6
  "scripts": {
@@ -207,6 +207,7 @@ export default class MyDBMigrator {
207
207
  // console.log("alterPrimaryKey()")
208
208
  if (col.COLUMN_NAME === "id" && col.AUTO_INCREMENT === true) {
209
209
  const isPrimaryKey = await this.checkIsPrimaryKey(
210
+ this.MyDB.dbInfo.database,
210
211
  tableName,
211
212
  col.COLUMN_NAME
212
213
  )
@@ -413,19 +414,23 @@ export default class MyDBMigrator {
413
414
  }
414
415
  }
415
416
 
416
- private async checkIsPrimaryKey(tableName: string, columnName: string) {
417
- // let result: any = await this.MyDB.query(`SELECT *
418
- // FROM INFORMATION_SCHEMA.COLUMNS
419
- // WHERE TABLE_SCHEMA='${databaseName}'
420
- // AND TABLE_NAME='${tableName}'
421
- // AND COLUMN_NAME='${columnName}'`)
417
+ private async checkIsPrimaryKey(
418
+ databaseName: string,
419
+ tableName: string,
420
+ columnName: string
421
+ ) {
422
+ let result = (await this.MyDB.query(`SELECT *
423
+ FROM INFORMATION_SCHEMA.COLUMNS
424
+ WHERE TABLE_SCHEMA='${databaseName}'
425
+ AND TABLE_NAME='${tableName}'
426
+ AND COLUMN_NAME='${columnName}'`)) as { COLUMN_KEY: string }[]
422
427
 
423
- const result2 = this.onetimeLoadColumnContent.find(
424
- (row) => row.TABLE_NAME === tableName && columnName === columnName
425
- )
428
+ // const result2 = this.onetimeLoadColumnContent.find(
429
+ // (row) => row.TABLE_NAME === tableName && columnName === columnName
430
+ // )
426
431
 
427
- if (result2) {
428
- if (result2.COLUMN_KEY === "PRI") return true
432
+ if (result.length) {
433
+ if (result[0].COLUMN_KEY === "PRI") return true
429
434
  else return false
430
435
  } else return false
431
436
  }