import { Awaitable, Dict } from 'cosmokit'; import { Context, Service } from 'cordis'; import { Eval, Update } from './eval.ts'; import { Direction, Modifier, Selection } from './selection.ts'; import { Field, Model, Relation } from './model.ts'; import { Database } from './database.ts'; import { FlatKeys, Keys, Values } from './utils.ts'; export declare namespace Driver { interface Stats { size: number; tables: Dict; } interface TableStats { count: number; size: number; } type Cursor = any> = K[] | CursorOptions; interface CursorOptions = any> { limit?: number; offset?: number; fields?: K[]; sort?: Partial>>; include?: Relation.Include>; } interface WriteResult { inserted?: number; matched?: number; modified?: number; removed?: number; } interface IndexDef { name?: string; keys: { [P in K]?: 'asc' | 'desc'; }; } interface Index extends IndexDef { unique?: boolean; } interface Transformer { types: Field.Type[]; dump: (value: S | null) => T | null | void; load: (value: T | null) => S | null | void; } } export declare namespace Driver { type Constructor = new (ctx: Context, config: T) => Driver; } export declare abstract class Driver { ctx: Context; config: T; abstract start(): Promise; abstract stop(): Promise; abstract drop(table: string): Promise; abstract dropAll(): Promise; abstract stats(): Promise>; abstract prepare(name: string): Promise; abstract get(sel: Selection.Immutable, modifier: Modifier): Promise; abstract eval(sel: Selection.Immutable, expr: Eval.Expr): Promise; abstract set(sel: Selection.Mutable, data: Update): Promise; abstract remove(sel: Selection.Mutable): Promise; abstract create(sel: Selection.Mutable, data: any): Promise; abstract upsert(sel: Selection.Mutable, data: any[], keys: string[]): Promise; abstract withTransaction(callback: (session?: any) => Promise): Promise; abstract getIndexes(table: string): Promise; abstract createIndex(table: string, index: Driver.Index): Promise; abstract dropIndex(table: string, name: string): Promise; database: Database; types: Dict; constructor(ctx: Context, config: T); [Service.init](): AsyncGenerator<() => void, void, unknown>; model(table: string | Selection.Immutable | Dict): Model; protected migrate(name: string, hooks: MigrationHooks): Promise; define(converter: Driver.Transformer): void; _ensureSession(): Promise; prepareIndexes(table: string): Promise; } export interface MigrationHooks { before: (keys: string[]) => boolean; after: (keys: string[]) => void; finalize: () => Awaitable; error: (reason: any) => void; }