iagate-querykit
Version:
QueryKit: lightweight TypeScript query toolkit with models, views, triggers, events, scheduler and adapters (better-sqlite3).
140 lines • 6.46 kB
TypeScript
export type Operator = '=' | '!=' | '<>' | '>' | '>=' | '<' | '<=' | 'LIKE' | 'NOT LIKE' | 'IN' | 'NOT IN' | 'BETWEEN' | 'NOT BETWEEN' | 'IS NULL' | 'IS NOT NULL';
export type RelationshipSelector<T> = (rel: (name: string, select?: string[]) => void) => void;
export declare class QueryBuilder<T extends {
id?: any;
} & Record<string, any>> {
private tableName;
private whereClauses;
private orWhereClauses;
private joins;
private selectColumns;
private orderClauses;
private limitValue?;
private offsetValue?;
private groupByColumns;
private havingClauses;
private isDistinct;
private pendingAction?;
private aggregates;
private tableAlias?;
private unionParts;
private targetBanks?;
private isTracking;
private isSeeding;
private trackingLogs;
private virtualTable;
private includeAllRelations;
constructor(tableName: string);
bank(bankOrBanks: string | string[]): this;
hasPendingWrite(): boolean;
private track;
initial(data?: T[]): Promise<this>;
tracking(): {
step: string;
details: any;
timestamp: Date;
}[];
private applyWhereClausesToVirtual;
private executeVirtualAction;
select(columns?: (keyof T | string)[]): this;
selectRaw(sql: string): this;
aggregatesSelect(columns: string[]): this;
distinct(): this;
where(column: keyof T | string, operator: Operator, value: any): this;
orWhere(column: keyof T | string, operator: Operator, value: any): this;
whereIf(condition: any, column: keyof T | string, operator: Operator, value: any): this;
whereAll(conditions: Partial<T>): this;
insert(data: Partial<T> | Partial<T>[]): this;
update(data: Partial<T>): this;
delete(): this;
updateOrInsert(attributes: Partial<T>, values?: Partial<T>): this;
increment(column: keyof T, amount?: number): this;
decrement(column: keyof T, amount?: number): this;
whereIn(column: keyof T | string, values: any[], logical?: 'AND' | 'OR'): this;
orWhereIn(column: keyof T | string, values: any[]): this;
whereNotIn(column: keyof T | string, values: any[]): this;
orWhereNotIn(column: keyof T | string, values: any[]): this;
whereNull(column: keyof T | string): this;
orWhereNull(column: keyof T | string): this;
whereNotNull(column: keyof T | string): this;
orWhereNotNull(column: keyof T | string): this;
whereBetween(column: keyof T | string, values: [any, any]): this;
whereNotBetween(column: keyof T | string, values: [any, any]): this;
whereColumn(firstColumn: keyof T | string, operator: Operator, secondColumn: keyof T | string, logical?: 'AND' | 'OR'): this;
whereRaw(sql: string, bindings?: any[], logical?: 'AND' | 'OR'): this;
whereRawSearch(searchTerm: string, columns: (keyof T | string)[]): this;
whereExists(query: QueryBuilder<any>): this;
whereNotExists(query: QueryBuilder<any>): this;
when(condition: any, callback: (query: this, value: any) => void): this;
unless(condition: any, callback: (query: this, value: any) => void): this;
clone(): this;
orderBy(column: keyof T | string, direction?: 'ASC' | 'DESC'): this;
orderByMany(orders: {
column: string;
direction?: 'ASC' | 'DESC';
}[]): this;
limit(count: number): this;
offset(count: number): this;
innerJoin(targetTable: string, on: string): this;
leftJoin(targetTable: string, on: string): this;
rightJoin(targetTable: string, on: string): this;
innerJoinOn(targetTable: string, left: string, right: string): this;
leftJoinOn(targetTable: string, left: string, right: string): this;
rightJoinOn(targetTable: string, left: string, right: string): this;
groupBy(columns: (keyof T | string)[]): this;
having(column: keyof T | string, op: Operator, value: any): this;
havingRaw(sql: string, bindings?: any[], logical?: 'AND' | 'OR'): this;
havingIf(condition: any, column: keyof T | string, op: Operator, value: any): this;
toSql(): {
sql: string;
bindings: any[];
};
private buildWhereClause;
get<U = T>(): U | undefined;
first<U = T>(): U | undefined;
find(id: string | number): T | undefined;
exists(): Promise<boolean>;
pluck(column: keyof T): Promise<any[]>;
all<U = T>(): Promise<U[]>;
run(): any;
allSync<U = T>(): U[];
getSync<U = T>(): U | undefined;
firstSync<U = T>(): U | undefined;
pluckSync(column: keyof T | string): any[];
scalarSync<U = any>(alias?: string): U | undefined;
count(column?: string, alias?: string): this;
sum(column: string, alias?: string): this;
avg(column: string, alias?: string): this;
min(column: string, alias?: string): this;
max(column: string, alias?: string): this;
private addAggregate;
selectExpression(expression: string, alias?: string): this;
selectCount(column?: string, alias?: string): this;
selectSum(column: string, alias?: string): this;
selectAvg(column: string, alias?: string): this;
selectMin(column: string, alias?: string): this;
selectMax(column: string, alias?: string): this;
selectCaseSum(conditionSql: string, alias: string): this;
groupByOne(column: keyof T | string): this;
paginate(page?: number, perPage?: number): this;
range(field: keyof T | string, start?: Date, end?: Date): this;
period(field: keyof T | string, periodKey?: '24h' | '7d' | '30d' | string): this;
whereLike(column: keyof T | string, pattern: string): this;
orWhereLike(column: keyof T | string, pattern: string): this;
whereContains(column: keyof T | string, term: string): this;
whereStartsWith(column: keyof T | string, prefix: string): this;
whereEndsWith(column: keyof T | string, suffix: string): this;
whereILike(column: keyof T | string, pattern: string): this;
whereContainsCI(column: keyof T | string, term: string): this;
whereStartsWithCI(column: keyof T | string, prefix: string): this;
whereEndsWithCI(column: keyof T | string, suffix: string): this;
whereSearch(searchTerm: string, columns: (keyof T | string)[]): this;
union(query: QueryBuilder<any>): this;
unionAll(query: QueryBuilder<any>): this;
make(): Promise<{
changes: number;
lastInsertRowid: number | bigint;
}>;
relationship(selector?: RelationshipSelector<T>): this;
}
//# sourceMappingURL=query-builder.d.ts.map