UNPKG

@sqb/connect

Version:

Multi-dialect database connection framework written with TypeScript

66 lines (65 loc) 2.29 kB
import { classes } from '@sqb/builder'; import { Pool as LightningPool } from 'lightning-pool'; import { Maybe, Type } from 'ts-gems'; import { Repository } from '../orm/repository.class.js'; import { SqbConnection } from './sqb-connection.js'; import { ClientConfiguration, ClientDefaults, ConnectionOptions, QueryExecuteOptions, QueryRequest, QueryResult, TransactionFunction } from './types.js'; declare const inspect: unique symbol; interface SqbClientEvents { execute: (request: QueryRequest) => void; error: (error: Error) => void; closing: () => void; close: () => void; acquire: (connection: SqbConnection) => Promise<void>; terminate: () => void; 'connection-return': (connection: SqbConnection) => Promise<void>; } declare const SqbClient_base: Type<import("strict-typed-events").TypedEventEmitter<any, SqbClientEvents, SqbClientEvents>>; export declare class SqbClient extends SqbClient_base { private readonly _adapter; private readonly _pool; private readonly _defaults; private readonly _entities; constructor(config: ClientConfiguration); get defaults(): ClientDefaults; /** * Returns dialect */ get dialect(): string; /** * Returns database driver name */ get driver(): string; /** * Returns true if pool is closed */ get isClosed(): boolean; get pool(): LightningPool; /** * Obtains a connection from the connection pool and executes the callback */ acquire(fn: TransactionFunction, options?: ConnectionOptions): Promise<any>; /** * Obtains a connection from the connection pool. */ acquire(options?: ConnectionOptions): Promise<SqbConnection>; /** * Shuts down the pool and destroys all resources. */ close(terminateWait?: number): Promise<void>; /** * Executes a query or callback with a new acquired connection. */ execute(query: string | classes.Query, options?: QueryExecuteOptions): Promise<QueryResult>; /** * Tests the pool */ test(): Promise<void>; getRepository<T>(entity: Type<T> | string, opts?: { schema?: string; }): Repository<T>; getEntity<T>(name: string): Maybe<Type<T>>; toString(): string; [inspect](): string; } export {};