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 { export class Handler {
async syncDB(db: DB, handler: Handler, deleteInDB: boolean = false) { async syncDB(db: DB, handler: Handler, deleteInDB: boolean = false) {
let gd = new QueryBuilder(); //Constraint Data
gd.addCode(`SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE where CONSTRAINT_SCHEMA = `); let constraints = await db.query(handler.builders.query(handler.querys.listConstraints(handler, db)));
gd.addInjection(db.name); let key = await db.query(handler.builders.query(handler.querys.listConstraintDetails(handler, db)));
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));
//Table List //Table List
let allTables = (await db.query(handler.builders.query(handler.querys.listTables(handler, db)))).map((d: any) => d.TABLE_NAME); 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"`); qb.addCode(` and TABLE_TYPE = "BASE TABLE"`);
return qb; 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 => { create: (handler: Handler, table: Table): QueryBuilder => {
const builder = new QueryBuilder(); const builder = new QueryBuilder();
builder.addCode(`create table if not exists ${table.toString(handler)}(`); builder.addCode(`create table if not exists ${table.toString(handler)}(`);