Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

MssqlClient unstable

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 Since v4.0.0 Source

Constants

Since v4.0.0

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

unstable
Since v4.0.0

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>
Since v4.0.0

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

unstable
Since v4.0.0

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

unstable
Since v4.0.0

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 unstable
Since v4.0.0

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

unstable
Since v4.0.0

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 unstable
Since v4.0.0

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

unstable
Since v4.0.0

Runtime type identifier used to mark MssqlClient values.

Signature

declare const TypeId: unique symbol

TypeId

type unstable
Since v4.0.0

Type-level identifier used to mark MssqlClient values.

Signature

type TypeId = typeof TypeId