AdapterRegistry
AdapterRegistry is the static registry that database adapter packages (e.g. @sqb/postgres)
register themselves into, and that SqbClient queries when it resolves the
driver/dialect you passed in ClientConfiguration. See
Creating a Client for how this
plays out from an application's point of view — you rarely need to call AdapterRegistry
directly unless you're writing your own adapter package.
Every method on AdapterRegistry is static; the class is never instantiated.
Methods
findDialect()
static findDialect(dialect: string): Adapter | undefined
Returns the first registered Adapter whose dialect matches, or
undefined. This is what SqbClient calls when you construct it with { dialect: '...' }.
findDriver()
static findDriver(driver: string): Adapter | undefined
Returns the first registered Adapter whose driver matches, or undefined. This is what
SqbClient calls when you construct it with { driver: '...' }.
getAll()
static getAll(dialect: string): Adapter[]
Returns every registered adapter matching a given dialect (useful when more than one driver package targets the same SQL dialect).
register()
static register(...adapters: Adapter[]): void
Registers one or more adapters. Adapter packages call this as a side effect of being imported —
throws A DatabaseAdapter must contain "driver" property if an adapter is missing its driver
field.
import { AdapterRegistry } from '@sqb/connect';
import { PgAdapter } from './pg-adapter.js';
AdapterRegistry.register(new PgAdapter());
unRegister()
static unRegister(...adapters: Adapter[]): void
Removes previously registered adapters — mainly useful in tests.
has()
static has(adapter: Adapter): boolean
Returns true if the given adapter instance is currently registered.
get()
static get(index: number): Adapter | undefined
Returns the adapter at a given index in registration order.
items()
static items(): IterableIterator<Adapter>
Returns an iterator over every registered adapter.
forEach()
static forEach(callback: (value: Adapter, index: number) => void, thisArg?: any): void
Iterates over every registered adapter.
Properties
| Property | Type | Description |
|---|---|---|
size | number | Number of currently registered adapters. |