To support a database not currently shipped with Datazen, implement the same core abstractions used by existing adapters.
Datazen currently focuses on runtime DBAL concerns (driver, connection, platform, query execution, type conversion), and now includes a partial Schema module. If you are adding runtime support only, you can ship a driver/platform without schema-manager parity first.
For a new driver on an already supported platform, implement:
DriverConnection(src/driver.ts)Driver(src/driver.ts)- driver-specific exception converter (
src/driver/api/*/exception-converter.ts)
For a new database platform (new vendor/dialect), also implement:
AbstractPlatformsubclass (src/platforms/*)- vendor type mappings and SQL generation overrides
- optionally, a vendor
AbstractSchemaManagersubclass (src/schema/*) if you want schema-introspection parity
DriverConnection must provide:
prepare(sql)->Promise<DriverStatement>query(sql)->Promise<DriverResult>exec(sql)->Promise<number | string>quote(value)->stringlastInsertId()->Promise<number | string>- transaction APIs (
beginTransaction,commit,rollBack) - optional savepoint APIs (
createSavepoint,releaseSavepoint,rollbackSavepoint) getServerVersion()(string | Promise<string>)close()getNativeConnection()
Driver must provide:
connect(params)(async)getExceptionConverter()getDatabasePlatform(versionProvider)
Note: built-in drivers also expose a bindingStyle property used by Connection
for placeholder compilation, but this is currently a convention (duck-typed) and
not part of the exported Driver interface.
If your driver is named-binding, Connection will compile positional SQL
placeholders into named placeholders automatically.
- Add a new folder under
src/driver/<your-driver>/. - Implement:
connection.ts(implementsDriverConnection)driver.ts(implementsDriver)types.ts(driver client/pool type contracts)
- Add exception converter under
src/driver/api/<vendor>/exception-converter.ts. - Register exports in
src/index.ts. - If using a built-in shortcut name, add it to
DriverManager:DriverNameunion insrc/driver-manager.tsDRIVER_MAPentry insrc/driver-manager.ts
- Create
src/platforms/<vendor>-platform.tsextendingAbstractPlatform. - Implement vendor SQL behavior:
- limit/offset SQL
- quoting rules
- date/time functions and format strings
- transaction isolation SQL
- lock hints (if supported)
- Implement
initializeDatazenTypeMappings()for DB type -> Datazen type names. - Add driver adapter as in Path A and return your platform from
Driver#getDatabasePlatform(). - (Optional, schema parity) add a vendor schema manager and return it from the
platform's
createSchemaManager(connection)implementation. - Export the platform from
src/platforms/index.tsandsrc/index.ts.
Built-in adapters are pool/client-first. Define clear params shape in your
src/driver/<vendor>/types.ts, then validate in driver.ts similarly to
existing drivers.
Recommended pattern:
- Accept
pool,connection, orclientaliases when practical. - Support ownership flags (
ownsPool/ownsClient) for lifecycle control.
Follow existing parity pattern and add tests at minimum for:
- Driver contract behavior (
src/__tests__/driver/*) - Connection adapter execution and transactions (
src/__tests__/driver/*-connection.test.ts) - Exception conversion mapping (
src/__tests__/driver/driver-exception-converter.test.tsstyle) - Platform SQL behavior (
src/__tests__/platforms/*) if adding a platform
If you add parser- or parameter-related behavior, also add tests under:
src/__tests__/parameter/*src/__tests__/sql/*
You can avoid touching DriverManager map and pass your driver directly:
import { DriverManager } from "@devscast/datazen";
const conn = DriverManager.getConnection({
driverInstance: new CustomDriver(),
client,
});Or via class:
const conn = DriverManager.getConnection({
driverClass: CustomDriver,
client,
});For Node adapters, prefer:
- package as peer dependency for runtime driver library
- package installed as dev dependency for local tests/examples
This mirrors current mysql2 / mssql integration strategy.
- Keep one class/interface per file.
- Keep namespace/folder parity best effort with Doctrine naming.
- Add or update tests for every new behavior.
- Run:
bun run formatbun run test
- Add a
CHANGELOG.mdsummary entry.