clean up and view modifier
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
jusax23 2023-02-14 18:13:06 +01:00
parent d763d2a35e
commit 711d2d2c7a
3 changed files with 35 additions and 21 deletions

View file

@ -112,13 +112,14 @@ export class Table {
return handler.builders.escapeID(this.dbLangTableName); return handler.builders.escapeID(this.dbLangTableName);
} }
addAttribute(name: string, type: Datatype, ops: attributeSettings = {}, noErrorOnNameConflict = false) { addAttribute(name: string, type: Datatype, ops: attributeSettings = {}, noErrorOnNameConflict = false) {
name = name.toLowerCase(); let lowName = name.toLowerCase();
if (this.dbLangTableAttributes[name] != null) throw new Error("You are tring to create an Attribute twise!"); if (this.dbLangTableAttributes[lowName] != null) throw new Error("You are tring to create an Attribute twise!");
let attr = new Attribute(name, this, type, ops); let attr = new Attribute(lowName, this, type, ops);
this.dbLangTableAttributes[name] = attr; this.dbLangTableAttributes[lowName] = attr;
if (["serialize", "toString", "addAttribute", "dbLangTableName", "dbLangTableAttributes", "dbLangDatabaseInstance", "addConstraint", "addAttributes"].includes(name)) { if (["serialize", "toString", "addAttribute", "dbLangTableName", "dbLangTableAttributes", "dbLangDatabaseInstance", "addConstraint", "addAttributes"].includes(lowName)) {
if (!noErrorOnNameConflict) throw new Error("You cannot name Attribute like Methode of this Table!"); if (!noErrorOnNameConflict) throw new Error("You cannot name Attribute like Methode of this Table!");
} else { } else {
this[lowName] = attr;
this[name] = attr; this[name] = attr;
} }
return attr; return attr;

View file

@ -411,21 +411,6 @@ export class Handler {
qb.addCode(")"); qb.addCode(")");
return qb; return qb;
}, },
/*// add constraints
appPrimaryKeys: (handler: Handler, table: Table): QueryBuilder => new QueryBuilder(),
appForeignKeys: (handler: Handler, table: Table): QueryBuilder => new QueryBuilder(),
addUniqueKeys: (handler: Handler, table: Table): QueryBuilder => new QueryBuilder(),
addChecks: (handler: Handler, table: Table): QueryBuilder => new QueryBuilder(),
//should drop all keys to be able to recreate them
dropPrimaryKeys: (handler: Handler, table: Table): QueryBuilder => new QueryBuilder(),
dropForeignKeys: (handler: Handler, table: Table): QueryBuilder => new QueryBuilder(),
dropUniqueKeys: (handler: Handler, table: Table): QueryBuilder => new QueryBuilder(),
dropChecks: (handler: Handler, table: Table): QueryBuilder => new QueryBuilder(),
// check constraints
listPrimaryKeys: (handler: Handler, table: Table): QueryBuilder => new QueryBuilder(),
listForeignKeys: (handler: Handler, table: Table): QueryBuilder => new QueryBuilder(),
listUniqueKeys: (handler: Handler, table: Table): QueryBuilder => new QueryBuilder(),
listChecks: (handler: Handler, table: Table): QueryBuilder => new QueryBuilder(),*/
} }
builders = { builders = {
@ -499,6 +484,8 @@ export class Handler {
ge: joinArg(">"), ge: joinArg(">"),
plus: joinArg("+"), plus: joinArg("+"),
minus: joinArg("-"), minus: joinArg("-"),
mult: joinArg("*"),
divide: joinArg("-/"),
not: (handler: Handler, a: allModifierInput[]): QueryBuilder => { not: (handler: Handler, a: allModifierInput[]): QueryBuilder => {
let e = a[0]; let e = a[0];
if (e instanceof Attribute) return new QueryBuilder([{ data: "not (" + e.toString(handler) + ")" }]) if (e instanceof Attribute) return new QueryBuilder([{ data: "not (" + e.toString(handler) + ")" }])
@ -513,7 +500,28 @@ export class Handler {
{ data: "not(" }, { data: "not(" },
{ inject: true, data: e }, { inject: true, data: e },
{ data: ")" } { data: ")" }
]) ]);
},
like: (handler: Handler, a: allModifierInput[]): QueryBuilder => {
const builder = new QueryBuilder();
if (a[0] instanceof Attribute) builder.addCode(a[0].toString());
else if (a[0] instanceof Modifier || a[0] instanceof selectQuery || a[0] instanceof Aggregation) {
const builder = new QueryBuilder();
builder.append(a[0].serialize(handler));
return builder;
}else{
builder.addInjection(a[0]);
}
builder.addCode(" LIKE ");
if (a[1] instanceof Attribute) builder.addCode(a[1].toString());
else if (a[1] instanceof Modifier || a[1] instanceof selectQuery || a[1] instanceof Aggregation) {
const builder = new QueryBuilder();
builder.append(a[1].serialize(handler));
return builder;
}else{
builder.addInjection(a[1]);
}
return builder;
} }
} }
datatypes = { datatypes = {

View file

@ -13,6 +13,11 @@ export const leq = (...args: (allModifierInput)[]) => new BooleanModifier("leq",
export const le = (...args: (allModifierInput)[]) => new BooleanModifier("le", args); export const le = (...args: (allModifierInput)[]) => new BooleanModifier("le", args);
export const plus = (...args: (allModifierInput)[]) => new NumberModifier("plus", args); export const plus = (...args: (allModifierInput)[]) => new NumberModifier("plus", args);
export const minus = (...args: (allModifierInput)[]) => new NumberModifier("minus", args); export const minus = (...args: (allModifierInput)[]) => new NumberModifier("minus", args);
export const mult = (...args: (allModifierInput)[]) => new NumberModifier("mult", args);
export const divide = (...args: (allModifierInput)[]) => new NumberModifier("divide", args);
export const not = (...args: (allModifierInput)[]) => new BooleanModifier("not", args);
export const like = (a: allModifierInput, b: allModifierInput) => new BooleanModifier("like", [a, b]);
//aggregations //aggregations