import { ConnectionInfo } from './engine'; import { FlushOptions } from './flush'; import { Record } from './record'; import { RecordConfig } from './loader'; import { Schema, Model, Field, SimpleField, ForeignKeyField, RelatedField } from './schema'; import { Schema as SchemaConfig } from './config'; import { Column as ColumnInfo, Constraint, Document, DocumentValue, MutationOptions, SelectFields, TableCreate, TableFilter, TableInsert, TableRow, TableUpdate, Value } from './types'; import { Connection, ConnectionPool, Row } from './engine'; export type Filter = Document | Document[]; import { FieldMap, JsonFilterOptions, OperatorMap, QueryBuilder } from './filter'; import { FieldOptions } from './select'; import { ViewOptions } from './view'; export declare class ClosureTable { table: Table; ancestor: ForeignKeyField; descendant: ForeignKeyField; depth?: SimpleField | undefined; constructor(table: Table, ancestor: ForeignKeyField, descendant: ForeignKeyField, depth?: SimpleField | undefined); } export declare class Database { name: string; schema: Schema; operatorMap: OperatorMap; jsonFilterOptions?: JsonFilterOptions; pool: ConnectionPool; tableMap: { [key: string]: Table; }; tableList: Table[]; constructor(connection: ConnectionPool | ConnectionInfo, schema?: Schema, operatorMap?: OperatorMap, jsonFilterOptions?: JsonFilterOptions); getModels(bulk?: boolean): { [key: string]: any; }; buildSchema(config?: SchemaConfig): Promise; clone(): Database; private setSchema; table(name: Name): Table; table(name: string | Field | Model): Table; model(name: string): Model; append(name: Name, data: TableCreate): Record; append(name: string, data: { [key: string]: any; }): any; getDirtyCount(): number; flush(flushOptions?: FlushOptions): Promise<{ connection: Connection; complete: boolean; }>; end(): Promise; clear(): this; json(): { [key: string]: Document[]; }; query(fmt: string, ...args: unknown[]): Promise; select(options: DatabaseSelectOptions, connection?: Connection): Promise; cleanup(): Promise; zap(excludes?: string[]): Promise; } export type OrderBy = string | string[]; export interface SelectOptions { where?: TFilter; offset?: number; limit?: number; orderBy?: OrderBy; groupBy?: string[]; having?: Filter; raw?: boolean; } export declare const SelectOptionKeys: (keyof SelectOptions)[]; export interface DatabaseSelectOptions extends SelectOptions { fields: string | string[]; from: string | ViewOptions; } export declare class Table { db: Database; name: string; model: Model; closureTable?: ClosureTable; recordList: Record[]; recordMap: { [key: string]: { [key: string]: Record; }; }; noInsert: boolean; selectOnly?: Document; constructor(db: Database, model: Model); column(name: string): ColumnInfo; keyColumn(): ColumnInfo; getParentField(model?: Model): ForeignKeyField; getAncestors(row: Value | Document, filter?: TableFilter | Filter): Promise; getDescendants(row: Value | Document, filter?: TableFilter | Filter): Promise; select>(fields: SelectFields | string | Document | string[], options?: SelectOptions | Filter>, filterThunk?: (builder: QueryBuilder) => string, connection?: Connection): Promise; first>(fields: SelectFields | string | Document | string[], filter?: TableFilter | Filter, orderBy?: OrderBy): Promise; _resolveRelatedFields(connection: Connection, result: Document[], fields: string | Document): Promise; get>(key: Value | TableFilter | Filter): Promise; insert(data: TableInsert): Promise; create>(data: TableCreate, options?: MutationOptions): Promise; update(data: TableUpdate, filter?: TableFilter): Promise; upsert>(data: TableCreate, update?: TableUpdate, options?: MutationOptions): Promise; modify>(data: TableUpdate, filter: TableFilter, options?: MutationOptions): Promise; private _call; delete(filter?: Filter): Promise; replace(data: Document): Promise; count(filter?: Filter, expr?: string): Promise; existing(data: Document): Promise>; private _name; private _where; private _pair; private _select; _update(connection: Connection, fields: Document, filter: Filter): Promise; _insert(connection: Connection, data: Row): Promise; _delete(connection: Connection, filter?: Filter): Promise; /** * Deletes rows matching `filter` one level at a time, leaves first, following a * self-referential foreign key. This avoids relying on the database's ON DELETE * CASCADE for the self-reference, whose cascade depth MySQL caps (error 6575: * "Foreign key cascade delete/update exceeds max tables limit"). It assumes the * matched set is closed under descendants, which holds for replaceRecordsIn (a * kept record's parent is always kept too). */ _deleteLeaves(connection: Connection, filter: Filter, selfField: ForeignKeyField): Promise; escapeName(name: SimpleField | string | number): string; escapeValue(field: SimpleField | string, value: Value): string; _get(connection: Connection, key: Value | Filter): Promise; _resolveParentFields(connection: Connection, input: Document, filter?: Filter): Promise; private _returning; _create(connection: Connection, data: Document, options?: MutationOptions): Promise; private _upsert; private _modify; private _updateChildFields; private _updateChildField; _disconnectUnique(connection: Connection, field: SimpleField, id: Value): Promise; _connectThrough(connection: Connection, related: RelatedField, value: Value, args: Document[]): Promise; private _createThrough; private _upsertThrough; private _updateThrough; _deleteThrough(connection: Connection, related: RelatedField, value: Value, args: Document[]): Promise; _disconnectThrough(connection: Connection, related: RelatedField, value: Value, args: Document[]): Promise; claim(filter: Filter, data: Document, orderBy?: string[]): Promise; append(data?: { [key: string]: any; } | any[]): Record; connect(data?: { [key: string]: any; } | any[]): Record; clear(): void; getDirtyCount(): number; json(): Document[]; _mapGet(record: Record): Record | undefined; _mapPut(record: Record): void; _initMap(): void; _selectRelated(connection: Connection, field: RelatedField, values: Value[], fields: string | Document, selectOptions: SelectOptions): Promise<(Document | Document[] | DocumentValue[])[]> | Promise<(string | number | boolean | Date | import("./types").JsonValue[] | Document | import("./types").ScalarValue[] | Document[] | null | undefined)[] | DocumentValue[][]>; xappend(data: Document | Document[], fields: RecordConfig, defaults?: Document, keys?: string[]): Promise; xselect(fields: RecordConfig, options?: SelectOptions, keys?: string[]): Promise<{ [key: string]: any; }[]>; _xselect(config: RecordConfig, options?: SelectOptions): Promise; selectTree(filter: Filter, options?: FieldOptions): Promise; mock(data?: Document, save?: boolean): Promise; mockMany(data: Document[], save?: boolean): Promise; } export declare function _toCamel(value: Value | any, field: SimpleField): Value | any; export declare function toDocument(row: Row, model: Model, fieldMap?: FieldMap): Document; export declare function isEmpty(value: Value | Record | any): boolean; export declare function shouldSelectSeparately(model: Model, fields: string | Document): boolean; export declare function getUniqueFields(model: Model, row: Document): Row | undefined;