DataZen is a TypeScript-first DBAL (Database Abstraction Layer) inspired by Doctrine DBAL. It targets teams who want SQL-first development with a stable runtime abstraction, without adopting a full ORM.
Using Bun:
bun add @devscast/datazen mysql2For SQL Server projects:
bun add @devscast/datazen mssqlOther supported runtime drivers include pg and sqlite3.
mysql2, mssql, pg, and sqlite3 are optional peer dependencies so
applications control driver versions and only install the runtime adapters they
actually use.
- Introduction
- Doctrine/Datazen Parity Notes
- Architecture
- Configuration
- Data Retrieval and Manipulation
- Query Builder
- Types
- Portability
- Platforms
- Transactions
- Security
- Known Vendor Issues
- Supporting Other Databases
import mysql from "mysql2/promise";
import { DriverManager } from "@devscast/datazen";
const pool = mysql.createPool({
database: "mydb",
host: "localhost",
password: "secret",
user: "user",
});
const conn = DriverManager.getConnection({
driver: "mysql2",
pool,
});
const value = await conn.fetchOne("SELECT 1");Doctrine examples are often synchronous (PHP request model). In DataZen/Node,
I/O methods are async (await connection/statement/query-builder execution),
while Result fetch/iterate methods are synchronous once a result is available.
import sql from "mssql";
import { DriverManager } from "@devscast/datazen";
const pool = await sql.connect({
database: "mydb",
options: { encrypt: true, trustServerCertificate: true },
password: "secret",
server: "localhost",
user: "user",
});
const conn = DriverManager.getConnection({
driver: "mssql",
pool,
});
const value = await conn.fetchOne("SELECT 1");const qb = conn
.createQueryBuilder()
.select("u.id", "u.email")
.from("users", "u")
.where("u.email = :email")
.setParameter("email", "john@example.com");
const user = await qb.fetchAssociative();This project is fully inspired by the architecture and design of doctrine/dbal.
DataZen is an independent TypeScript/Node implementation and is not affiliated with Doctrine.