From 287de2e09fab9d7616a480ae16b2b9e3cb02961d Mon Sep 17 00:00:00 2001 From: jusax23 Date: Wed, 15 Feb 2023 16:45:55 +0100 Subject: [PATCH] moved constraint data query --- src/defaultHandler.ts | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/defaultHandler.ts b/src/defaultHandler.ts index c643775..8a34be5 100644 --- a/src/defaultHandler.ts +++ b/src/defaultHandler.ts @@ -5,17 +5,9 @@ import { allModifierInput, joinType, onAction, primaryData } from "./types" export class Handler { async syncDB(db: DB, handler: Handler, deleteInDB: boolean = false) { - let gd = new QueryBuilder(); - gd.addCode(`SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE where CONSTRAINT_SCHEMA = `); - gd.addInjection(db.name); - gd.addCode(` or TABLE_SCHEMA = `); - gd.addInjection(db.name); - gd.addCode(`;select * from information_schema.table_constraints where CONSTRAINT_SCHEMA = `); - gd.addInjection(db.name) - gd.addCode(` or TABLE_SCHEMA = `); - gd.addInjection(db.name); - - let [key, constraints] = await db.query(handler.builders.query(gd)); + //Constraint Data + let constraints = await db.query(handler.builders.query(handler.querys.listConstraints(handler, db))); + let key = await db.query(handler.builders.query(handler.querys.listConstraintDetails(handler, db))); //Table List let allTables = (await db.query(handler.builders.query(handler.querys.listTables(handler, db)))).map((d: any) => d.TABLE_NAME); @@ -334,6 +326,22 @@ export class Handler { qb.addCode(` and TABLE_TYPE = "BASE TABLE"`); return qb; }, + listConstraints: (handler: Handler, db: DB) => { + let qb = new QueryBuilder(); + qb.addCode(`select * from information_schema.table_constraints where CONSTRAINT_SCHEMA = `); + qb.addInjection(db.name); + qb.addCode(` or TABLE_SCHEMA = `); + qb.addInjection(db.name); + return qb; + }, + listConstraintDetails: (handler: Handler, db: DB) => { + let qb = new QueryBuilder(); + qb.addCode(`SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE where CONSTRAINT_SCHEMA = `); + qb.addInjection(db.name); + qb.addCode(` or TABLE_SCHEMA = `); + qb.addInjection(db.name); + return qb; + }, create: (handler: Handler, table: Table): QueryBuilder => { const builder = new QueryBuilder(); builder.addCode(`create table if not exists ${table.toString(handler)}(`);