UNPKG

iagate-querykit

Version:

QueryKit: lightweight TypeScript query toolkit with models, views, triggers, events, scheduler and adapters (better-sqlite3).

72 lines 2.41 kB
type TriggerEvent = 'INSERT' | 'UPDATE' | 'DELETE'; type TriggerTiming = 'BEFORE' | 'AFTER' | 'INSTEAD OF'; export type SemanticTriggerAction = 'INSERT' | 'UPDATE' | 'DELETE' | 'READ'; export type SemanticTriggerTiming = 'BEFORE' | 'AFTER'; export type NormalizedFilter = { type: string; column?: string; operator?: string; value?: any; logical?: 'AND' | 'OR'; not?: boolean; }; export type TriggerContext = { table: string; action: SemanticTriggerAction; timing: SemanticTriggerTiming; data?: any; where?: { sql: string; bindings: any[]; filters?: NormalizedFilter[]; }; rows?: any[]; result?: { changes?: number; lastInsertRowid?: number | bigint; }; }; export type SemanticTriggerBody = string | ((ctx: TriggerContext) => any | Promise<any>); export type ParallelBody = { parallel: (SemanticTriggerBody)[]; }; export type SemanticTriggerBodyUnion = SemanticTriggerBody | SemanticTriggerBody[] | ParallelBody; export type CreateSemanticTriggerOptions = { when: SemanticTriggerTiming; action: SemanticTriggerAction | '*' | Array<SemanticTriggerAction | '*'>; except?: Array<SemanticTriggerAction | '*'>; table: string | string[]; body: SemanticTriggerBodyUnion; state?: 'bank' | 'state'; }; export declare class TriggerManager { private static semantic; private static eventNameFor; private static runBody; private static attachListenerFor; private static serializeBodyToSql; private static extractSqlStrings; private static extractNonSql; create(name: string, opts: CreateSemanticTriggerOptions): void; drop(name: string): void; dropAsync(name: string): Promise<void>; dropAll(): void; list(): string[]; listDetailed(): { bank_triggers: string[]; state_triggers: string[]; }; listDetailedAsync(): Promise<{ bank_triggers: string[]; state_triggers: string[]; }>; createTrigger(name: string, tableName: string, timing: TriggerTiming, event: TriggerEvent, body: string): void; dropTrigger(name: string): void; private triggerQueriesByDialect; listTriggers(): string[]; triggerExists(name: string): boolean; listTriggersAsync(): Promise<string[]>; triggerExistsAsync(name: string): Promise<boolean>; } export {}; //# sourceMappingURL=trigger-manager.d.ts.map