Setu-TS
    Preparing search index...

    Class DatabaseService

    Database service implementation wrapping an ORM adapter.

    0.1.0

    Implements

    Index
    • Creates a database service over one adapter and repository data-source factory.

      Parameters

      • _adapter: IDatabaseAdapter

        The underlying database adapter (internal contract with scoped tx factory).

      • _createDataSource: (entity: string) => IDataSource

        Factory that creates a DataSource for a named entity (non-transactional).

      • _adapterType: DatabaseAdapterType

        The adapter type (used for unsupported-operation checks).

      • Optional_options: DatabaseAdapterOptions

        Adapter-specific options for logging and tuning.

      • Optional_logger: { debug(msg: string, meta?: Record<string, unknown>): void }

        Optional logger for query logging.

      • _now: () => number = ...

        Monotonic clock — injected from ctx.runtime.hrtime(). NEVER Date.now().

      • _setTimer: (fn: () => void, ms: number) => unknown = defaultSetTimer

        Timer arm for the bounded reachability probe — injected from ctx.runtime.

      • _clearTimer: (handle: unknown) => void = defaultClearTimer

        Timer clearance arm — injected from ctx.runtime.

      Returns DatabaseService

    • get hasReachabilityProbe(): boolean

      Whether the adapter carries a reachability probe at all (M95b §3.5) — a synchronous read, because once the call is wrapped in the bound this is the only way absence is observable. The indicator maps absence to today's behaviour (up, reachable OMITTED, /ready 200): a probe that was never written is evidence of nothing.

      Returns boolean

    • get isClosed(): boolean

      Reports whether close has run — a LIFECYCLE-only read that reaches no adapter and performs no I/O (M90b).

      isHealthy() answers two questions at once: the service's own lifecycle AND the adapter's readiness. The database health indicator gates on lifecycle uncached — a closed database must read down immediately, never from an outcome cached before close — and bounds the adapter question inside its cached probe. Reading isHealthy() for the gate therefore called the adapter on the ONE path that is deliberately outside that bound, and made a poll cost two readiness reads instead of one. This is the gate.

      Returns boolean

      true once the service has been closed

      0.5.0

    • Bounded backend liveness (M95b §3.5) — the database twin of IMessageBroker.reachability() (M70c's tri-state), so the two capabilities report through one shape.

      undefined when the adapter carries no probe at all, when the probe has not answered within the 2 s bound, or when it rejects: "could not determine" is a different fact from "contacted and refused", and the indicator maps the two differently (degraded vs down). DatabaseService.isHealthy keeps its lifecycle gate and its published signature; this is the member the indicator reads.

      Returns Promise<boolean | undefined>

      true/false from the adapter's probe, undefined when no answer was produced inside the bound

    • Execute the work callback within a database transaction.

      On success the transaction commits and the callback result is returned. On error the transaction rolls back and the error propagates.

      Type Parameters

      • T

        Return type of the work callback

      Parameters

      • work: (uow: IUnitOfWork) => Promise<T>

        Function receiving a transaction-scoped Unit of Work

      • Optionaloptions: TransactionOptions

        Optional transaction settings, including requested isolation

      Returns Promise<T>

      The result of the work callback

      If the work callback throws — transaction is rolled back

      0.1.0