The Cosmos adapter — an Azure Cosmos DB NoSQL-API backend.
Constructed by DatabasePlugin for the 'cosmos' arm, and also
constructible directly by an application for the 'custom' arm.
Example 1
Example 1
import { DatabasePlugin } from '@setu-ts/database-plugin'; app.register(DatabasePlugin({ type: 'cosmos', options: { endpoint: 'https://my-account.documents.azure.com:443/', key: config.getOrThrow('COSMOS_KEY'), database: 'app', containers: { Order: { container: 'orders', partitionKey: 'tenantId' } }, }, }));
CosmosAdapter(options: CosmosAdapterOptions)
Creates the adapter.
options: CosmosAdapterOptions
The 'cosmos' arm options
transactionIsolationLevels: readonly TransactionIsolationLevel[]
Cosmos DB exposes no portable transaction-isolation selector.
beginTransaction(options?: TransactionOptions): Promise<IAdapterTransaction>
Opens a deferred-write transaction whose buffer is flushed as one transactional batch at commit.
Cosmos has no interactive transaction, so reads inside it observe
committed state only and every write lands at commit — the contract's
deferred-write clause, and the shape D1Adapter established.
connect(): Promise<void>
Establishes the connection: resolves the client and proves the database is reachable with these credentials.
Nothing is retained until the connection is fully established, and the in-flight attempt is never cached past settlement — holding a rejected promise would turn one transient outage into a permanently unusable adapter.
createDataSource(entity: string): IDataSource
Returns a data source for the named entity's container. @inheritdoc
disconnect(): Promise<void>
Releases the client and the per-container caches.
The SDK client holds no socket the adapter must close — it is a
fetch-based handle — so this drops the references rather than closing
something, and an injected client stays usable by the application that
supplied it.
isReady(): boolean
Reports whether the adapter is connected. @inheritdoc
rawQuery<T>(_sql: string,_params?: unknown[]): Promise<T[]>
Refuses the raw query by name.
Cosmos has a SQL dialect, but every query is scoped to ONE container and this signature has nowhere to name it — guessing one would be the silent divergence M70j closed elsewhere. An application reaches the injected client directly for a container-scoped query.
It rejects, never throws synchronously.