Skip to main content

SqbServiceBase

SqbServiceBase is the abstract base class for all @opra/sqb service classes. It wires up the database connection and transaction support. You do not extend it directly — use SqbCollectionService or SqbSingletonService instead.

import { SqbServiceBase } from '@opra/sqb';

Hierarchy: ServiceBase → SqbServiceBase


Constructor​

new SqbServiceBase(options?: SqbServiceBase.Options)

Methods​

withTransaction​

withTransaction<U>(
callback: (connection: SqbConnection, _this: this) => U,
): Promise<U>

Executes callback inside a database transaction. If a transaction is already active on the current context it joins that transaction instead of starting a new one. The callback receives the active SqbConnection and a transaction-scoped copy of the service.


getConnection​

getConnection(): SqbConnection | SqbClient | Promise<SqbConnection | SqbClient>

Returns the active database connection for the current context. Throws if no connection is configured.


Interfaces​

SqbServiceBase.Options​

Extends ServiceBase.Options.

OptionTypeDescription
dbSqbClient | SqbConnection | ((_this) => SqbClient | SqbConnection)Database client or connection. Can be a static value or a function computed per request.