Skip to content

MysqlClient.ts

MySQL adapter for Effect SQL, backed by the mysql2 driver.

This module provides constructors and layers for a MysqlClient and the generic Effect SQL client service. make creates a managed mysql2 pool, checks the connection with SELECT 1, maps mysql2 failures to SqlError, supports transaction connections, and exposes streaming queries through mysql2 query streams. It also provides direct and config-backed layers plus a MySQL statement compiler.

Since v4.0.0



Creates the MySQL statement compiler, using ? placeholders and backtick-escaped identifiers.

Signature

declare const makeCompiler: (transform?: (_: string) => string) => Statement.Compiler

Source

Since v4.0.0

Creates a scoped MySQL client backed by a managed mysql2 pool, verifying connectivity and supporting streaming queries through mysql2 query streams.

Signature

declare const make: (options: MysqlClientConfig) => Effect.Effect<MysqlClient, SqlError, Scope | Reactivity.Reactivity>

Source

Since v4.0.0

Creates a layer from a concrete MySQL client configuration, providing both MysqlClient and SqlClient.

Signature

declare const layer: (
config: MysqlClientConfig
) => Layer.Layer<MysqlClient | Client.SqlClient, Config.ConfigError | SqlError>

Source

Since v4.0.0

Creates a layer from a Config-wrapped MySQL client configuration, providing both MysqlClient and SqlClient.

Signature

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

Source

Since v4.0.0

mysql2-backed SQL client service, extending SqlClient with its runtime type marker and client configuration.

Signature

export interface MysqlClient extends Client.SqlClient {
readonly [TypeId]: TypeId
readonly config: MysqlClientConfig
}

Source

Since v4.0.0

Configuration for a mysql2 client, including connection URI or connection fields, pool options, span attributes, and query/result name transforms.

Signature

export interface MysqlClientConfig {
/**
* Connection URI. Setting this will override the other connection options
*/
readonly url?: Redacted.Redacted | undefined
readonly host?: string | undefined
readonly port?: number | undefined
readonly database?: string | undefined
readonly username?: string | undefined
readonly password?: Redacted.Redacted | undefined
readonly maxConnections?: number | undefined
readonly connectionTTL?: Duration.Input | undefined
readonly poolConfig?: Mysql.PoolOptions | undefined
readonly spanAttributes?: Record<string, unknown> | undefined
readonly transformResultNames?: ((str: string) => string) | undefined
readonly transformQueryNames?: ((str: string) => string) | undefined
}

Source

Since v4.0.0

Service tag for the mysql2 SQL client service.

When to use

Use to access or provide a mysql2 client through the Effect context.

Signature

declare const MysqlClient: Context.Service<MysqlClient, MysqlClient>

Source

Since v4.0.0

Runtime type identifier used to mark MysqlClient values.

Signature

declare const TypeId: "~@effect/sql-mysql2/MysqlClient"

Source

Since v4.0.0

Type-level identifier used to mark MysqlClient values.

Signature

type TypeId = "~@effect/sql-mysql2/MysqlClient"

Source

Since v4.0.0