import * as CQN from "./cqn"; import { Definition as RawDef } from "./csn"; import { expr, func, Operator, ref } from "./cxn"; import { Linked } from "./reflect"; type Definition = RawDef | Linked; /** * Query Object with fluent API */ export type QueryObject = SELECT | INSERT | UPDATE | DELETE | CREATE | DROP; export declare class PromiseLike { then(_resolved: (x: any) => any, _rejected: (e: Error) => any): any; } interface Constructable { new (...args: any[]): T; } export declare class QL { SELECT: typeof SELECT & ((...columns: string[]) => SELECT) & ((columns: string[]) => SELECT); INSERT: typeof INSERT & ((...entries: object[]) => INSERT) & ((entries: object[]) => INSERT); UPDATE: typeof UPDATE & typeof UPDATE.entity; DELETE: typeof DELETE; CREATE: typeof CREATE; UPSERT: typeof UPSERT; DROP: typeof DROP; } export declare class SELECT extends PromiseLike { static one: SELECT_one & { from: SELECT_one; }; static distinct: typeof SELECT; static from: SELECT_from; from(entity: Definition | string | QueryObject | CQN.CQN, primaryKey?: number | string | object, projection?: (e: any) => void): this; alias(alias: string): this; byKey(primaryKey?: number | string | object): this; columns(projection: (e: T) => void): this; columns(...col: string[]): this; columns(...col: (ref | func)[]): this; where(predicate: object): this; where(...expr: any[]): this; and(predicate: object): this; and(...expr: any[]): this; having(...expr: string[]): this; having(predicate: object): this; groupBy(...expr: string[]): this; orderBy(...expr: string[]): this; fullJoin(other: string, as?: string): SELECT_join; leftJoin(other: string, as?: string): SELECT_join; rightJoin(other: string, as?: string): SELECT_join; innerJoin(other: string, as?: string): SELECT_join; join(other: string, as?: string, kind?: "inner" | "full" | "left" | "right"): SELECT_join; limit(rows: number, offset?: number): this; /** * locks the selected rows in the current transaction * thereby preventing concurrent updates by other parallel transactions * until the transaction is committed or rolled back * * using a shared lock allows all transactions to read the locked record */ forShareLock(options?: { wait: number; }): this; /** * Exclusively locks the selected rows for subsequent updates in the current transaction, thereby preventing concurrent updates by other parallel transactions. * * @param options */ forUpdate(options?: { wait: number; }): this; SELECT: CQN.SELECT["SELECT"]; } type SELECT_one = ((entity: Definition | string, primaryKey?: number | string | object, projection?: (e: any) => void) => SELECT) & ((entity: T[], projection?: (e: T) => void) => SELECT & Promise) & ((entity: T[], primaryKey: number | string | object, projection?: (e: T) => void) => SELECT & Promise) & ((entity: { new (): T; }, projection?: (e: T) => void) => SELECT & Promise) & ((entity: { new (): T; }, primaryKey: number | string | object, projection?: (e: T) => void) => SELECT & Promise); type SELECT_from = ((entity: Definition | string, primaryKey?: number | string | object, projection?: (e: any) => void) => SELECT) & ((entity: T[], projection?: (e: T) => void) => SELECT & Promise) & ((entity: T[], primaryKey: number | string | object, projection?: (e: T) => void) => SELECT & Promise) & ((entity: { new (): T; }, projection?: (e: T) => void) => SELECT & Promise) & ((entity: { new (): T; }, primaryKey: number | string | object, projection?: (e: T) => void) => SELECT & Promise); interface SELECT_join extends SELECT { on(...expr: Array): SELECT; } export declare class INSERT extends PromiseLike { static into(entity: Definition | string, entries?: object | object[]): INSERT; static into(entity: Constructable, entries?: object | object[]): INSERT; static into(entity: T, entries?: T | object | object[]): INSERT; into(entity: Definition | string): this; as(select: SELECT): this; data(block: (e: T) => void): this; entries(...entries: object[]): this; columns(...col: string[]): this; values(...val: any[]): this; rows(...row: any[]): this; INSERT: CQN.INSERT["INSERT"]; } export declare class UPSERT extends PromiseLike { static into(entity: Definition | string, entries?: object | object[]): INSERT; static into(entity: Constructable, entries?: object | object[]): INSERT; static into(entity: T, entries?: T | object | object[]): INSERT; into(entity: Definition | string): this; as(select: SELECT): this; data(block: (e: T) => void): this; entries(...entries: object[]): this; columns(...col: string[]): this; values(...val: any[]): this; rows(...row: any[]): this; UPSERT: CQN.UPSERT["UPSERT"]; } export declare class DELETE extends PromiseLike { static from(entity: Definition | string, primaryKey?: number | string | object): DELETE; byKey(primaryKey?: number | string | object): this; where(predicate: object): this; where(...expr: any[]): this; and(predicate: object): this; and(...expr: any[]): this; DELETE: CQN.DELETE["DELETE"]; } export declare class UPDATE extends PromiseLike { static entity(entity: Definition | string, primaryKey?: number | string | object): UPDATE; static entity(entity: Constructable, primaryKey?: number | string | object): UPDATE; static entity(entity: T, primaryKey?: number | string | object): UPDATE; byKey(primaryKey?: number | string | object): this; set(data: object): this; with(data: object): this; where(predicate: object): this; where(...expr: any[]): this; and(predicate: object): this; and(...expr: any[]): this; UPDATE: CQN.UPDATE["UPDATE"]; } export declare class CREATE extends PromiseLike { static entity(entity: Definition | string): CREATE; CREATE: CQN.CREATE["CREATE"]; } export declare class DROP extends PromiseLike { static entity(entity: Definition | string): DROP; DROP: CQN.DROP["DROP"]; } export {};