import { Attribute, Table } from "./db"; import { Handler } from "./defaultHandler"; import { QueryBuilder } from "./query"; import { allModifierInput, primaryData, serializeReturn } from "./types"; export class Datatype{ type: string; args: primaryData[]; constructor(type:string, args: primaryData[]){ this.type = type; this.args = args; } serialize(handler : Handler): QueryBuilder{ return handler.datatypes[this.type as keyof typeof handler.datatypes](this.args); } } export abstract class Modifier { t: string; a: Array; constructor(type: string, args: (allModifierInput)[]) { this.t = type; this.a = args; } serialize(handler : Handler): QueryBuilder { return handler.modifiers[this.t as keyof typeof handler.modifiers](handler,this.a); } } export class BooleanModifier extends Modifier { } export class NumberModifier extends Modifier { } export class StringModifier extends Modifier { } export class Aggregation { t: string; a: Attribute; constructor(type: string, args: Attribute) { this.t = type; this.a = args; } serialize(handler : Handler): QueryBuilder { return handler.aggregations[this.t as keyof typeof handler.aggregations](handler,this.a); } } export class Joins { serialize(handler : Handler): QueryBuilder { return new QueryBuilder(); } } export interface Constraint{ name:string; serialize( handler: Handler) : QueryBuilder; uses(attr:Attribute): boolean; check(attr:Table): boolean | string; } export class checkConstraint implements Constraint{ checkQuery:BooleanModifier; name: string; constructor(name:string, check: BooleanModifier){ this.name = name; this.checkQuery = check; } check(attr: Table): boolean { return true; } uses(attr: Attribute): boolean { throw new Error("Method not implemented."); } serialize(handler: Handler): QueryBuilder { throw new Error("Method not implemented."); } } export class uniqueConstraint implements Constraint{ name: string; attrs: Attribute[]; constructor(name:string, attrs:Attribute[]){ this.name = name; this.attrs = attrs; } check(table: Table): boolean|string { for(let i = 0; i < this.attrs.length; i++){ if(this.attrs[i].ops.primaryKey) return "Can not combine unique Constraint and primary key"; } return false; } uses(attr: Attribute): boolean { return this.attrs.includes(attr); } serialize(handler: Handler): QueryBuilder { throw new Error("Method not implemented."); } }