import type { Knex } from 'knex'; import { Dialect } from './dialects'; import { SchemaProvider } from './schema'; import { Metadata } from './metadata'; import { EntityManager } from './entity-manager'; import { MigrationProvider } from './migrations'; import { LifecycleProvider } from './lifecycles'; import * as errors from './errors'; import { Callback, TransactionObject } from './transaction-context'; import type { Model } from './types'; import { type RepairManager } from './repairs'; export { isKnexQuery } from './utils/knex'; export { isDatabaseClientKind } from './connection'; export { attributeNaming } from './metadata'; export { createField } from './fields'; export type { AttributeNaming, Meta } from './metadata'; export type { AttributeRenamesOperation, Migration, BuiltMigrationFile, MigrationFileBuilder, MigrationFileFormat, MigrationFileOperation, } from './migrations'; export type { Event } from './lifecycles'; export type { Attribute, Model, JoinTable } from './types'; export type { AttributeRenameHandler, AttributeRenames } from './schema'; export type { Identifiers } from './utils/identifiers'; export { POOL_TIMEOUT_CODE } from './pool-diagnostics'; export type { EventLoopDelay, PoolDiagnostics, PoolState, PoolTimeoutDetails, } from './pool-diagnostics'; interface Settings { forceMigration?: boolean; runMigrations?: boolean; /** * Describe the pool on knex connection pool timeouts (details on the error, a docs link, one * warning block per 30 s). Defaults to true; false leaves knex's error untouched. Must be a * boolean (for example `env.bool('DATABASE_POOL_TIMEOUT_DIAGNOSTICS', true)`): a string is not * read as false. */ poolTimeoutDiagnostics?: boolean; /** * Maximum time in milliseconds a query run through the query builder's `execute()` may run * before the database cancels it. Unset by default (no limit). Only applied on clients that * can cancel queries (postgres, mysql); ignored on sqlite. Streams, direct `db.connection` * queries, schema sync, and migrations are not covered. Must be a positive number (for * example `env.int('DATABASE_QUERY_TIMEOUT')`). */ queryTimeout?: number; migrations: { dir: string; }; [key: string]: unknown; } export type Logger = Record<'info' | 'warn' | 'error' | 'debug', (message: string | Record) => void>; export interface DatabaseConfig { connection: Knex.Config; settings: Settings; logger?: Logger; /** Lifecycle phase of the host application, e.g. "boot" or "runtime", for pool timeout reports. */ getPhase?: () => string | undefined; } declare class Database { connection: Knex; dialect: Dialect; config: DatabaseConfig; metadata: Metadata; schema: SchemaProvider; migrations: MigrationProvider; lifecycles: LifecycleProvider; entityManager: EntityManager; repair: RepairManager; logger: Logger; /** Set unless `settings.poolTimeoutDiagnostics` is false or the install failed. */ private poolDiagnostics?; private phase?; constructor(config: DatabaseConfig); init({ models }: { models: Model[]; }): Promise; query(uid: string): import("./entity-manager").Repository; inTransaction(): boolean; /** * Labels pool timeout reports raised while `fn` runs, for example "schema sync". Nested calls * restore the outer label. Calls that overlap without nesting can restore the wrong label; core * only nests them (schema sync, then a migration). * * The label is process-wide, not per call: a call made at runtime relabels every concurrent * timeout report until it returns. It is meant for boot-time work (schema sync, migrations). * * @internal */ runInPhase(phase: string, fn: () => Promise): Promise; /** * Run work inside a DB transaction. On a fulfilled callback, the transaction * is committed; on rejection, it is rolled back. The callback receives Knex * `commit` and `rollback` helpers: if you call `rollback` and return without * throwing, the implementation avoids attempting a second `commit` on an * already-finalised transactor. * * A call inside another transaction joins it, without a savepoint: it neither commits nor rolls * back on its own. If `cb` throws and a caller catches the error, the writes `cb` made before * the error are committed with the outer transaction. Use `savepoint` to undo them. */ transaction(): Promise; transaction(c: TCallback): Promise>; /** * Runs `cb` in a savepoint of the current transaction, so a failure undoes only `cb`'s writes. * If `cb` throws, its writes are rolled back, the `onCommit` callbacks registered in it are * dropped, its `onRollback` callbacks run, and the error is rethrown. The transaction stays * usable, on Postgres also after a database error, but not after a MySQL deadlock, which rolls * back the whole transaction: the savepoint then can't be rolled back to, and it throws an * `errors.SavepointError`, as when it can't be released. Throws if called outside a transaction. */ savepoint(cb: () => Promise | T): Promise; /** * Starts a top-level knex transaction. knex resolves it through a promise chain that async stack * traces cannot follow, so on failure the stack is extended with the frames of our callers. */ private startTransaction; getSchemaName(): string | undefined; getConnection(): Knex; getConnection(tableName?: string): Knex.QueryBuilder; getInfo(): { displayName: string; schema: any; client: string; }; getSchemaConnection(trx?: Knex): Knex.SchemaBuilder; queryBuilder(uid: string): import("./query/query-builder").QueryBuilder; /** * Wait for `onCommit` and `onRollback` hooks still running on this database. * The transaction call itself does not wait, so a test that reads a hook's * side effect does. `destroy()` stops waiting after 10 seconds. */ settleTransactionHooks(timeoutMs?: number): Promise; destroy(): Promise; } export { Database, errors }; //# sourceMappingURL=index.d.ts.map