UNPKG

@opra/sqb

Version:

Opra SQB adapter package

46 lines (45 loc) 1.53 kB
import { ServiceBase } from '@opra/core'; import { SqbClient, SqbConnection } from '@sqb/connect'; /** * Namespace for SqbServiceBase types and options. */ export declare namespace SqbServiceBase { /** * Options for initializing SqbServiceBase. */ interface Options extends ServiceBase.Options { /** * The SQB client or connection used by this service. */ db?: SqbServiceBase['db']; } } /** * Base class for services using SQB (SQL Builder) for database operations. */ export declare class SqbServiceBase extends ServiceBase { /** * The SQB client or connection used by this service. */ db?: (SqbClient | SqbConnection) | ((_this: this) => SqbClient | SqbConnection); /** * Constructs a new instance. * * @param options - Options for the service. */ constructor(options?: SqbServiceBase.Options); /** * Executes the provided callback within a database transaction. * If a transaction is already active in the current context, the callback * joins it rather than starting a new one. * * @param callback - The function to execute within the transaction. */ withTransaction<U = any>(callback: (connection: SqbConnection, _this: this) => U): Promise<U>; /** * Returns the active database connection for the current context. * * @throws If no database connection is configured. */ getConnection(): SqbConnection | SqbClient | Promise<SqbConnection | SqbClient>; }