Creates a database service over one adapter and repository data-source factory.
The underlying database adapter (internal contract with scoped tx factory).
Factory that creates a DataSource for a named entity (non-transactional).
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.
Monotonic clock — injected from ctx.runtime.hrtime(). NEVER Date.now().
Timer arm for the bounded reachability probe — injected from ctx.runtime.
Timer clearance arm — injected from ctx.runtime.
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.
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.
true once the service has been closed
Returns a repository bound to the named entity on the outer database scope.
Programmatic migrations are unsupported by the current adapters. Each ORM
owns schema migration through its own CLI, so this rejects with
UnsupportedMigrationError.
A rejected promise naming the unsupported operation
Optionalparams: unknown[]memory adapter rejects with UnsupportedRawQueryError, so
every refusal from this Promise-returning method is observable through
either await or .catch().
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.
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.
Return type of the work callback
Function receiving a transaction-scoped Unit of Work
Optionaloptions: TransactionOptions
Optional transaction settings, including requested isolation
The result of the work callback
Database service implementation wrapping an ORM adapter.
Since
0.1.0