Overview
@effect/sql-mssql provides a Microsoft SQL Server driver for Effect’s SQL toolkit. It uses the tedious library and supports connection pooling, transactions, stored procedures, and SQL Server-specific features.
Installation
Basic Usage
Creating a Client
Use theMssqlClient.layer function to create a SQL Server client layer:
Executing Queries
Configuration Options
Connection Options
| Option | Type | Description |
|---|---|---|
server | string | SQL Server hostname |
port | number | Database port (default: 1433) |
database | string | Database name |
username | string | Username for authentication |
password | Redacted | Password for authentication |
domain | string | Domain for Windows authentication |
authType | string | Authentication type (e.g., “ntlm”, “azure-active-directory-password”) |
instanceName | string | Named instance of SQL Server |
encrypt | boolean | Enable encryption (default: false) |
trustServer | boolean | Trust server certificate (default: true) |
connectTimeout | Duration.Input | Connection timeout (default: 5s) |
Connection Pool Options
| Option | Type | Description |
|---|---|---|
minConnections | number | Minimum number of connections (default: 1) |
maxConnections | number | Maximum number of connections (default: 10) |
connectionTTL | Duration.Input | Time-to-live for connections (default: 45 minutes) |
Transform Options
| Option | Type | Description |
|---|---|---|
transformResultNames | (str: string) => string | Transform column names in results |
transformQueryNames | (str: string) => string | Transform identifiers in queries |
Advanced Options
| Option | Type | Description |
|---|---|---|
parameterTypes | Record<Statement.PrimitiveKind, DataType> | Custom parameter type mapping |
spanAttributes | Record<string, unknown> | Custom telemetry attributes |
SQL Server-Specific Features
OUTPUT Clause
SQL Server uses OUTPUT instead of RETURNING:Custom Parameters
Use typed parameters for SQL Server-specific types:Stored Procedures
Call stored procedures with input and output parameters:Transactions
Automatic transaction management with savepoints:Parameter Type Mapping
Customize how JavaScript types map to SQL Server types:Name Transformations
Automatically convert between naming conventions:Error Handling
All SQL errors are wrapped inSqlError:
