import { TableConstraint, CreateColumnDef, StatementLocation } from './parser/syntax/ast.ts';
export type nil = undefined | null;
export type Schema = { name: string; fields: SchemaField[]; constraints?: TableConstraint[];}
export interface SchemaField extends Omit<CreateColumnDef, 'dataType'> { type: IType; serial?: boolean;}
export interface IType { readonly primary: DataType; toString(): string;}
export enum DataType { text = 'text', array = 'array', long = 'long', float = 'float', decimal = 'decimal', int = 'int', jsonb = 'jsonb', regtype = 'regtype', json = 'json', blob = 'blob', timestamp = 'timestamp', date = 'date', null = 'null', bool = 'bool',}
export interface MemoryDbOptions { readonly autoCreateForeignKeyIndices?: boolean;}
export interface IMemoryDb { readonly adapters: LibAdapters; readonly public: ISchema; getSchema(db?: string | null): ISchema; createSchema(name: string): ISchema; getTable(table: string): IMemoryTable; on(event: 'query', handler: (query: string) => any): ISubscription; on(event: GlobalEvent, handler: () => any): ISubscription; on(event: TableEvent, handler: (table: string) => any): ISubscription;
backup(): IBackup;}
export interface IBackup { restore(): void;}
export interface LibAdapters { createPg(queryLatency?: number): { Pool: any; Client: any };
createPgPromise(queryLatency?: number): any;
createSlonik(queryLatency?: number): any;
createPgNative(queryLatency?: number): any;
createTypeormConnection(typeOrmConnection: any, queryLatency?: number): any;}
export interface ISchema { many(query: string): any[]; none(query: string): void; one(query: string): any; declareTable(table: Schema): IMemoryTable; query(text: string): QueryResult;
queries(text: string): Iterable<QueryResult>}
export interface QueryResult { command: string; rowCount: number; fields: Array<FieldInfo>; rows: any[];
ignored?: boolean; location: StatementLocation;}
export interface FieldInfo { name: string;}
export type TableEvent = 'seq-scan';export type GlobalEvent = 'query' | 'query-failed' | 'catastrophic-join-optimization' | 'schema-change';
export interface IMemoryTable { on(event: TableEvent, handler: () => any): ISubscription; listIndices(): IndexDef[];}
export interface ISubscription { unsubscribe(): void;}
export interface IndexDef { name: string; expressions: string[];}
export class CastError extends Error { constructor(from: DataType, to: DataType, inWhat?: string) { super(`failed to cast ${from} to ${to}` + (inWhat ? ' in ' + inWhat : '')); }}export class ColumnNotFound extends Error { constructor(columnName: string) { super(`column "${columnName}" does not exist`); }}
export class AmbiguousColumn extends Error { constructor(columnName: string) { super(`column "${columnName}" is ambiguous`); }}
export class TableNotFound extends Error { constructor(tableName: string) { super('Table not found: ' + tableName); }}
export class QueryError extends Error {}
export class RecordExists extends Error { constructor() { super('Records already exists'); }}
export class NotSupported extends Error { constructor(what?: string) { super('Not supported' + (what ? ': ' + what : '')); }
static never(value: never, msg?: string) { return new NotSupported(`${msg ?? ''} ${JSON.stringify(value)}`); }}export class ReadOnlyError extends Error { constructor(what?: string) { super('You cannot modify ' + (what ? ': ' + what : 'this')); }}