@effect/sql-mysql2 4.0.0-beta.10 → 4.0.0-beta.101

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # `@effect/sql-mysql2`
2
2
 
3
- An `@effect/sql` implementation using the `mysql2` library.
3
+ An Effect SQL implementation using the `mysql2` library.
4
4
 
5
5
  ## Documentation
6
6
 
@@ -1,44 +1,67 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * MySQL adapter for Effect SQL, backed by the `mysql2` driver.
3
+ *
4
+ * This module provides constructors and layers for a {@link MysqlClient} and
5
+ * the generic Effect SQL client service. `make` creates a managed mysql2 pool,
6
+ * checks the connection with `SELECT 1`, maps mysql2 failures to `SqlError`,
7
+ * supports transaction connections, and exposes streaming queries through
8
+ * mysql2 query streams. It also provides direct and config-backed layers plus a
9
+ * MySQL statement compiler.
10
+ *
11
+ * @since 4.0.0
3
12
  */
4
13
  import * as Config from "effect/Config";
14
+ import * as Context from "effect/Context";
5
15
  import * as Duration from "effect/Duration";
6
16
  import * as Effect from "effect/Effect";
7
17
  import * as Layer from "effect/Layer";
8
18
  import * as Redacted from "effect/Redacted";
9
19
  import type { Scope } from "effect/Scope";
10
- import * as ServiceMap from "effect/ServiceMap";
11
20
  import * as Reactivity from "effect/unstable/reactivity/Reactivity";
12
21
  import * as Client from "effect/unstable/sql/SqlClient";
13
22
  import { SqlError } from "effect/unstable/sql/SqlError";
14
23
  import * as Statement from "effect/unstable/sql/Statement";
15
24
  import * as Mysql from "mysql2";
16
25
  /**
17
- * @category type ids
18
- * @since 1.0.0
26
+ * Runtime type identifier used to mark `MysqlClient` values.
27
+ *
28
+ * @category type IDs
29
+ * @since 4.0.0
19
30
  */
20
31
  export declare const TypeId: TypeId;
21
32
  /**
22
- * @category type ids
23
- * @since 1.0.0
33
+ * Type-level identifier used to mark `MysqlClient` values.
34
+ *
35
+ * @category type IDs
36
+ * @since 4.0.0
24
37
  */
25
38
  export type TypeId = "~@effect/sql-mysql2/MysqlClient";
26
39
  /**
40
+ * mysql2-backed SQL client service, extending `SqlClient` with its runtime type marker and client configuration.
41
+ *
27
42
  * @category models
28
- * @since 1.0.0
43
+ * @since 4.0.0
29
44
  */
30
45
  export interface MysqlClient extends Client.SqlClient {
31
46
  readonly [TypeId]: TypeId;
32
47
  readonly config: MysqlClientConfig;
33
48
  }
34
49
  /**
35
- * @category tags
36
- * @since 1.0.0
50
+ * Service tag for the mysql2 SQL client service.
51
+ *
52
+ * **When to use**
53
+ *
54
+ * Use to access or provide a mysql2 client through the Effect context.
55
+ *
56
+ * @category services
57
+ * @since 4.0.0
37
58
  */
38
- export declare const MysqlClient: ServiceMap.Service<MysqlClient, MysqlClient>;
59
+ export declare const MysqlClient: Context.Service<MysqlClient, MysqlClient>;
39
60
  /**
61
+ * Configuration for a mysql2 client, including connection URI or connection fields, pool options, span attributes, and query/result name transforms.
62
+ *
40
63
  * @category models
41
- * @since 1.0.0
64
+ * @since 4.0.0
42
65
  */
43
66
  export interface MysqlClientConfig {
44
67
  /**
@@ -53,28 +76,41 @@ export interface MysqlClientConfig {
53
76
  readonly maxConnections?: number | undefined;
54
77
  readonly connectionTTL?: Duration.Input | undefined;
55
78
  readonly poolConfig?: Mysql.PoolOptions | undefined;
79
+ /**
80
+ * Use the text protocol instead of prepared statements, for proxies like
81
+ * Cloudflare Hyperdrive that do not support `COM_STMT_PREPARE`.
82
+ */
83
+ readonly disablePreparedStatements?: boolean | undefined;
56
84
  readonly spanAttributes?: Record<string, unknown> | undefined;
57
85
  readonly transformResultNames?: ((str: string) => string) | undefined;
58
86
  readonly transformQueryNames?: ((str: string) => string) | undefined;
59
87
  }
60
88
  /**
89
+ * Creates a scoped MySQL client backed by a managed mysql2 pool, verifying connectivity and supporting streaming queries through mysql2 query streams.
90
+ *
61
91
  * @category constructors
62
- * @since 1.0.0
92
+ * @since 4.0.0
63
93
  */
64
94
  export declare const make: (options: MysqlClientConfig) => Effect.Effect<MysqlClient, SqlError, Scope | Reactivity.Reactivity>;
65
95
  /**
96
+ * Creates a layer from a `Config`-wrapped MySQL client configuration, providing both `MysqlClient` and `SqlClient`.
97
+ *
66
98
  * @category layers
67
- * @since 1.0.0
99
+ * @since 4.0.0
68
100
  */
69
101
  export declare const layerConfig: (config: Config.Wrap<MysqlClientConfig>) => Layer.Layer<MysqlClient | Client.SqlClient, Config.ConfigError | SqlError>;
70
102
  /**
103
+ * Creates a layer from a concrete MySQL client configuration, providing both `MysqlClient` and `SqlClient`.
104
+ *
71
105
  * @category layers
72
- * @since 1.0.0
106
+ * @since 4.0.0
73
107
  */
74
108
  export declare const layer: (config: MysqlClientConfig) => Layer.Layer<MysqlClient | Client.SqlClient, Config.ConfigError | SqlError>;
75
109
  /**
110
+ * Creates the MySQL statement compiler, using `?` placeholders and backtick-escaped identifiers.
111
+ *
76
112
  * @category compiler
77
- * @since 1.0.0
113
+ * @since 4.0.0
78
114
  */
79
115
  export declare const makeCompiler: (transform?: (_: string) => string) => Statement.Compiler;
80
116
  //# sourceMappingURL=MysqlClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MysqlClient.d.ts","sourceRoot":"","sources":["../src/MysqlClient.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAE/C,OAAO,KAAK,UAAU,MAAM,uCAAuC,CAAA;AACnE,OAAO,KAAK,MAAM,MAAM,+BAA+B,CAAA;AAEvD,OAAO,EAAE,QAAQ,EA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AAE,KAAK,CAAC,WAAW,GAAG,SAAS,CAAA;IAEnD;;;OAGG;IACH,QAAQ,CAAC,yBAAyB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAExD,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;IAE7D,QAAQ,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAA;IACrE,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAA;CACrE;AAED;;;;;GAKG;AACH,eAAO,MAAM,IAAI,YACN,iBAAiB,KACzB,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,EAAE,KAAK,GAAG,UAAU,CAAC,UAAU,CAsMjE,CAAA;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,WAAW,WACd,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,KACrC,KAAK,CAAC,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,GAAG,QAAQ,CAUnC,CAAA;AAEzC;;;;;GAKG;AACH,eAAO,MAAM,KAAK,WACR,iBAAiB,KACxB,KAAK,CAAC,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,GAAG,QAAQ,CAMnC,CAAA;AAEzC;;;;;GAKG;AACH,eAAO,MAAM,YAAY,eAAgB,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,uBAiB1D,CAAA"}
