MysqlClient.ts
MysqlClient.ts overview
Section titled “MysqlClient.ts overview”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
Exports Grouped by Category
Section titled “Exports Grouped by Category”compiler
Section titled “compiler”makeCompiler
Section titled “makeCompiler”Creates the MySQL statement compiler, using ? placeholders and backtick-escaped identifiers.
Signature
declare const makeCompiler: (transform?: (_: string) => string) => Statement.CompilerSince v4.0.0
constructors
Section titled “constructors”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>Since v4.0.0
layers
Section titled “layers”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>Since v4.0.0
layerConfig
Section titled “layerConfig”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>Since v4.0.0
models
Section titled “models”MysqlClient (interface)
Section titled “MysqlClient (interface)”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}Since v4.0.0
MysqlClientConfig (interface)
Section titled “MysqlClientConfig (interface)”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}Since v4.0.0
services
Section titled “services”MysqlClient
Section titled “MysqlClient”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>Since v4.0.0
type IDs
Section titled “type IDs”TypeId
Section titled “TypeId”Runtime type identifier used to mark MysqlClient values.
Signature
declare const TypeId: "~@effect/sql-mysql2/MysqlClient"Since v4.0.0
TypeId (type alias)
Section titled “TypeId (type alias)”Type-level identifier used to mark MysqlClient values.
Signature
type TypeId = "~@effect/sql-mysql2/MysqlClient"Since v4.0.0