import { Attribute, DB } from "./db"; import { BooleanModifier, Modifier } from "./dbStructure"; import { Handler } from "./defaultHandler"; import { primaryData, selectElements, selectFromElements, serializeReturn } from "./types"; export class Query { sql : string; values : primaryData[]; constructor(sql: string, values: primaryData[]) { this.sql = sql; this.values = values; } } export class selectQuery { attr:selectElements[] = []; from:selectFromElements; constructor(a: selectElements[], from:selectFromElements) { this.attr.push(...a.flat(Infinity)); this.from = from ? from : null; } whereD:BooleanModifier | null = null; where(m: BooleanModifier) { this.whereD = m; return this; } groupByD: Attribute[] = []; groupBy(a: Attribute[]) { this.groupByD = a; return this; } havingD:Modifier | null = null; having(m: Modifier) { this.havingD = m; return this; } serialize(handler = Handler) : serializeReturn { return handler.querys.select(this); } query(db: DB) { const s = this.serialize(db.getHandler()); return new Query(s[0],s[1]); } }