@dazejs/framework
Version:
Daze.js - A powerful web framework for Node.js
132 lines (131 loc) • 5.43 kB
TypeScript
import { Actuator } from '../actuator/actuator';
import { Parser } from '../parser';
import { Join } from './join';
export type TSymlink = 'and' | 'or' | '';
export type TJoinType = 'inner' | 'left' | 'right' | 'cross';
export interface ColumnDescribeOption {
type: 'column' | 'raw';
column: string;
as?: string;
}
interface WhereDescribeOption {
type: 'value' | 'column' | 'sql' | 'in' | 'notIn' | 'null' | 'notNull';
column?: string;
operator?: string;
value?: any;
symlink: TSymlink;
}
interface HavingDescribeOption {
type: 'value';
column: string;
operator: string;
value: any;
symlink: TSymlink;
}
interface AggregateOption {
func: string;
column: string;
}
interface UnionOption {
builder: Builder;
isAll: boolean;
}
interface OrderOption {
type: 'column' | 'raw';
column: string;
direction?: string;
}
type BindingKeys = 'select' | 'from' | 'join' | 'where' | 'having' | 'order' | 'union';
export declare class Builder {
_distinct: boolean | string[];
_aggregate?: AggregateOption;
_columns: ColumnDescribeOption[];
_table: string;
_alias: string;
_wheres: WhereDescribeOption[];
_orders: OrderOption[];
_limit?: number;
_offset?: number;
_lock: boolean | string;
_groups: string[];
_joins: Join[];
_havings: HavingDescribeOption[];
_unions: UnionOption[];
params: any[];
bindings: Map<BindingKeys, any[]>;
parser: Parser;
actuator: Actuator;
private shouldLogSql;
private shouldDumpSql;
constructor(actuator: Actuator, parser: Parser);
removeAggregate(): this;
select(...columns: (string | string[])[]): this;
selectSub(query: Builder | ((query: Builder) => Builder | void), as: string): this;
selectRaw(raw: string, bindings?: any[]): this;
fields(...columns: (string | string[])[]): this;
columns(...columns: (string | string[])[]): this;
table(table: string, as?: string): this;
alias(as: string): this;
where(column: string | [string, any, any?, TSymlink?][], operator?: any, value?: any, symlink?: TSymlink): this;
orWhere(column: string | [string, any, any?][], operator: any, value?: any): this;
whereRaw(sql: string, params?: any[], symlink?: TSymlink): this;
orWhereRaw(sql: string, params?: any[]): this;
whereColumn(column: string, operator: string, value?: string, symlink?: TSymlink): this;
whereIn(column: string, value: any[], symlink?: TSymlink): this;
orWhereIn(column: string, value: any[]): this;
whereNotIn(column: string, value: any[], symlink?: TSymlink): this;
orWhereNotIn(column: string, value: any[]): this;
whereNull(column: string, symlink?: TSymlink, not?: boolean): this;
whereNotNull(column: string, symlink?: TSymlink): this;
orWhereNull(column: string): this;
orWhereNotNull(column: string): this;
orWhereColumn(column: string, operator: string, value?: string): this;
aggregate(type: string, column?: string): Promise<number | undefined>;
count(column?: string): Promise<number>;
max(column: string): Promise<number | undefined>;
min(column: string): Promise<number | undefined>;
sum(column: string): Promise<number>;
avg(column: string): Promise<number | undefined>;
orderBy(column: string, direction?: string): this;
orderByRaw(raw: string): this;
limit(value: number): this;
take(value: number): this;
offset(value: number): this;
skip(value: number): this;
distinct(column?: string | boolean, ...columns: string[]): this;
lock(value: boolean | string): this;
sharedLock(): this;
lockForUpdate(): this;
groupBy(...columns: string[] | string[][]): this;
join(table: string | ((join: Join & Builder) => Join | void), column?: string, operator?: any, value?: any, type?: TJoinType): this;
leftJoin(table: string | ((join: Join & Builder) => Join | void), column?: string, operator?: any, value?: any): this;
rightJoin(table: string | ((join: Join & Builder) => Join | void), column?: string, operator?: any, value?: any): this;
having(column: string, operator: any, value?: any, symlink?: TSymlink): this;
union(builder: Builder | ((union: Builder) => Builder | void), isAll?: boolean): this;
unionAll(builder: Builder | ((union: Builder) => Builder)): this;
addBinding(key: BindingKeys, value: any): this;
getBindings(): any[];
getBindingsWithKeys(keys: BindingKeys[]): any[];
getBindingsExceptKeys(keys: BindingKeys[]): any[];
toSql(): string;
logSql(): this;
log(): this;
dumpSql(): this;
dump(): this;
find(): Promise<any[]>;
findAndCount(): Promise<[any[], number]>;
first(): Promise<Record<string, any> | undefined>;
getBindingsForUpdate(values?: any[]): any[];
getBindingsForDelete(): any[];
private buildDebugSql;
private logDebugSql;
commit(): Promise<void>;
rollback(): Promise<void>;
insertAll(data?: Record<string, any>[]): Promise<string | number>;
insert(data: Record<string, any>): Promise<string | number>;
update(data: Record<string, any>): Promise<string | number>;
increment(column: string, amount?: number, extra?: Record<string, any>): Promise<string | number>;
decrement(column: string, amount?: number, extra?: Record<string, any>): Promise<string | number>;
delete(id?: number | string): Promise<string | number>;
}
export {};