@@ -1,16 +1,25 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * MySQL adapter for Effect SQL, backed by the `mysql2` driver.
3
+ *
4
+ * This module provides constructors and layers for a {@link MysqlClient} and
5
+ * the generic Effect SQL client service. `make` creates a managed mysql2 pool,
6
+ * checks the connection with `SELECT 1`, maps mysql2 failures to `SqlError`,
7
+ * supports transaction connections, and exposes streaming queries through
8
+ * mysql2 query streams. It also provides direct and config-backed layers plus a
9
+ * MySQL statement compiler.
10
+ *
11
+ * @since 4.0.0
3
12
  */
4
13
  import * as Config from "effect/Config";
14
+ import * as Context from "effect/Context";
5
15
  import * as Duration from "effect/Duration";
6
16
  import * as Effect from "effect/Effect";
7
17
  import * as Layer from "effect/Layer";
8
18
  import * as Redacted from "effect/Redacted";
9
- import * as ServiceMap from "effect/ServiceMap";
10
19
  import * as Stream from "effect/Stream";
11
20
  import * as Reactivity from "effect/unstable/reactivity/Reactivity";
12
21
  import * as Client from "effect/unstable/sql/SqlClient";
13
- import { SqlError } from "effect/unstable/sql/SqlError";
22
+ import { AuthenticationError, AuthorizationError, ConnectionError, ConstraintError, DeadlockError, LockTimeoutError, SqlError, SqlSyntaxError, StatementTimeoutError, UniqueViolation, UnknownError } from "effect/unstable/sql/SqlError";
14
23
  import { asyncPauseResume } from "effect/unstable/sql/SqlStream";
15
24
  import * as Statement from "effect/unstable/sql/Statement";
16
25
  import * as Mysql from "mysql2";
@@ -18,31 +27,126 @@ const ATTR_DB_SYSTEM_NAME = "db.system.name";
18
27
  const ATTR_DB_NAMESPACE = "db.namespace";
19
28
  const ATTR_SERVER_ADDRESS = "server.address";
20
29
  const ATTR_SERVER_PORT = "server.port";
30
+ const mysqlErrnoFromCause = cause => {
31
+ if (typeof cause !== "object" || cause === null || !("errno" in cause)) {
32
+ return undefined;
33
+ }
34
+ const errno = cause.errno;
35
+ return typeof errno === "number" ? errno : undefined;
36
+ };
37
+ const mysqlConnectionErrorCodes = /*#__PURE__*/new Set([1040, 1042, 1043, 1129, 1130, 1203]);
38
+ const mysqlAuthorizationErrorCodes = /*#__PURE__*/new Set([1044, 1142, 1143, 1227]);
39
+ const mysqlSyntaxErrorCodes = /*#__PURE__*/new Set([1054, 1064, 1146]);
40
+ const mysqlConstraintErrorCodes = /*#__PURE__*/new Set([1022, 1048, 1169, 1216, 1217, 1451, 1452, 1557]);
41
+ const UNKNOWN_CONSTRAINT = "unknown";
42
+ const normalizeConstraintIdentifier = identifier => {
43
+ if (typeof identifier !== "string") {
44
+ return UNKNOWN_CONSTRAINT;
45
+ }
46
+ const trimmed = identifier.trim();
47
+ return trimmed.length === 0 ? UNKNOWN_CONSTRAINT : trimmed;
48
+ };
49
+ const mysqlCauseProperty = (cause, property) => {
50
+ if (typeof cause !== "object" || cause === null || !(property in cause)) {
51
+ return undefined;
52
+ }
53
+ return cause[property];
54
+ };
55
+ const mysqlDuplicateEntryConstraintFromMessage = message => {
56
+ if (typeof message !== "string") {
57
+ return UNKNOWN_CONSTRAINT;
58
+ }
59
+ const match = /\bfor key\s+(?:'([^']*)'|\x60([^\x60]*)\x60|([^\s'\x60]+))/i.exec(message);
60
+ return match === null ? UNKNOWN_CONSTRAINT : normalizeConstraintIdentifier(match[1] ?? match[2] ?? match[3]);
61
+ };
62
+ const mysqlDuplicateEntryConstraintFromCause = cause => {
63
+ const constraint = normalizeConstraintIdentifier(mysqlCauseProperty(cause, "constraint"));
64
+ if (constraint !== UNKNOWN_CONSTRAINT) {
65
+ return constraint;
66
+ }
67
+ const sqlMessageConstraint = mysqlDuplicateEntryConstraintFromMessage(mysqlCauseProperty(cause, "sqlMessage"));
68
+ if (sqlMessageConstraint !== UNKNOWN_CONSTRAINT) {
69
+ return sqlMessageConstraint;
70
+ }
71
+ return mysqlDuplicateEntryConstraintFromMessage(mysqlCauseProperty(cause, "message"));
72
+ };
73
+ const classifyError = (cause, message, operation) => {
74
+ const props = {
75
+ cause,
76
+ message,
77
+ operation
78
+ };
79
+ const errno = mysqlErrnoFromCause(cause);
80
+ if (errno !== undefined) {
81
+ if (mysqlConnectionErrorCodes.has(errno)) {
82
+ return new ConnectionError(props);
83
+ }
84
+ if (errno === 1045) {
85
+ return new AuthenticationError(props);
86
+ }
87
+ if (mysqlAuthorizationErrorCodes.has(errno)) {
88
+ return new AuthorizationError(props);
89
+ }
90
+ if (mysqlSyntaxErrorCodes.has(errno)) {
91
+ return new SqlSyntaxError(props);
92
+ }
93
+ if (errno === 1062) {
94
+ return new UniqueViolation({
95
+ ...props,
96
+ constraint: mysqlDuplicateEntryConstraintFromCause(cause)
97
+ });
98
+ }
99
+ if (mysqlConstraintErrorCodes.has(errno)) {
100
+ return new ConstraintError(props);
101
+ }
102
+ if (errno === 1213) {
103
+ return new DeadlockError(props);
104
+ }
105
+ if (errno === 1205) {
106
+ return new LockTimeoutError(props);
107
+ }
108
+ if (errno === 3024) {
109
+ return new StatementTimeoutError(props);
110
+ }
111
+ }
112
+ return new UnknownError(props);
113
+ };
21
114
  /**
22
- * @category type ids
23
- * @since 1.0.0
115
+ * Runtime type identifier used to mark `MysqlClient` values.
116
+ *
117
+ * @category type IDs
118
+ * @since 4.0.0
24
119
  */
25
120
  export const TypeId = "~@effect/sql-mysql2/MysqlClient";
26
121
  /**
27
- * @category tags
28
- * @since 1.0.0
122
+ * Service tag for the mysql2 SQL client service.
123
+ *
124
+ * **When to use**
125
+ *
126
+ * Use to access or provide a mysql2 client through the Effect context.
127
+ *
128
+ * @category services
129
+ * @since 4.0.0
29
130
  */
