UNPKG

@lordfokas/magic-orm

Version:

A class-based ORM in TypeScript. Unorthodox and extremely opinionated, made to fit my specific use cases.

50 lines (49 loc) 1.54 kB
import { type Connection } from './DB.js'; import { Entity } from './Entity.js'; import { Primitive } from './Structures.js'; export declare class QueryBuilder { #private; constructor(entity: typeof Entity, fields: string[]); protected where(cond: string): this; protected param(...params: Primitive[]): this; filter(filters: Filter[], entity: typeof Entity): this; protected injectConditions(sql: string[]): void; protected fields(): string[]; protected params(): Primitive[]; protected conds(): string[]; protected table(): string; protected entity(): typeof Entity; } export declare class SelectBuilder extends QueryBuilder { #private; constructor(entity: typeof Entity, fields: string); order(order: string): this; join(master: SelectBuilder, reverse?: boolean): this; count(): this; chains(): Chain[]; execute(db: Connection): Promise<any>; } export declare class UpdateBuilder extends QueryBuilder { constructor(entity: Entity, fields: string[]); execute(db: Connection): Promise<any>; } export type Filter = FilterIn | FilterVar | FilterVal; export type FilterIn = { col: string; in: Primitive[]; }; export type FilterVar = { col: string; op?: Op; var: Primitive; }; export type FilterVal = { col: string; op?: Op; val: Primitive; }; export type Op = "=" | "<" | ">" | "<=" | ">=" | "<>" | "!=" | "IS" | "IS NOT" | "NOT"; export type Chain = { readonly parent: typeof Entity; readonly child: typeof Entity; };