Skip to content
panatesPublic

About

Extensible, multi-dialect SQL query builder and Database connection framework for NodeJS

Topics

Resources

Code of conduct

Security policy

Stars

18 stars

Watchers

4 watching

Forks

Repository files navigation

SQB

SQB

SQB is a TypeScript database framework for Node.js: a query builder, connection pooling, an ORM and migrations for PostgreSQL, MySQL, MariaDB, SQL Server, Oracle and SQLite.

NPM Version NPM Downloads CI Tests Test Coverage

📖 Documentation · 🚀 Getting Started · 📦 Packages · 💬 Issues

About

SQB gives you a query builder, connection pooling, an ORM and migrations as one TypeScript toolkit. Queries are plain objects that SQB turns into the right SQL for the database you connect to, so the same code runs on every supported database.

Quick start

Install the query builder, the connection layer and one database adapter:

npm install @sqb/builder @sqb/connect @sqb/postgres
import '@sqb/postgres';
import { Eq, Select } from '@sqb/builder';
import { SqbClient } from '@sqb/connect';

const client = new SqbClient({ dialect: 'postgres', host: 'localhost', database: 'mydb' });

const result = await client.execute(
  Select('id', 'given_name').from('customers').where(Eq('active', true)).limit(10),
);
console.log(result.rows);

To read and write typed entities through repositories instead, see the ORM guide. The full documentation is at sqbjs.org.

Packages

Most projects need @sqb/builder, @sqb/connect and one database adapter.

Package Description
@sqb/builder The query builder: SQL statements as objects, serialized for any dialect.
@sqb/connect Connection pooling, transactions, cursors and the ORM (entities, repositories).
@sqb/migrator A versioned schema and data migration runner.
@sqb/nestjs A NestJS module that provides an @sqb/connect client.
@sqb/adapter-tests The conformance test suite every adapter runs.
Database Adapter Driver
PostgreSQL @sqb/postgres postgrejs
MySQL @sqb/mysql mysql2
MariaDB @sqb/mariadb mariadb
Microsoft SQL Server @sqb/mssql mssql
Oracle Database @sqb/oracle oracledb
SQLite @sqb/sqlite node:sqlite / bun:sqlite
SQLite (WebAssembly) @sqb/sqljs sql.js

Each adapter loads its -dialect package, which holds that database's SQL syntax. Depend on a -dialect package directly only to generate SQL without connecting.

Node.js compatibility

Node.js 22 or later. @sqb/sqlite needs Node.js 22.5 or later, the first release with node:sqlite.

Issues

Report bugs and discuss features on the GitHub issues page.

License

SQB is available under the BSD 3-Clause license.

About

Extensible, multi-dialect SQL query builder and Database connection framework for NodeJS

Topics

Resources

Code of conduct

Security policy

Stars

18 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages