Microsoft SQL Server
@sqb/mssql is the SQB adapter for Microsoft SQL Server. It's built on top of
mssql, which itself wraps the pure-JavaScript
tedious driver — no native build step is required.
Install
npm install @sqb/mssql mssql
@sqb/connect and @sqb/builder are peer dependencies pulled in transitively if you already
depend on them directly; otherwise install them alongside.
Registering the adapter
Importing @sqb/mssql registers it as a side effect — there's nothing else to wire up:
import '@sqb/mssql';
import { SqbClient } from '@sqb/connect';
const client = new SqbClient({
dialect: 'mssql', // or driver: 'mssql'
host: 'localhost',
database: 'mydb',
user: 'myuser',
password: 'mypassword',
});
Under the hood, @sqb/mssql's entry point imports @sqb/mssql-dialect (which teaches
@sqb/builder T-SQL syntax) and registers a MssqlAdapter instance with AdapterRegistry.
MssqlAdapter reports driver: 'mssql' and dialect: 'mssql'.
Configuration
host (mapped to server), port, user, password, and database from
ClientConfiguration map onto the
mssql driver's own config object. driverOptions.encrypt and
driverOptions.trustServerCertificate set config.options.encrypt/.trustServerCertificate
(defaulting to false/true respectively when not given), and
driverOptions.options is merged into config.options on top of those two defaults:
new SqbClient({
dialect: 'mssql',
host: 'localhost',
database: 'mydb',
driverOptions: {
encrypt: true,
trustServerCertificate: false,
},
});
The rest of driverOptions is spread directly onto the top-level mssql config object, so it
can carry any option the driver supports (e.g. pool, connectionTimeout) that isn't already
covered by the standard fields. Because of the merge order, a top-level driverOptions.options
object replaces the encrypt/trustServerCertificate defaults wholesale rather than merging
with them — set encrypt/trustServerCertificate at the top level of driverOptions (as
above) rather than nested under driverOptions.options if you want them merged with the
defaults.
Feature notes
- Cursors: supported (
features.cursor: true), backed by the driver's request streaming — see Cursors & Streaming. - Schemas: not exposed through
features.schema—setSchema()/getSchema()aren't implemented by this adapter. RETURNING: SQB'sRETURNINGclause is translated to T-SQL'sOUTPUT INSERTED.col/OUTPUT DELETED.colsyntax, inserted before the statement'sVALUES/WHEREclause.- Named parameters: SQB's
:paramNameplaceholders are normalized to T-SQL's@paramNamesyntax, with awareness of[bracketed identifiers]so a:-like sequence inside one isn't mistaken for a parameter.
Migrator support
@sqb/migrator currently only implements its migration adapter for PostgreSQL — see
Running migrations. SQL Server migrations must be managed
outside @sqb/migrator today.
See also
- Choosing a Database Adapter
MssqlAdapterAPI reference- Creating a Client