fixed custom constraints
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
jusax23 2023-02-14 20:40:25 +01:00
parent 711d2d2c7a
commit 7c4d4fb9c7
3 changed files with 14 additions and 6 deletions

View file

@ -16,7 +16,7 @@ export class DB {
this.name = database; this.name = database;
} }
async query(query: Query) { async query(query: Query) {
console.log(query); //console.log(query);
return await this.pool.query(query); return await this.pool.query(query);
} }
getHandler() { getHandler() {
@ -41,6 +41,9 @@ export class DB {
for (let i = 0; i < this.tables.length; i++) if (this.tables[i].dbLangTableName == name) return this.tables[i]; for (let i = 0; i < this.tables.length; i++) if (this.tables[i].dbLangTableName == name) return this.tables[i];
return null; return null;
} }
async close() {
if (this.pool) await this.pool.end();
}
} }
export class Attribute { export class Attribute {

View file

@ -465,7 +465,6 @@ export class Handler {
}, },
} }
aggregations = { aggregations = {
count: (handler: Handler, a: Attribute): QueryBuilder => new QueryBuilder([{ data: "count(" + a.toString(handler) + ")" }]), count: (handler: Handler, a: Attribute): QueryBuilder => new QueryBuilder([{ data: "count(" + a.toString(handler) + ")" }]),
sum: (handler: Handler, a: Attribute): QueryBuilder => new QueryBuilder([{ data: "sum(" + a.toString(handler) + ")" }]), sum: (handler: Handler, a: Attribute): QueryBuilder => new QueryBuilder([{ data: "sum(" + a.toString(handler) + ")" }]),
@ -524,6 +523,7 @@ export class Handler {
return builder; return builder;
} }
} }
datatypes = { datatypes = {
char: dataTypeSingleNum("char"), char: dataTypeSingleNum("char"),
varchar: dataTypeSingleNum("varchar"), varchar: dataTypeSingleNum("varchar"),

View file

@ -1,5 +1,5 @@
import { Attribute } from "./db"; import { Attribute } from "./db";
import { Aggregation, BooleanModifier, checkConstraint, Datatype, NumberModifier } from "./dbStructure"; import { Aggregation, BooleanModifier, checkConstraint, Datatype, foreignConstraint, NumberModifier, uniqueConstraint } from "./dbStructure";
import { selectQuery } from "./query"; import { selectQuery } from "./query";
import { allModifierInput, primaryData, selectElements, selectFromElements } from "./types"; import { allModifierInput, primaryData, selectElements, selectFromElements } from "./types";
@ -71,8 +71,13 @@ export const YEAR = new Datatype("year", []);
// Constraints // Constraints
//TODO: //TODO:
//primary key //primary key
export const foreginKey = (attrs: Attribute[], target: Attribute[]) => { }; export const foreignKey = (attrs: Attribute[], target: Attribute[]) => new foreignConstraint(
export const uniqueKey = (attr: Attribute[]) => { }; "foreign_constraint_"
+ attrs.map(a => a.name + "_" + a.table.dbLangTableName).join("_")
+ "_to_"
+ target.map(a => a.name + "_" + a.table.dbLangTableName).join("_"),
attrs, target);
export const uniqueKey = (attrs: Attribute[]) => new uniqueConstraint("unique_constraint_" + attrs.map(a => a.name + "_" + a.table.dbLangTableName).join("_"), attrs);
export const check = (name: string, mod: BooleanModifier) => new checkConstraint(name, mod); export const check = (name: string, mod: BooleanModifier) => new checkConstraint(name, mod);