fixed custom constraints
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
711d2d2c7a
commit
7c4d4fb9c7
3 changed files with 14 additions and 6 deletions
|
@ -16,7 +16,7 @@ export class DB {
|
|||
this.name = database;
|
||||
}
|
||||
async query(query: Query) {
|
||||
console.log(query);
|
||||
//console.log(query);
|
||||
return await this.pool.query(query);
|
||||
}
|
||||
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];
|
||||
return null;
|
||||
}
|
||||
async close() {
|
||||
if (this.pool) await this.pool.end();
|
||||
}
|
||||
}
|
||||
|
||||
export class Attribute {
|
||||
|
@ -69,7 +72,7 @@ export class Attribute {
|
|||
}
|
||||
if (ops.foreginKey != null) {
|
||||
table.addConstraint(new foreignConstraint(
|
||||
table.dbLangDatabaseInstance.name + "_" + table.dbLangTableName + "_" + name + "_foreign_constraint_to_"+ops.foreginKey.link.name,
|
||||
table.dbLangDatabaseInstance.name + "_" + table.dbLangTableName + "_" + name + "_foreign_constraint_to_" + ops.foreginKey.link.name,
|
||||
[this],
|
||||
[ops.foreginKey.link],
|
||||
ops.foreginKey.onDelete,
|
||||
|
|
|
@ -465,7 +465,6 @@ export class Handler {
|
|||
},
|
||||
}
|
||||
|
||||
|
||||
aggregations = {
|
||||
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) + ")" }]),
|
||||
|
@ -524,6 +523,7 @@ export class Handler {
|
|||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
datatypes = {
|
||||
char: dataTypeSingleNum("char"),
|
||||
varchar: dataTypeSingleNum("varchar"),
|
||||
|
|
11
src/funcs.ts
11
src/funcs.ts
|
@ -1,5 +1,5 @@
|
|||
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 { allModifierInput, primaryData, selectElements, selectFromElements } from "./types";
|
||||
|
||||
|
@ -71,8 +71,13 @@ export const YEAR = new Datatype("year", []);
|
|||
// Constraints
|
||||
//TODO:
|
||||
//primary key
|
||||
export const foreginKey = (attrs: Attribute[], target: Attribute[]) => { };
|
||||
export const uniqueKey = (attr: Attribute[]) => { };
|
||||
export const foreignKey = (attrs: Attribute[], target: Attribute[]) => new foreignConstraint(
|
||||
"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);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue