Skip to content

MssqlClient

Microsoft SQL Server client implementation for Effect SQL, backed by the tedious driver.

This module provides the MssqlClient service, constructors, layers, and SQL Server statement compiler. make creates a pooled Tedious client, checks the connection with SELECT 1, maps SQL Server failures to SqlError, and supports transactions with savepoints. The SQL Server-specific service adds typed Tedious parameters with param, stored procedure calls with call, direct or config-backed layers, and default parameter type mappings. Streaming queries are not implemented by this driver.

10 exports Added in v4.0.0 Source

Constants

Default mapping from Effect SQL primitive value kinds to Tedious SQL Server parameter data types.

Signature

declare const defaultParameterTypes: Record<Statement.PrimitiveKind, DataType>;

Constructors

make

Added in v4.0.0 Source

Creates a scoped Microsoft SQL Server client backed by a connection pool, with transaction and stored procedure support. Streaming queries are not implemented.

Signature

declare function make(
options: MssqlClientConfig,
): Effect<MssqlClient, SqlError, Scope | Reactivity>;

makeCompiler

Added in v4.0.0 Source

Creates the SQL Server statement compiler, using @1-style placeholders, bracket-escaped identifiers, and SQL Server OUTPUT INSERTED returning clauses.

Signature

declare function makeCompiler(transform?: (_: string) => string): Compiler;

Layers

layer

Added in v4.0.0 Source

Creates a layer from a concrete SQL Server client configuration, providing both MssqlClient and SqlClient.

Signature

declare function layer(config: MssqlClientConfig): Layer<MssqlClient | SqlClient, SqlError>;

layerConfig

Added in v4.0.0 Source

Creates a layer from a Config-wrapped SQL Server client configuration, providing both MssqlClient and SqlClient.

Signature

declare const layerConfig: (
config: Config.Wrap<MssqlClientConfig>,
) => Layer.Layer<Client.SqlClient | MssqlClient, Config.ConfigError | SqlError>;

Models

MssqlClientConfig interface

Added in v4.0.0 Source

Configuration for a Microsoft SQL Server client, including connection, authentication, pool, parameter type, span attribute, and query/result name transform options.

Signature

interface MssqlClientConfig {
readonly authType?: string;
readonly cancelTimeout?: Input;
readonly connectionRetryInterval?: Input;
readonly connectionTTL?: Input;
readonly connectTimeout?: Input;
readonly database?: string;
readonly domain?: string;
readonly encrypt?: boolean;
readonly instanceName?: string;
readonly maxConnections?: number;
readonly maxRetriesOnTransientErrors?: number;
readonly minConnections?: number;
readonly multiSubnetFailover?: boolean;
readonly parameterTypes?: Record<PrimitiveKind, DataType>;
readonly password?: Redacted<string>;
readonly port?: number;
readonly server: string;
readonly spanAttributes?: Record<string, unknown>;
readonly transformQueryNames?: (str: string) => string;
readonly transformResultNames?: (str: string) => string;
readonly trustServer?: boolean;
readonly username?: string;
}

Services

MssqlClient

Added in v4.0.0 Source

Service tag for the Microsoft SQL Server client service.

When to use

Use to access or provide a Microsoft SQL Server client through the Effect context.

Signature

declare const MssqlClient: Service<MssqlClient, MssqlClient>;

MssqlClient interface

Added in v4.0.0 Source

Microsoft SQL Server client service, extending SqlClient with typed parameter fragments and stored procedure calls.

Signature

interface MssqlClient extends SqlClient {
<A extends object = Row>(strings: TemplateStringsArray, ...args: Array<any>): Statement<A>;
(value: string): Identifier;
readonly [TypeId]: typeof TypeId;
readonly call: <
I extends Record<string, Parameter<any>>,
O extends Record<string, Parameter<any>>,
A extends object,
>(
procedure: ProcedureWithValues<I, O, A>,
) => Effect<Result<O, A>, SqlError>;
readonly config: MssqlClientConfig;
readonly param: (type: DataType, value: unknown, options?: any) => Fragment;
}

Type IDs

TypeId

Added in v4.0.0 Source

Runtime type identifier used to mark MssqlClient values.

Signature

declare const TypeId: unique symbol;

TypeId type

Added in v4.0.0 Source

Type-level identifier used to mark MssqlClient values.

Signature

type TypeId = typeof TypeId;