30
- export const MysqlClient = /*#__PURE__*/ServiceMap.Service("@effect/sql-mysql2/MysqlClient");
131
+ export const MysqlClient = /*#__PURE__*/Context.Service("@effect/sql-mysql2/MysqlClient");
31
132
  /**
133
+ * Creates a scoped MySQL client backed by a managed mysql2 pool, verifying connectivity and supporting streaming queries through mysql2 query streams.
134
+ *
32
135
  * @category constructors
33
- * @since 1.0.0
136
+ * @since 4.0.0
34
137
  */
35
138
  export const make = options => Effect.gen(function* () {
36
139
  const compiler = makeCompiler(options.transformQueryNames);
37
140
  const transformRows = options.transformResultNames ? Statement.defaultTransforms(options.transformResultNames).array : undefined;
141
+ const defaultMethod = options.disablePreparedStatements === true ? "query" : "execute";
38
142
  class ConnectionImpl {
39
143
  conn;
40
144
  constructor(conn) {
41
145
  this.conn = conn;
42
146
  }
43
- runRaw(sql, values, rowsAsArray = false, method = "execute") {
147
+ runRaw(sql, values, rowsAsArray = false, method = defaultMethod) {
44
148
  return Effect.callback(resume => {
45
- ;
149
+ const operation = method === "query" ? "executeUnprepared" : "execute";
46
150
  this.conn[method]({
47
151
  sql,
48
152
  values,
@@ -50,8 +154,7 @@ export const make = options => Effect.gen(function* () {
50
154
  }, (cause, results, _fields) => {
51
155
  if (cause) {
52
156
  resume(Effect.fail(new SqlError({
53
- cause,
54
- message: "Failed to execute statement"
157
+ reason: classifyError(cause, "Failed to execute statement", operation)
55
158
  })));
56
159
  } else {
57
160
  resume(Effect.succeed(results));
@@ -59,7 +162,7 @@ export const make = options => Effect.gen(function* () {
59
162
  });
60
163
  });
61
164
  }
62
- run(sql, values, rowsAsArray = false, method = "execute") {
165
+ run(sql, values, rowsAsArray = false, method = defaultMethod) {
63
166
  return this.runRaw(sql, values, rowsAsArray, method).pipe(Effect.map(results => Array.isArray(results) ? results : []));
64
167
  }
65
168
  execute(sql, params, transformRows) {
@@ -71,6 +174,9 @@ export const make = options => Effect.gen(function* () {
71
174
  executeValues(sql, params) {
72
175
  return this.run(sql, params, true);
73
176
  }
177
+ executeValuesUnprepared(sql, params) {
178
+ return this.run(sql, params, true, "query");
179
+ }
74
180
  executeUnprepared(sql, params, transformRows) {
75
181
  return transformRows ? Effect.map(this.run(sql, params, false, "query"), transformRows) : this.run(sql, params, false, "query");
76
182
  }
@@ -94,16 +200,15 @@ export const make = options => Effect.gen(function* () {
94
200
  password: options.password ? Redacted.value(options.password) : undefined,
95
201
  multipleStatements: true,
96
202
  supportBigNumbers: true,
97
- connectionLimit: options.maxConnections,
98
- idleTimeout: options.connectionTTL ? Duration.toMillis(Duration.fromInputUnsafe(options.connectionTTL)) : undefined
203
+ connectionLimit: options.maxConnections ?? options.poolConfig?.connectionLimit,
204
+ idleTimeout: options.connectionTTL ? Duration.toMillis(Duration.fromInputUnsafe(options.connectionTTL)) : options.poolConfig?.idleTimeout
99
205
  });
100
206
  yield* Effect.acquireRelease(Effect.callback(resume => {
101
207
  ;
102
208
  pool.query("SELECT 1", cause => {
103
209
  if (cause) {
104
210
  resume(Effect.fail(new SqlError({
105
- cause,
106
- message: "MysqlClient: Failed to connect"
211
+ reason: classifyError(cause, "MysqlClient: Failed to connect", "connect")
107
212
  })));
108
213
  } else {
109
214
  resume(Effect.void);
@@ -113,9 +218,12 @@ export const make = options => Effect.gen(function* () {
113
218
  pool.end(() => resume(Effect.void));
114
219
  })).pipe(Effect.timeoutOrElse({
115
220
  duration: Duration.seconds(5),
116
- onTimeout: () => Effect.fail(new SqlError({
117
- message: "MysqlClient: Connection timeout",
118
- cause: new Error("connection timeout")
221
+ orElse: () => Effect.fail(new SqlError({
222
+ reason: new ConnectionError({
223
+ message: "MysqlClient: Connection timeout",
224
+ cause: new Error("connection timeout"),
225
+ operation: "connect"
226
+ })
119
227
  }))
120
228
  }));
121
229
  const poolConnection = new ConnectionImpl(pool);
@@ -123,8 +231,7 @@ export const make = options => Effect.gen(function* () {
123
231
  pool.getConnection((cause, conn) => {
124
232
  if (cause) {
125
233
  resume(Effect.fail(new SqlError({
126
- cause,
127
- message: "Failed to acquire connection"
234
+ reason: classifyError(cause, "Failed to acquire connection", "acquireConnection")
128
235
  })));
129
236
  } else {
130
237
  resume(Effect.succeed(conn));
@@ -148,18 +255,24 @@ export const make = options => Effect.gen(function* () {
148
255
  });
149
256
  });
150
257
  /**
258
+ * Creates a layer from a `Config`-wrapped MySQL client configuration, providing both `MysqlClient` and `SqlClient`.
259
+ *
151
260
  * @category layers
152
- * @since 1.0.0
261
+ * @since 4.0.0
153
262
  */
154
- export const layerConfig = config => Layer.effectServices(Config.unwrap(config).asEffect().pipe(Effect.flatMap(make), Effect.map(client => ServiceMap.make(MysqlClient, client).pipe(ServiceMap.add(Client.SqlClient, client))))).pipe(Layer.provide(Reactivity.layer));
263
+ export const layerConfig = config => Layer.effectContext(Config.unwrap(config).pipe(Effect.flatMap(make), Effect.map(client => Context.make(MysqlClient, client).pipe(Context.add(Client.SqlClient, client))))).pipe(Layer.provide(Reactivity.layer));
155
264
  /**
265
+ * Creates a layer from a concrete MySQL client configuration, providing both `MysqlClient` and `SqlClient`.
266
+ *
156
267
  * @category layers
157
- * @since 1.0.0
268
+ * @since 4.0.0
158
269
  */
159
- export const layer = config => Layer.effectServices(Effect.map(make(config), client => ServiceMap.make(MysqlClient, client).pipe(ServiceMap.add(Client.SqlClient, client)))).pipe(Layer.provide(Reactivity.layer));
270
+ export const layer = config => Layer.effectContext(Effect.map(make(config), client => Context.make(MysqlClient, client).pipe(Context.add(Client.SqlClient, client)))).pipe(Layer.provide(Reactivity.layer));
160
271
  /**
272
+ * Creates the MySQL statement compiler, using `?` placeholders and backtick-escaped identifiers.
273
+ *
161
274
  * @category compiler
162
- * @since 1.0.0
275
+ * @since 4.0.0
163
276
  */
164
277
  export const makeCompiler = transform => Statement.makeCompiler({
165
278
  dialect: "mysql",
@@ -184,8 +297,7 @@ function queryStream(conn, sql, params) {
184
297
  let buffer = [];
185
298
  let taskPending = false;
186
299
  query.on("error", cause => emit.fail(new SqlError({
187
- cause,
188
- message: "Failed to stream statement"
300
+ reason: classifyError(cause, "Failed to stream statement", "stream")
189
301
  })));
190
302
  query.on("data", row => {
191
303
  buffer.push(row);
@@ -1 +1 @@
1
- {"version":3,"file":"MysqlClient.js","names":["Config","Duration","Effect","Layer","Redacted","ServiceMap","Stream","Reactivity","Client","SqlError","asyncPauseResume","Statement","Mysql","ATTR_DB_SYSTEM_NAME","ATTR_DB_NAMESPACE","ATTR_SERVER_ADDRESS","ATTR_SERVER_PORT","TypeId","MysqlClient","Service","make","options","gen","compiler","makeCompiler","transformQueryNames","transformRows","transformResultNames","defaultTransforms","array","undefined","ConnectionImpl","conn","constructor","runRaw","sql","values","rowsAsArray","method","callback","resume","cause","results","_fields","fail","message","succeed","run","pipe","map","Array","isArray","execute","params","executeRaw","executeValues","executeUnprepared","executeStream","stream","queryStream","mapArray","_","pool","url","createPool","uri","value","multipleStatements","supportBigNumbers","connectionLimit","maxConnections","idleTimeout","connectionTTL","toMillis","fromInputUnsafe","poolConfig","host","port","database","user","username","password","acquireRelease","query","void","end","timeoutOrElse","duration","seconds","onTimeout","Error","poolConnection","acquireConn","getConnection","sync","release","transactionAcquirer","spanAttributes","Object","entries","push","assign","acquirer","config","layerConfig","effectServices","unwrap","asEffect","flatMap","client","add","SqlClient","provide","layer","transform","dialect","placeholder","onIdentifier","withoutTransform","escape","onCustom","onRecordUpdate","defaultEscape","fnUntraced","emit","addFinalizer","destroy","buffer","taskPending","on","row","queueMicrotask","items","length","onPause","pause","onResume"],"sources":["../src/MysqlClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAE3C,OAAO,KAAKC,UAAU,MAAM,mBAAmB;AAC/C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,UAAU,MAAM,uCAAuC;AACnE,OAAO,KAAKC,MAAM,MAAM,+BAA+B;AAEvD,SAASC,QAAQ,QAAQ,8BAA8B;AACvD,SAASC,gBAAgB,QAAQ,+BAA+B;AAChE,OAAO,KAAKC,SAAS,MAAM,+BAA+B;AAC1D,OAAO,KAAKC,KAAK,MAAM,QAAQ;AAE/B,MAAMC,mBAAmB,GAAG,gBAAgB;AAC5C,MAAMC,iBAAiB,GAAG,cAAc;AACxC,MAAMC,mBAAmB,GAAG,gBAAgB;AAC5C,MAAMC,gBAAgB,GAAG,aAAa;AAEtC;;;;AAIA,OAAO,MAAMC,MAAM,GAAW,iCAAiC;AAiB/D;;;;AAIA,OAAO,MAAMC,WAAW,gBAAGb,UAAU,CAACc,OAAO,CAAc,gCAAgC,CAAC;AA6B5F;;;;AAIA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ream","Reactivity","Client","AuthenticationError","AuthorizationError","ConnectionError","ConstraintError","DeadlockError","LockTimeoutError","SqlError","SqlSyntaxError","StatementTimeoutError","UniqueViolation","UnknownError","asyncPauseResume","Statement","Mysql","ATTR_DB_SYSTEM_NAME","ATTR_DB_NAMESPACE","ATTR_SERVER_ADDRESS","ATTR_SERVER_PORT","mysqlErrnoFromCause","cause","undefined","errno","mysqlConnectionErrorCodes","Set","mysqlAuthorizationErrorCodes","mysqlSyntaxErrorCodes","mysqlConstraintErrorCodes","UNKNOWN_CONSTRAINT","normalizeConstraintIdentifier","identifier","trimmed","trim","length","mysqlCauseProperty","property","mysqlDuplicateEntryConstraintFromMessage","message","match","exec","mysqlDuplicateEntryConstraintFromCause","constraint","sqlMessageConstraint","classifyError","operation","props","has","TypeId","MysqlClient","Service","make","options","gen","compiler","makeCompiler","transformQueryNames","transformRows","transformResultNames","defaultTransforms","array","defaultMethod","disablePreparedStatements","ConnectionImpl","conn","constructor","runRaw","sql","values","rowsAsArray","method","callback","resume","results","_fields","fail","reason","succeed","run","pipe","map","Array","isArray","execute","params","executeRaw","executeValues","executeValuesUnprepared","executeUnprepared","executeStream","stream","queryStream","mapArray","_","pool","url","createPool","uri","value","multipleStatements","supportBigNumbers","connectionLimit","maxConnections","idleTimeout","connectionTTL","toMillis","fromInputUnsafe","poolConfig","host","port","database","user","username","password","acquireRelease","query","void","end","timeoutOrElse","duration","seconds","orElse","Error","poolConnection","acquireConn","getConnection","sync","release","transactionAcquirer","spanAttributes","Object","entries","push","assign","acquirer","config","layerConfig","effectContext","unwrap","flatMap","client","add","SqlClient","provide","layer","transform","dialect","placeholder","onIdentifier","withoutTransform","escape","onCustom","onRecordUpdate","defaultEscape","fnUntraced","emit","addFinalizer","destroy","buffer","taskPending","on","row","queueMicrotask","items","onPause","pause","onResume"],"sources":["../src/MysqlClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;AAYA,OAAO,KAAKA,MAAM,MAAM,eAAe;AACvC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AMhK,MAAM,CAACkI,IAAI,CAAC,MAAMX,KAAK,CAAC0C,OAAO,EAAU,CAAC,CAAC;IAE5E,IAAIC,MAAM,GAAe,EAAE;IAC3B,IAAIC,WAAW,GAAG,KAAK;IACvB5C,KAAK,CAAC6C,EAAE,CACN,OAAO,EACN3I,KAAc,IACbsI,IAAI,CAAChF,IAAI,CAAC,IAAInE,QAAQ,CAAC;MAAEoE,MAAM,EAAEhC,aAAa,CAACvB,KAAK,EAAE,4BAA4B,EAAE,QAAQ;IAAC,CAAE,CAAC,CAAC,CACpG;IACD8F,KAAK,CAAC6C,EAAE,CAAC,MAAM,EAAGC,GAAQ,IAAI;MAC5BH,MAAM,CAAC1B,IAAI,CAAC6B,GAAG,CAAC;MAChB,IAAI,CAACF,WAAW,EAAE;QAChBA,WAAW,GAAG,IAAI;QAClBG,cAAc,CAAC,MAAK;UAClB,MAAMC,KAAK,GAAGL,MAAM;UACpBA,MAAM,GAAG,EAAE;UACXH,IAAI,CAAC/F,KAAK,CAACuG,KAAK,CAAC;UACjBJ,WAAW,GAAG,KAAK;QACrB,CAAC,CAAC;MACJ;IACF,CAAC,CAAC;IACF5C,KAAK,CAAC6C,EAAE,CAAC,KAAK,EAAE,MAAK;MACnB,IAAIF,MAAM,CAAC5H,MAAM,GAAG,CAAC,EAAE;QACrByH,IAAI,CAAC/F,KAAK,CAACkG,MAAM,CAAC;QAClBA,MAAM,GAAG,EAAE;MACb;MACAH,IAAI,CAACtC,GAAG,EAAE;IACZ,CAAC,CAAC;IAEF,OAAO;MACL+C,OAAOA,CAAA;QACLjD,KAAK,CAACkD,KAAK,EAAE;MACf,CAAC;MACDC,QAAQA,CAAA;QACNnD,KAAK,CAAC3C,MAAM,EAAE;MAChB;KACD;EACH,CAAC,CAAC,CAAC;AACL","ignoreList":[]}
@@ -1,5 +1,13 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * MySQL adapter for the shared Effect SQL migration runner.
3
+ *
4
+ * This module re-exports the shared `Migrator` loaders and error types, then
5
+ * provides `run` and `layer` helpers that apply ordered migrations through the
6
+ * current mysql2-backed `SqlClient`. `run` returns the applied migration IDs
7
+ * and names, while `layer` runs migrations during layer construction and
8
+ * provides no services.
9
+ *
10
+ * @since 4.0.0
3
11
  */
4
12
  import type * as Effect from "effect/Effect";
5
13
  import * as Layer from "effect/Layer";
@@ -7,17 +15,21 @@ import * as Migrator from "effect/unstable/sql/Migrator";
7
15
  import type * as Client from "effect/unstable/sql/SqlClient";
8
16
  import type { SqlError } from "effect/unstable/sql/SqlError";
9
17
  /**
10
- * @since 1.0.0
18
+ * @since 4.0.0
11
19
  */
12
20
  export * from "effect/unstable/sql/Migrator";
13
21
  /**
14
- * @category constructor
15
- * @since 1.0.0
22
+ * Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
23
+ *
24
+ * @category constructors
25
+ * @since 4.0.0
16
26
  */
17
27
  export declare const run: <R2 = never>({ loader, schemaDirectory, table }: Migrator.MigratorOptions<R2>) => Effect.Effect<ReadonlyArray<readonly [id: number, name: string]>, Migrator.MigrationError | SqlError, Client.SqlClient | R2>;
18
28
  /**
29
+ * Creates a layer that runs the configured SQL migrations during layer construction.
30
+ *
19
31
  * @category layers
20
- * @since 1.0.0
32
+ * @since 4.0.0
21
33
  */
22
34
  export declare const layer: <R>(options: Migrator.MigratorOptions<R>) => Layer.Layer<never, Migrator.MigrationError | SqlError, Client.SqlClient | R>;
23
35
  //# sourceMappingURL=MysqlMigrator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MysqlMigrator.d.ts","sourceRoot":"","sources":["../src/MysqlMigrator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,8BAA8B,CAAA;AACxD,OAAO,KAAK,KAAK,MAAM,MAAM,+BAA+B,CAAA;AAC5D,OAAO,KAAK,EAA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AAM,CAChB,aAAa,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,EAClD,QAAQ,CAAC,cAAc,GAAG,QAAQ,EAClC,MAAM,CAAC,SAAS,GAAG,EAAE,CAsDrB,CAAA;AAEF;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,WACZ,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,KACnC,KAAK,CAAC,KAAK,CACZ,KAAK,EACL,QAAQ,CAAC,cAAc,GAAG,QAAQ,EAClC,MAAM,CAAC,SAAS,GAAG,CAAC,CACgB,CAAA"}
@@ -1,12 +1,14 @@
1
1
  import * as Layer from "effect/Layer";
2
2
  import * as Migrator from "effect/unstable/sql/Migrator";
3
3
  /**
4
- * @since 1.0.0
4
+ * @since 4.0.0
5
5
  */
6
6
  export * from "effect/unstable/sql/Migrator";
7
7
  /**
8
- * @category constructor
9
- * @since 1.0.0
8
+ * Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
9
+ *
10
+ * @category constructors
11
+ * @since 4.0.0
10
12
  */
11
13
  export const run = /*#__PURE__*/Migrator.make({
12
14
  // TODO: re-add when Command module is available
@@ -63,8 +65,10 @@ export const run = /*#__PURE__*/Migrator.make({
63
65
  // }
64
66
  });
65
67
  /**
68
+ * Creates a layer that runs the configured SQL migrations during layer construction.
69
+ *
66
70
  * @category layers
67
- * @since 1.0.0
71
+ * @since 4.0.0
68
72
  */
69
73
  export const layer = options => Layer.effectDiscard(run(options));
70
74
  //# sourceMappingURL=MysqlMigrator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MysqlMigrator.js","names":["Layer","Migrator","run","make","layer","options","effectDiscard"],"sources":["../src/MysqlMigrator.ts"],"sourcesContent":[null],"mappings":"AAIA,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,QAAQ,MAAM,8BAA8B;AAIxD;;;AAGA,cAAc,8BAA8B;AAE5C;;;;AAIA,OAAO,MAAMC,GAAG,gBAMZD,QAAQ,CAACE,IAAI,CAAC;EAChB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;AAAA,CACD,CAAC;AAEF;;;;AAIA,OAAO,MAAMC,KAAK,GAChBC,OAAoC,IAKjCL,KAAK,CAACM,aAAa,CAACJ,GAAG,CAACG,OAAO,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"MysqlMigrator.js","names":["Layer","Migrator","run","make","layer","options","effectDiscard"],"sources":["../src/MysqlMigrator.ts"],"sourcesContent":[null],"mappings":"AAYA,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,QAAQ,MAAM,8BAA8B;AAIxD;;;AAGA,cAAc,8BAA8B;AAE5C;;;;;;AAMA,OAAO,MAAMC,GAAG,gBAMZD,QAAQ,CAACE,IAAI,CAAC;EAChB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;AAAA,CACD,CAAC;AAEF;;;;;;AAMA,OAAO,MAAMC,KAAK,GAChBC,OAAoC,IAKjCL,KAAK,CAACM,aAAa,CAACJ,GAAG,CAACG,OAAO,CAAC,CAAC","ignoreList":[]}
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
  /**
5
- * @since 1.0.0
5
+ * @since 4.0.0
6
6
  */
7
7
  export * as MysqlClient from "./MysqlClient.ts";
8
8
  /**
9
- * @since 1.0.0
9
+ * @since 4.0.0
10
10
  */
11
11
  export * as MysqlMigrator from "./MysqlMigrator.ts";
12
12
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
  // @barrel: Auto-generated exports. Do not edit manually.
5
5
  /**
6
- * @since 1.0.0
6
+ * @since 4.0.0
7
7
  */
8
8
  export * as MysqlClient from "./MysqlClient.js";
9
9
  /**
10
- * @since 1.0.0
10
+ * @since 4.0.0
11
11
  */
12
12
  export * as MysqlMigrator from "./MysqlMigrator.js";
13
13
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@effect/sql-mysql2",
3
- "version": "4.0.0-beta.10",
3
+ "version": "4.0.0-beta.101",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "A MySQL toolkit for Effect",
7
7
  "homepage": "https://effect.website",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "https://github.com/Effect-TS/effect-smol.git",
10
+ "url": "https://github.com/Effect-TS/effect.git",
11
11
  "directory": "packages/sql/mysql2"
12
12
  },
13
13
  "bugs": {
14
- "url": "https://github.com/Effect-TS/effect-smol/issues"
14
+ "url": "https://github.com/Effect-TS/effect/issues"
15
15
  },
16
16
  "tags": [
17
17
  "typescript",
@@ -43,19 +43,18 @@
43
43
  "provenance": true
44
44
  },
45
45
  "devDependencies": {
46
- "@testcontainers/mysql": "^11.11.0",
47
- "effect": "^4.0.0-beta.10"
46
+ "@testcontainers/mysql": "^11.14.0",
47
+ "effect": "^4.0.0-beta.101"
48
48
  },
49
49
  "peerDependencies": {
50
- "effect": "^4.0.0-beta.10"
50
+ "effect": "^4.0.0-beta.101"
51
51
  },
52
52
  "dependencies": {
53
- "mysql2": "^3.16.2"
53
+ "mysql2": "^3.22.6"
54
54
  },
55
55
  "scripts": {
56
56
  "codegen": "effect-utils codegen",
57
57
  "build": "tsc -b tsconfig.json && pnpm babel",
58
- "build:tsgo": "tsgo -b tsconfig.json && pnpm babel",
59
58
  "babel": "babel dist --plugins annotate-pure-calls --out-dir dist --source-maps",
60
59
  "check": "tsc -b tsconfig.json",
61
60
  "test": "vitest",
@@ -1,18 +1,39 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * MySQL adapter for Effect SQL, backed by the `mysql2` driver.
3
+ *
4
+ * This module provides constructors and layers for a {@link MysqlClient} and
5
+ * the generic Effect SQL client service. `make` creates a managed mysql2 pool,
6
+ * checks the connection with `SELECT 1`, maps mysql2 failures to `SqlError`,
7
+ * supports transaction connections, and exposes streaming queries through
8
+ * mysql2 query streams. It also provides direct and config-backed layers plus a
9
+ * MySQL statement compiler.
10
+ *
11
+ * @since 4.0.0
3
12
  */
4
13
  import * as Config from "effect/Config"
14
+ import * as Context from "effect/Context"
5
15
  import * as Duration from "effect/Duration"
6
16
  import * as Effect from "effect/Effect"
7
17
  import * as Layer from "effect/Layer"
8
18
  import * as Redacted from "effect/Redacted"
9
19
  import type { Scope } from "effect/Scope"
10
- import * as ServiceMap from "effect/ServiceMap"
11
20
  import * as Stream from "effect/Stream"
12
21
  import * as Reactivity from "effect/unstable/reactivity/Reactivity"
13
22
  import * as Client from "effect/unstable/sql/SqlClient"
14
23
  import type { Connection } from "effect/unstable/sql/SqlConnection"
15
- import { SqlError } from "effect/unstable/sql/SqlError"
24
+ import {
25
+ AuthenticationError,
26
+ AuthorizationError,
27
+ ConnectionError,
28
+ ConstraintError,
29
+ DeadlockError,
30
+ LockTimeoutError,
31
+ SqlError,
32
+ SqlSyntaxError,
33
+ StatementTimeoutError,
34
+ UniqueViolation,
35
+ UnknownError
36
+ } from "effect/unstable/sql/SqlError"
16
37
  import { asyncPauseResume } from "effect/unstable/sql/SqlStream"
17
38
  import * as Statement from "effect/unstable/sql/Statement"
18
39
  import * as Mysql from "mysql2"
@@ -22,21 +43,118 @@ const ATTR_DB_NAMESPACE = "db.namespace"
22
43
  const ATTR_SERVER_ADDRESS = "server.address"
23
44
  const ATTR_SERVER_PORT = "server.port"
24
45
 
46
+ const mysqlErrnoFromCause = (cause: unknown): number | undefined => {
47
+ if (typeof cause !== "object" || cause === null || !("errno" in cause)) {
48
+ return undefined
49
+ }
50
+ const errno = cause.errno
51
+ return typeof errno === "number" ? errno : undefined
52
+ }
53
+
54
+ const mysqlConnectionErrorCodes = new Set([1040, 1042, 1043, 1129, 1130, 1203])
55
+ const mysqlAuthorizationErrorCodes = new Set([1044, 1142, 1143, 1227])
56
+ const mysqlSyntaxErrorCodes = new Set([1054, 1064, 1146])
57
+ const mysqlConstraintErrorCodes = new Set([1022, 1048, 1169, 1216, 1217, 1451, 1452, 1557])
58
+
59
+ const UNKNOWN_CONSTRAINT = "unknown"
60
+
61
+ const normalizeConstraintIdentifier = (identifier: unknown): string => {
62
+ if (typeof identifier !== "string") {
63
+ return UNKNOWN_CONSTRAINT
64
+ }
65
+ const trimmed = identifier.trim()
66
+ return trimmed.length === 0 ? UNKNOWN_CONSTRAINT : trimmed
67
+ }
68
+
69
+ const mysqlCauseProperty = (cause: unknown, property: "constraint" | "message" | "sqlMessage"): unknown => {
70
+ if (typeof cause !== "object" || cause === null || !(property in cause)) {
71
+ return undefined
72
+ }
73
+ return (cause as Record<string, unknown>)[property]
74
+ }
75
+
76
+ const mysqlDuplicateEntryConstraintFromMessage = (message: unknown): string => {
77
+ if (typeof message !== "string") {
78
+ return UNKNOWN_CONSTRAINT
79
+ }
80
+ const match = /\bfor key\s+(?:'([^']*)'|\x60([^\x60]*)\x60|([^\s'\x60]+))/i.exec(message)
81
+ return match === null ?
82
+ UNKNOWN_CONSTRAINT :
83
+ normalizeConstraintIdentifier(match[1] ?? match[2] ?? match[3])
84
+ }
85
+
86
+ const mysqlDuplicateEntryConstraintFromCause = (cause: unknown): string => {
87
+ const constraint = normalizeConstraintIdentifier(mysqlCauseProperty(cause, "constraint"))
88
+ if (constraint !== UNKNOWN_CONSTRAINT) {
89
+ return constraint
90
+ }
91
+ const sqlMessageConstraint = mysqlDuplicateEntryConstraintFromMessage(mysqlCauseProperty(cause, "sqlMessage"))
92
+ if (sqlMessageConstraint !== UNKNOWN_CONSTRAINT) {
93
+ return sqlMessageConstraint
94
+ }
95
+ return mysqlDuplicateEntryConstraintFromMessage(mysqlCauseProperty(cause, "message"))
96
+ }
97
+
98
+ const classifyError = (
99
+ cause: unknown,
100
+ message: string,
101
+ operation: string
102
+ ) => {
103
+ const props = { cause, message, operation }
104
+ const errno = mysqlErrnoFromCause(cause)
105
+ if (errno !== undefined) {
106
+ if (mysqlConnectionErrorCodes.has(errno)) {
107
+ return new ConnectionError(props)
108
+ }
109
+ if (errno === 1045) {
110
+ return new AuthenticationError(props)
111
+ }
112
+ if (mysqlAuthorizationErrorCodes.has(errno)) {
113
+ return new AuthorizationError(props)
114
+ }
115
+ if (mysqlSyntaxErrorCodes.has(errno)) {
116
+ return new SqlSyntaxError(props)
117
+ }
118
+ if (errno === 1062) {
119
+ return new UniqueViolation({ ...props, constraint: mysqlDuplicateEntryConstraintFromCause(cause) })
120
+ }
121
+ if (mysqlConstraintErrorCodes.has(errno)) {
122
+ return new ConstraintError(props)
123
+ }
124
+ if (errno === 1213) {
125
+ return new DeadlockError(props)
126
+ }
127
+ if (errno === 1205) {
128
+ return new LockTimeoutError(props)
129
+ }
130
+ if (errno === 3024) {
131
+ return new StatementTimeoutError(props)
132
+ }
133
+ }
134
+ return new UnknownError(props)
135
+ }
136
+
25
137
  /**
26
- * @category type ids
27
- * @since 1.0.0
138
+ * Runtime type identifier used to mark `MysqlClient` values.
139
+ *
140
+ * @category type IDs
141
+ * @since 4.0.0
28
142
  */
29
143
  export const TypeId: TypeId = "~@effect/sql-mysql2/MysqlClient"
30
144
 
31
145
  /**
32
- * @category type ids
33
- * @since 1.0.0
146
+ * Type-level identifier used to mark `MysqlClient` values.
147
+ *
148
+ * @category type IDs
149
+ * @since 4.0.0
34
150
  */
35
151
  export type TypeId = "~@effect/sql-mysql2/MysqlClient"
36
152
 
37
153
  /**
154
+ * mysql2-backed SQL client service, extending `SqlClient` with its runtime type marker and client configuration.
155
+ *
38
156
  * @category models
39
- * @since 1.0.0
157
+ * @since 4.0.0
40
158
  */
41
159
  export interface MysqlClient extends Client.SqlClient {
42
160
  readonly [TypeId]: TypeId
@@ -44,14 +162,22 @@ export interface MysqlClient extends Client.SqlClient {
44
162
  }
45
163
 
46
164
  /**
47
- * @category tags
48
- * @since 1.0.0
165
+ * Service tag for the mysql2 SQL client service.
166
+ *
167
+ * **When to use**
168
+ *
169
+ * Use to access or provide a mysql2 client through the Effect context.
170
+ *
171
+ * @category services
172
+ * @since 4.0.0
49
173
  */
50
- export const MysqlClient = ServiceMap.Service<MysqlClient>("@effect/sql-mysql2/MysqlClient")
174
+ export const MysqlClient = Context.Service<MysqlClient>("@effect/sql-mysql2/MysqlClient")
51
175
 
52
176
  /**
177
+ * Configuration for a mysql2 client, including connection URI or connection fields, pool options, span attributes, and query/result name transforms.
178
+ *
53
179
  * @category models
54
- * @since 1.0.0
180
+ * @since 4.0.0
55
181
  */
56
182
  export interface MysqlClientConfig {
57
183
  /**
@@ -70,6 +196,12 @@ export interface MysqlClientConfig {
70
196
 
71
197
  readonly poolConfig?: Mysql.PoolOptions | undefined
72
198
 
199
+ /**
200
+ * Use the text protocol instead of prepared statements, for proxies like
201
+ * Cloudflare Hyperdrive that do not support `COM_STMT_PREPARE`.
202
+ */
203
+ readonly disablePreparedStatements?: boolean | undefined
204
+
73
205
  readonly spanAttributes?: Record<string, unknown> | undefined
74
206
 
75
207
  readonly transformResultNames?: ((str: string) => string) | undefined
@@ -77,8 +209,10 @@ export interface MysqlClientConfig {
77
209
  }
78
210
 
79
211
  /**
212
+ * Creates a scoped MySQL client backed by a managed mysql2 pool, verifying connectivity and supporting streaming queries through mysql2 query streams.
213
+ *
80
214
  * @category constructors
81
- * @since 1.0.0
215
+ * @since 4.0.0
82
216
  */
83
217
  export const make = (
84
218
  options: MysqlClientConfig
@@ -90,6 +224,7 @@ export const make = (
90
224
  options.transformResultNames
91
225
  ).array :
92
226
  undefined
227
+ const defaultMethod: "execute" | "query" = options.disablePreparedStatements === true ? "query" : "execute"
93
228
 
94
229
  class ConnectionImpl implements Connection {
95
230
  readonly conn: Mysql.PoolConnection | Mysql.Pool
@@ -101,16 +236,19 @@ export const make = (
101
236
  sql: string,
102
237
  values?: ReadonlyArray<any>,
103
238
  rowsAsArray = false,
104
- method: "execute" | "query" = "execute"
239
+ method: "execute" | "query" = defaultMethod
105
240
  ) {
106
241
  return Effect.callback<unknown, SqlError>((resume) => {
242
+ const operation = method === "query" ? "executeUnprepared" : "execute"
107
243
  ;(this.conn as any)[method]({
108
244
  sql,
109
245
  values,
110
246
  rowsAsArray
111
247
  }, (cause: unknown | null, results: unknown, _fields: any) => {
112
248
  if (cause) {
113
- resume(Effect.fail(new SqlError({ cause, message: "Failed to execute statement" })))
249
+ resume(
250
+ Effect.fail(new SqlError({ reason: classifyError(cause, "Failed to execute statement", operation) }))
251
+ )
114
252
  } else {
115
253
  resume(Effect.succeed(results))
116
254
  }
@@ -122,7 +260,7 @@ export const make = (
122
260
  sql: string,
123
261
  values?: ReadonlyArray<any>,
124
262
  rowsAsArray = false,
125
- method: "execute" | "query" = "execute"
263
+ method: "execute" | "query" = defaultMethod
126
264
  ) {
127
265
  return this.runRaw(sql, values, rowsAsArray, method).pipe(
128
266
  Effect.map((results) => Array.isArray(results) ? results : [])
@@ -144,6 +282,9 @@ export const make = (
144
282
  executeValues(sql: string, params: ReadonlyArray<unknown>) {
145
283
  return this.run(sql, params, true)
146
284
  }
285
+ executeValuesUnprepared(sql: string, params: ReadonlyArray<unknown>) {
286
+ return this.run(sql, params, true, "query")
287
+ }
147
288
  executeUnprepared(
148
289
  sql: string,
149
290
  params: ReadonlyArray<unknown>,
@@ -186,10 +327,10 @@ export const make = (
186
327
  : undefined,
187
328
  multipleStatements: true,
188
329
  supportBigNumbers: true,
189
- connectionLimit: options.maxConnections,
330
+ connectionLimit: options.maxConnections ?? options.poolConfig?.connectionLimit,
190
331
  idleTimeout: options.connectionTTL
191
332
  ? Duration.toMillis(Duration.fromInputUnsafe(options.connectionTTL))
192
- : undefined
333
+ : options.poolConfig?.idleTimeout
193
334
  } as Mysql.PoolOptions)
194
335
 
195
336
  yield* Effect.acquireRelease(
@@ -198,8 +339,7 @@ export const make = (
198
339
  if (cause) {
199
340
  resume(Effect.fail(
200
341
  new SqlError({
201
- cause,
202
- message: "MysqlClient: Failed to connect"
342
+ reason: classifyError(cause, "MysqlClient: Failed to connect", "connect")
203
343
  })
204
344
  ))
205
345
  } else {
@@ -214,11 +354,14 @@ export const make = (
214
354
  ).pipe(
215
355
  Effect.timeoutOrElse({
216
356
  duration: Duration.seconds(5),
217
- onTimeout: () =>
357
+ orElse: () =>
218
358
  Effect.fail(
219
359
  new SqlError({
220
- message: "MysqlClient: Connection timeout",
221
- cause: new Error("connection timeout")
360
+ reason: new ConnectionError({
361
+ message: "MysqlClient: Connection timeout",
362
+ cause: new Error("connection timeout"),
363
+ operation: "connect"
364
+ })
222
365
  })
223
366
  )
224
367
  })
@@ -230,7 +373,13 @@ export const make = (
230
373
  Effect.callback<Mysql.PoolConnection, SqlError>((resume) => {
231
374
  pool.getConnection((cause, conn) => {
232
375
  if (cause) {
233
- resume(Effect.fail(new SqlError({ cause, message: "Failed to acquire connection" })))
376
+ resume(
377
+ Effect.fail(
378
+ new SqlError({
379
+ reason: classifyError(cause, "Failed to acquire connection", "acquireConnection")
380
+ })
381
+ )
382
+ )
234
383
  } else {
235
384
  resume(Effect.succeed(conn))
236
385
  }
@@ -268,40 +417,46 @@ export const make = (
268
417
  })
269
418
 
270
419
  /**
420
+ * Creates a layer from a `Config`-wrapped MySQL client configuration, providing both `MysqlClient` and `SqlClient`.
421
+ *
271
422
  * @category layers
272
- * @since 1.0.0
423
+ * @since 4.0.0
273
424
  */
274
425
  export const layerConfig = (
275
426
  config: Config.Wrap<MysqlClientConfig>
276
427
  ): Layer.Layer<MysqlClient | Client.SqlClient, Config.ConfigError | SqlError> =>
277
- Layer.effectServices(
278
- Config.unwrap(config).asEffect().pipe(
428
+ Layer.effectContext(
429
+ Config.unwrap(config).pipe(
279
430
  Effect.flatMap(make),
280
431
  Effect.map((client) =>
281
- ServiceMap.make(MysqlClient, client).pipe(
282
- ServiceMap.add(Client.SqlClient, client)
432
+ Context.make(MysqlClient, client).pipe(
433
+ Context.add(Client.SqlClient, client)
283
434
  )
284
435
  )
285
436
  )
286
437
  ).pipe(Layer.provide(Reactivity.layer))
287
438
 
288
439
  /**
440
+ * Creates a layer from a concrete MySQL client configuration, providing both `MysqlClient` and `SqlClient`.
441
+ *
289
442
  * @category layers
290
- * @since 1.0.0
443
+ * @since 4.0.0
291
444
  */
292
445
  export const layer = (
293
446
  config: MysqlClientConfig
294
447
  ): Layer.Layer<MysqlClient | Client.SqlClient, Config.ConfigError | SqlError> =>
295
- Layer.effectServices(
448
+ Layer.effectContext(
296
449
  Effect.map(make(config), (client) =>
297
- ServiceMap.make(MysqlClient, client).pipe(
298
- ServiceMap.add(Client.SqlClient, client)
450
+ Context.make(MysqlClient, client).pipe(
451
+ Context.add(Client.SqlClient, client)
299
452
  ))
300
453
  ).pipe(Layer.provide(Reactivity.layer))
301
454
 
302
455
  /**
456
+ * Creates the MySQL statement compiler, using `?` placeholders and backtick-escaped identifiers.
457
+ *
303
458
  * @category compiler
304
- * @since 1.0.0
459
+ * @since 4.0.0
305
460
  */
306
461
  export const makeCompiler = (transform?: (_: string) => string) =>
307
462
  Statement.makeCompiler({
@@ -331,11 +486,15 @@ function queryStream(
331
486
  ) {
332
487
  return asyncPauseResume<any, SqlError>(Effect.fnUntraced(function*(emit) {
333
488
  const query = (conn as any).query(sql, params).stream()
334
- yield* Effect.addFinalizer(() => Effect.sync(() => query.destroy()))
489
+ yield* Effect.addFinalizer(() => Effect.sync(() => query.destroy() as void))
335
490
 
336
491
  let buffer: Array<any> = []
337
492
  let taskPending = false
338
- query.on("error", (cause: unknown) => emit.fail(new SqlError({ cause, message: "Failed to stream statement" })))
493
+ query.on(
494
+ "error",
495
+ (cause: unknown) =>
496
+ emit.fail(new SqlError({ reason: classifyError(cause, "Failed to stream statement", "stream") }))
497
+ )
339
498
  query.on("data", (row: any) => {
340
499
  buffer.push(row)
341
500
  if (!taskPending) {
@@ -1,5 +1,13 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * MySQL adapter for the shared Effect SQL migration runner.
3
+ *
4
+ * This module re-exports the shared `Migrator` loaders and error types, then
5
+ * provides `run` and `layer` helpers that apply ordered migrations through the
6
+ * current mysql2-backed `SqlClient`. `run` returns the applied migration IDs
7
+ * and names, while `layer` runs migrations during layer construction and
8
+ * provides no services.
9
+ *
10
+ * @since 4.0.0
3
11
  */
4
12
  import type * as Effect from "effect/Effect"
5
13
  import * as Layer from "effect/Layer"
@@ -8,13 +16,15 @@ import type * as Client from "effect/unstable/sql/SqlClient"
8
16
  import type { SqlError } from "effect/unstable/sql/SqlError"
9
17
 
10
18
  /**
11
- * @since 1.0.0
19
+ * @since 4.0.0
12
20
  */
13
21
  export * from "effect/unstable/sql/Migrator"
14
22
 
15
23
  /**
16
- * @category constructor
17
- * @since 1.0.0
24
+ * Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
25
+ *
26
+ * @category constructors
27
+ * @since 4.0.0
18
28
  */
19
29
  export const run: <R2 = never>(
20
30
  { loader, schemaDirectory, table }: Migrator.MigratorOptions<R2>
@@ -78,8 +88,10 @@ export const run: <R2 = never>(
78
88
  })
79
89
 
80
90
  /**
91
+ * Creates a layer that runs the configured SQL migrations during layer construction.
92
+ *
81
93
  * @category layers
82
- * @since 1.0.0
94
+ * @since 4.0.0
83
95
  */
84
96
  export const layer = <R>(
85
97
  options: Migrator.MigratorOptions<R>
package/src/index.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
 
5
5
  // @barrel: Auto-generated exports. Do not edit manually.
6
6
 
7
7
  /**
8
- * @since 1.0.0
8
+ * @since 4.0.0
9
9
  */
10
10
  export * as MysqlClient from "./MysqlClient.ts"
11
11
 
12
12
  /**
13
- * @since 1.0.0
13
+ * @since 4.0.0
14
14
  */
15
15
  export * as MysqlMigrator from "./MysqlMigrator.ts"