Skip to content

devscast/datazen-ts

DataZen: TypeScript Database Abstraction Layer

npm npm Lint Tests ci GitHub

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 mysql2

For SQL Server projects:

bun add @devscast/datazen mssql

Other supported runtime drivers include pg and sqlite3.

mysql2, mssql, pg, and sqlite3 are peer dependencies so applications control driver versions.

Documentation

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", "john@example.com");

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.

Contributors

contributors

About

DataZen : Typescript Database Abstraction Layer - Inspired by Doctrine

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors