@devscast/datazen
v1.1.4
Published
DataZen : TypeScript Database Abstraction Layer
Readme
DataZen: TypeScript Database Abstraction Layer
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.
Installation
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.
Documentation
- Introduction
- Doctrine/Datazen Parity Notes
- Architecture
- Configuration
- Data Retrieval and Manipulation
- Query Builder
- Types
- Portability
- Platforms
- Transactions
- Security
- Known Vendor Issues
- Supporting Other Databases
Quick Start (MySQL)
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.
Quick Start (SQL Server)
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");Query Builder Example
const qb = conn
.createQueryBuilder()
.select("u.id", "u.email")
.from("users", "u")
.where("u.email = :email")
.setParameter("email", "[email protected]");
const user = await qb.fetchAssociative();Attribution
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.
