From 123bbeba6c93d89961142ef59c7c7ea9aeed8884 Mon Sep 17 00:00:00 2001 From: jusax23 Date: Sun, 19 Feb 2023 13:43:19 +0100 Subject: [PATCH 1/2] conn limit and type optional --- src/db.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db.ts b/src/db.ts index f69447d..5685448 100644 --- a/src/db.ts +++ b/src/db.ts @@ -14,7 +14,7 @@ export class DB { type: dbType; mariaPool!: mariadb.Pool; //pgPool!: pg.Pool; - constructor({ host, user, password, database, connectionLimit = 5, databaseType = dbType.mariadb }: { host: string, user: string, password: string, database: string, connectionLimit: number, databaseType: dbType }) { + constructor({ host, user, password, database, connectionLimit = 5, databaseType = dbType.mariadb }: { host: string, user: string, password: string, database: string, connectionLimit?: number, databaseType?: dbType }) { this.type = databaseType; if (databaseType == dbType.mariadb) { this.mariaPool = mariadb.createPool({ host, user, password, database, connectionLimit, multipleStatements: true }); From 88321c76d18ee17556b2a16c60ce151ea94748f7 Mon Sep 17 00:00:00 2001 From: jusax23 Date: Sun, 19 Feb 2023 20:24:25 +0100 Subject: [PATCH 2/2] a_i fix --- src/defaultHandler.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/defaultHandler.ts b/src/defaultHandler.ts index 81398e1..d98d186 100644 --- a/src/defaultHandler.ts +++ b/src/defaultHandler.ts @@ -181,7 +181,7 @@ export class Handler { const attrData = tableD[keys[j]]; if (attrData == null) { create.appendEnding(handler.querys.addColumn(handler, a)); - changePrimary = true; + if (a.ops.primaryKey) changePrimary = true; } else if ( !handler.builders.compareDatatypes(handler, a.type, attrData.Type) || a.ops.default != attrData.Default || @@ -193,14 +193,18 @@ export class Handler { (!!a.ops.notNull || !!a.ops.autoIncrement || !!a.ops.primaryKey), (attrData.Null == "NO"), "|", (!!a.ops.autoIncrement), (attrData.Extra == "auto_increment"));*/ freeForUpdate(a.name, a.table.dbLangTableName); - if (a.ops.autoIncrement) + if (a.ops.autoIncrement) { + a.ops.autoIncrement = false; create.appendEnding(handler.querys.changeColumn(handler, a)); + a.ops.autoIncrement = true; + connst.appendEnding(handler.querys.changeColumn(handler, a)); + } + else create.appendEnding(handler.querys.changeColumn(handler, a)); } - if (attrData == null) { - changePrimary = true; - } else { + if (attrData != null) { if ((attrData.Key == "PRI") != (!!a.ops.primaryKey)) { freeForUpdate(a.name, a.table.dbLangTableName); + console.log("206"); changePrimary = true; } } @@ -454,7 +458,7 @@ export class Handler { let primaAttr = Object.entries(table.dbLangTableAttributes) .filter(([n, attr]) => !!attr.ops.primaryKey); const qb = new QueryBuilder(); - if(primaAttr.length == 0) return qb; + if (primaAttr.length == 0) return qb; qb.addCode("ALTER TABLE "); qb.addCode(table.serialize(handler)); qb.addCode(" add PRIMARY KEY if not exists (");