moved constraint data query
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
jusax23 2023-02-15 16:45:55 +01:00
parent 2b6e4872d5
commit 287de2e09f

View file

@ -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)}(`);