Skip to main content

Choosing a database adapter

SQB ships one adapter package per supported database. An adapter bundles two things: a SerializerExtension (the "dialect" — teaches @sqb/builder that database's SQL syntax, e.g. LIMIT/OFFSET vs. FETCH/OFFSET, RETURNING support, identifier quoting) and an Adapter implementation (the actual connection/cursor logic on top of a driver). Installing the adapter package pulls in its matching -dialect package automatically via a side-effect import, and self-registers with SQB — there's nothing else to wire up.

DatabasePackageDriverDriver type
PostgreSQL@sqb/postgresPostgreJSPure JS
MySQL@sqb/mysqlmysql2Pure JS
MariaDB@sqb/mariadbmariadb (official)Pure JS
Microsoft SQL Server@sqb/mssqlmssql (tedious-based)Pure JS
Oracle Database@sqb/oracleoracledbThin mode by default (pure JS); optional Thick mode links a native Oracle Client
SQLite (native)@sqb/sqlitenode:sqlite / bun:sqliteNative (built into the Node.js/Bun runtime)
SQLite (WebAssembly)@sqb/sqljssql.jsWebAssembly

Guidance

  • Targeting a server database? Pick the adapter matching that database — PostgreSQL, MySQL, MariaDB, SQL Server, or Oracle. All of them speak the same SqbClient/Repository API, so switching between them later is mostly a matter of swapping the adapter package and connection options.
  • Embedded/local SQLite in a normal Node.js or Bun process? Use @sqb/sqlite — it needs no native build step because it relies on the runtime's own SQLite bindings (node:sqlite / bun:sqlite). This requires Node.js >= 22.5.
  • SQLite in a browser, or any environment without native SQLite bindings? Use @sqb/sqljs, which runs SQLite compiled to WebAssembly via sql.js. It shares its dialect with @sqb/sqlite (both generate standard SQLite SQL), so query code written against one works against the other.
  • Not sure yet, or writing a library that should support several databases? Start with just @sqb/builder and add a @sqb/connect + adapter pair when you're ready to run against a real database.

Migrator support

warning

@sqb/migrator currently only implements a migration adapter for PostgreSQL. Running it with any other connection.dialect throws a TypeError at runtime — the migration adapter for that dialect is "not implemented yet." If you need versioned migrations against MySQL, MariaDB, SQL Server, Oracle, or SQLite today, you'll need to manage them outside @sqb/migrator.

See Running migrations for what is supported.