dblang/src/query.ts
jusax23 e33dbcdfca
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
add limit
2023-01-23 22:10:33 +01:00

52 lines
No EOL
1.3 KiB
TypeScript

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;
}
limitD: number | null = null;
limit(i: number) {
this.limitD = i;
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]);
}
}