Aliases #3

Merged
jusax23 merged 10 commits from dev into main 2023-02-18 15:47:44 +01:00
Showing only changes of commit 287de2e09f - Show all commits

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