@effect/sql-mysql2 4.0.0-beta.8 → 4.0.0-beta.81
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/dist/MysqlClient.d.ts +46 -15
- package/dist/MysqlClient.d.ts.map +1 -1
- package/dist/MysqlClient.js +134 -26
- package/dist/MysqlClient.js.map +1 -1
- package/dist/MysqlMigrator.d.ts +17 -5
- package/dist/MysqlMigrator.d.ts.map +1 -1
- package/dist/MysqlMigrator.js +8 -4
- package/dist/MysqlMigrator.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/package.json +5 -5
- package/src/MysqlClient.ts +181 -32
- package/src/MysqlMigrator.ts +17 -5
- package/src/index.ts +3 -3
package/dist/MysqlClient.d.ts
CHANGED
|
@@ -1,44 +1,67 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
-
*
|
|
18
|
-
*
|
|
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
|
-
*
|
|
23
|
-
*
|
|
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
|
|
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
|
-
*
|
|
36
|
-
*
|
|
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:
|
|
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
|
|
64
|
+
* @since 4.0.0
|
|
42
65
|
*/
|
|
43
66
|
export interface MysqlClientConfig {
|
|
44
67
|
/**
|
|
@@ -58,23 +81,31 @@ export interface MysqlClientConfig {
|
|
|
58
81
|
readonly transformQueryNames?: ((str: string) => string) | undefined;
|
|
59
82
|
}
|
|
60
83
|
/**
|
|
84
|
+
* Creates a scoped MySQL client backed by a managed mysql2 pool, verifying connectivity and supporting streaming queries through mysql2 query streams.
|
|
85
|
+
*
|
|
61
86
|
* @category constructors
|
|
62
|
-
* @since
|
|
87
|
+
* @since 4.0.0
|
|
63
88
|
*/
|
|
64
89
|
export declare const make: (options: MysqlClientConfig) => Effect.Effect<MysqlClient, SqlError, Scope | Reactivity.Reactivity>;
|
|
65
90
|
/**
|
|
91
|
+
* Creates a layer from a `Config`-wrapped MySQL client configuration, providing both `MysqlClient` and `SqlClient`.
|
|
92
|
+
*
|
|
66
93
|
* @category layers
|
|
67
|
-
* @since
|
|
94
|
+
* @since 4.0.0
|
|
68
95
|
*/
|
|
69
96
|
export declare const layerConfig: (config: Config.Wrap<MysqlClientConfig>) => Layer.Layer<MysqlClient | Client.SqlClient, Config.ConfigError | SqlError>;
|
|
70
97
|
/**
|
|
98
|
+
* Creates a layer from a concrete MySQL client configuration, providing both `MysqlClient` and `SqlClient`.
|
|
99
|
+
*
|
|
71
100
|
* @category layers
|
|
72
|
-
* @since
|
|
101
|
+
* @since 4.0.0
|
|
73
102
|
*/
|
|
74
103
|
export declare const layer: (config: MysqlClientConfig) => Layer.Layer<MysqlClient | Client.SqlClient, Config.ConfigError | SqlError>;
|
|
75
104
|
/**
|
|
105
|
+
* Creates the MySQL statement compiler, using `?` placeholders and backtick-escaped identifiers.
|
|
106
|
+
*
|
|
76
107
|
* @category compiler
|
|
77
|
-
* @since
|
|
108
|
+
* @since 4.0.0
|
|
78
109
|
*/
|
|
79
110
|
export declare const makeCompiler: (transform?: (_: string) => string) => Statement.Compiler;
|
|
80
111
|
//# sourceMappingURL=MysqlClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MysqlClient.d.ts","sourceRoot":"","sources":["../src/MysqlClient.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"MysqlClient.d.ts","sourceRoot":"","sources":["../src/MysqlClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,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;AAEzC,OAAO,KAAK,UAAU,MAAM,uCAAuC,CAAA;AACnE,OAAO,KAAK,MAAM,MAAM,+BAA+B,CAAA;AAEvD,OAAO,EAOL,QAAQ,EAKT,MAAM,8BAA8B,CAAA;AAErC,OAAO,KAAK,SAAS,MAAM,+BAA+B,CAAA;AAC1D,OAAO,KAAK,KAAK,MAAM,QAAQ,CAAA;AAkG/B;;;;;GAKG;AACH,eAAO,MAAM,MAAM,EAAE,MAA0C,CAAA;AAE/D;;;;;GAKG;AACH,MAAM,MAAM,MAAM,GAAG,iCAAiC,CAAA;AAEtD;;;;;GAKG;AACH,MAAM,WAAW,WAAY,SAAQ,MAAM,CAAC,SAAS;IACnD,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAA;CACnC;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,2CAAiE,CAAA;AAEzF;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH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EAAE,MAAM,CAAC,WAAW,GAAG,QAAQ,CAUnC,CAAA;AAEzC;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAChB,QAAQ,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,GAAI,YAAY,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,uBAiB1D,CAAA"}
|
package/dist/MysqlClient.js
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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,19 +27,113 @@ 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
|
-
*
|
|
23
|
-
*
|
|
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
|
-
*
|
|
28
|
-
*
|
|
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__*/
|
|
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
|
|
136
|
+
* @since 4.0.0
|
|
34
137
|
*/
|
|
35
138
|
export const make = options => Effect.gen(function* () {
|
|
36
139
|
const compiler = makeCompiler(options.transformQueryNames);
|
|
@@ -42,7 +145,7 @@ export const make = options => Effect.gen(function* () {
|
|
|
42
145
|
}
|
|
43
146
|
runRaw(sql, values, rowsAsArray = false, method = "execute") {
|
|
44
147
|
return Effect.callback(resume => {
|
|
45
|
-
;
|
|
148
|
+
const operation = method === "query" ? "executeUnprepared" : "execute";
|
|
46
149
|
this.conn[method]({
|
|
47
150
|
sql,
|
|
48
151
|
values,
|
|
@@ -50,8 +153,7 @@ export const make = options => Effect.gen(function* () {
|
|
|
50
153
|
}, (cause, results, _fields) => {
|
|
51
154
|
if (cause) {
|
|
52
155
|
resume(Effect.fail(new SqlError({
|
|
53
|
-
cause,
|
|
54
|
-
message: "Failed to execute statement"
|
|
156
|
+
reason: classifyError(cause, "Failed to execute statement", operation)
|
|
55
157
|
})));
|
|
56
158
|
} else {
|
|
57
159
|
resume(Effect.succeed(results));
|
|
@@ -102,8 +204,7 @@ export const make = options => Effect.gen(function* () {
|
|
|
102
204
|
pool.query("SELECT 1", cause => {
|
|
103
205
|
if (cause) {
|
|
104
206
|
resume(Effect.fail(new SqlError({
|
|
105
|
-
cause,
|
|
106
|
-
message: "MysqlClient: Failed to connect"
|
|
207
|
+
reason: classifyError(cause, "MysqlClient: Failed to connect", "connect")
|
|
107
208
|
})));
|
|
108
209
|
} else {
|
|
109
210
|
resume(Effect.void);
|
|
@@ -113,9 +214,12 @@ export const make = options => Effect.gen(function* () {
|
|
|
113
214
|
pool.end(() => resume(Effect.void));
|
|
114
215
|
})).pipe(Effect.timeoutOrElse({
|
|
115
216
|
duration: Duration.seconds(5),
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
217
|
+
orElse: () => Effect.fail(new SqlError({
|
|
218
|
+
reason: new ConnectionError({
|
|
219
|
+
message: "MysqlClient: Connection timeout",
|
|
220
|
+
cause: new Error("connection timeout"),
|
|
221
|
+
operation: "connect"
|
|
222
|
+
})
|
|
119
223
|
}))
|
|
120
224
|
}));
|
|
121
225
|
const poolConnection = new ConnectionImpl(pool);
|
|
@@ -123,8 +227,7 @@ export const make = options => Effect.gen(function* () {
|
|
|
123
227
|
pool.getConnection((cause, conn) => {
|
|
124
228
|
if (cause) {
|
|
125
229
|
resume(Effect.fail(new SqlError({
|
|
126
|
-
cause,
|
|
127
|
-
message: "Failed to acquire connection"
|
|
230
|
+
reason: classifyError(cause, "Failed to acquire connection", "acquireConnection")
|
|
128
231
|
})));
|
|
129
232
|
} else {
|
|
130
233
|
resume(Effect.succeed(conn));
|
|
@@ -148,18 +251,24 @@ export const make = options => Effect.gen(function* () {
|
|
|
148
251
|
});
|
|
149
252
|
});
|
|
150
253
|
/**
|
|
254
|
+
* Creates a layer from a `Config`-wrapped MySQL client configuration, providing both `MysqlClient` and `SqlClient`.
|
|
255
|
+
*
|
|
151
256
|
* @category layers
|
|
152
|
-
* @since
|
|
257
|
+
* @since 4.0.0
|
|
153
258
|
*/
|
|
154
|
-
export const layerConfig = config => Layer.
|
|
259
|
+
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
260
|
/**
|
|
261
|
+
* Creates a layer from a concrete MySQL client configuration, providing both `MysqlClient` and `SqlClient`.
|
|
262
|
+
*
|
|
156
263
|
* @category layers
|
|
157
|
-
* @since
|
|
264
|
+
* @since 4.0.0
|
|
158
265
|
*/
|
|
159
|
-
export const layer = config => Layer.
|
|
266
|
+
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
267
|
/**
|
|
268
|
+
* Creates the MySQL statement compiler, using `?` placeholders and backtick-escaped identifiers.
|
|
269
|
+
*
|
|
161
270
|
* @category compiler
|
|
162
|
-
* @since
|
|
271
|
+
* @since 4.0.0
|
|
163
272
|
*/
|
|
164
273
|
export const makeCompiler = transform => Statement.makeCompiler({
|
|
165
274
|
dialect: "mysql",
|
|
@@ -184,8 +293,7 @@ function queryStream(conn, sql, params) {
|
|
|
184
293
|
let buffer = [];
|
|
185
294
|
let taskPending = false;
|
|
186
295
|
query.on("error", cause => emit.fail(new SqlError({
|
|
187
|
-
cause,
|
|
188
|
-
message: "Failed to stream statement"
|
|
296
|
+
reason: classifyError(cause, "Failed to stream statement", "stream")
|
|
189
297
|
})));
|
|
190
298
|
query.on("data", row => {
|
|
191
299
|
buffer.push(row);
|
package/dist/MysqlClient.js.map
CHANGED
|
@@ -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,OAAO,MAAMC,IAAI,GACfC,OAA0B,IAE1BnB,MAAM,CAACoB,GAAG,CAAC,aAAS;EAClB,MAAMC,QAAQ,GAAGC,YAAY,CAACH,OAAO,CAACI,mBAAmB,CAAC;EAC1D,MAAMC,aAAa,GAAGL,OAAO,CAACM,oBAAoB,GAChDhB,SAAS,CAACiB,iBAAiB,CACzBP,OAAO,CAACM,oBAAoB,CAC7B,CAACE,KAAK,GACPC,SAAS;EAEX,MAAMC,cAAc;IACTC,IAAI;IACbC,YAAYD,IAAuC;MACjD,IAAI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EgC,KAAK;MAAEI,OAAO,EAAE;IAA4B,CAAE,CAAC,CAAC,CAAC;IAChHsC,KAAK,CAAC8C,EAAE,CAAC,MAAM,EAAGC,GAAQ,IAAI;MAC5BH,MAAM,CAAC3B,IAAI,CAAC8B,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;IACF7C,KAAK,CAAC8C,EAAE,CAAC,KAAK,EAAE,MAAK;MACnB,IAAIF,MAAM,CAACM,MAAM,GAAG,CAAC,EAAE;QACrBT,IAAI,CAAC/F,KAAK,CAACkG,MAAM,CAAC;QAClBA,MAAM,GAAG,EAAE;MACb;MACAH,IAAI,CAACvC,GAAG,EAAE;IACZ,CAAC,CAAC;IAEF,OAAO;MACLiD,OAAOA,CAAA;QACLnD,KAAK,CAACoD,KAAK,EAAE;MACf,CAAC;MACDC,QAAQA,CAAA;QACNrD,KAAK,CAAC3C,MAAM,EAAE;MAChB;KACD;EACH,CAAC,CAAC,CAAC;AACL","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"MysqlClient.js","names":["Config","Context","Duration","Effect","Layer","Redacted","Stream","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","ConnectionImpl","conn","constructor","runRaw","sql","values","rowsAsArray","method","callback","resume","results","_fields","fail","reason","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","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,OAAO,KAAKC,OAAO,MAAM,gBAAgB;AACzC,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,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,UAAU,MAAM,uCAAuC;AACnE,OAAO,KAAKC,MAAM,MAAM,+BAA+B;AAEvD,SACEC,mBAAmB,EACnBC,kBAAkB,EAClBC,eAAe,EACfC,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AAK;QACrB,CAAC,CAAC;MACJ;IACF,CAAC,CAAC;IACF5C,KAAK,CAAC6C,EAAE,CAAC,KAAK,EAAE,MAAK;MACnB,IAAIF,MAAM,CAACzH,MAAM,GAAG,CAAC,EAAE;QACrBsH,IAAI,CAAC5F,KAAK,CAAC+F,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,CAAC1C,MAAM,EAAE;MAChB;KACD;EACH,CAAC,CAAC,CAAC;AACL","ignoreList":[]}
|
package/dist/MysqlMigrator.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
|
18
|
+
* @since 4.0.0
|
|
11
19
|
*/
|
|
12
20
|
export * from "effect/unstable/sql/Migrator";
|
|
13
21
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
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
|
|
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
|
|
1
|
+
{"version":3,"file":"MysqlMigrator.d.ts","sourceRoot":"","sources":["../src/MysqlMigrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;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,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAE5D;;GAEG;AACH,cAAc,8BAA8B,CAAA;AAE5C;;;;;GAKG;AACH,eAAO,MAAM,GAAG,EAAE,CAAC,EAAE,GAAG,KAAK,EAC3B,EAAE,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,EAAE,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,KAC7D,MAAM,CAAC,MAAM,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,EACrB,SAAS,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"}
|
package/dist/MysqlMigrator.js
CHANGED
|
@@ -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
|
|
4
|
+
* @since 4.0.0
|
|
5
5
|
*/
|
|
6
6
|
export * from "effect/unstable/sql/Migrator";
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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
|
|
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":"
|
|
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
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
|
-
* @since
|
|
5
|
+
* @since 4.0.0
|
|
6
6
|
*/
|
|
7
7
|
export * as MysqlClient from "./MysqlClient.ts";
|
|
8
8
|
/**
|
|
9
|
-
* @since
|
|
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
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
// @barrel: Auto-generated exports. Do not edit manually.
|
|
5
5
|
/**
|
|
6
|
-
* @since
|
|
6
|
+
* @since 4.0.0
|
|
7
7
|
*/
|
|
8
8
|
export * as MysqlClient from "./MysqlClient.js";
|
|
9
9
|
/**
|
|
10
|
-
* @since
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/sql-mysql2",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.81",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "A MySQL toolkit for Effect",
|
|
@@ -43,14 +43,14 @@
|
|
|
43
43
|
"provenance": true
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@testcontainers/mysql": "^11.
|
|
47
|
-
"effect": "^4.0.0-beta.
|
|
46
|
+
"@testcontainers/mysql": "^11.14.0",
|
|
47
|
+
"effect": "^4.0.0-beta.81"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"effect": "^4.0.0-beta.
|
|
50
|
+
"effect": "^4.0.0-beta.81"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"mysql2": "^3.
|
|
53
|
+
"mysql2": "^3.22.3"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"codegen": "effect-utils codegen",
|
package/src/MysqlClient.ts
CHANGED
|
@@ -1,18 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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 {
|
|
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
|
-
*
|
|
27
|
-
*
|
|
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
|
-
*
|
|
33
|
-
*
|
|
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
|
|
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
|
-
*
|
|
48
|
-
*
|
|
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 =
|
|
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
|
|
180
|
+
* @since 4.0.0
|
|
55
181
|
*/
|
|
56
182
|
export interface MysqlClientConfig {
|
|
57
183
|
/**
|
|
@@ -77,8 +203,10 @@ export interface MysqlClientConfig {
|
|
|
77
203
|
}
|
|
78
204
|
|
|
79
205
|
/**
|
|
206
|
+
* Creates a scoped MySQL client backed by a managed mysql2 pool, verifying connectivity and supporting streaming queries through mysql2 query streams.
|
|
207
|
+
*
|
|
80
208
|
* @category constructors
|
|
81
|
-
* @since
|
|
209
|
+
* @since 4.0.0
|
|
82
210
|
*/
|
|
83
211
|
export const make = (
|
|
84
212
|
options: MysqlClientConfig
|
|
@@ -104,13 +232,16 @@ export const make = (
|
|
|
104
232
|
method: "execute" | "query" = "execute"
|
|
105
233
|
) {
|
|
106
234
|
return Effect.callback<unknown, SqlError>((resume) => {
|
|
235
|
+
const operation = method === "query" ? "executeUnprepared" : "execute"
|
|
107
236
|
;(this.conn as any)[method]({
|
|
108
237
|
sql,
|
|
109
238
|
values,
|
|
110
239
|
rowsAsArray
|
|
111
240
|
}, (cause: unknown | null, results: unknown, _fields: any) => {
|
|
112
241
|
if (cause) {
|
|
113
|
-
resume(
|
|
242
|
+
resume(
|
|
243
|
+
Effect.fail(new SqlError({ reason: classifyError(cause, "Failed to execute statement", operation) }))
|
|
244
|
+
)
|
|
114
245
|
} else {
|
|
115
246
|
resume(Effect.succeed(results))
|
|
116
247
|
}
|
|
@@ -198,8 +329,7 @@ export const make = (
|
|
|
198
329
|
if (cause) {
|
|
199
330
|
resume(Effect.fail(
|
|
200
331
|
new SqlError({
|
|
201
|
-
cause,
|
|
202
|
-
message: "MysqlClient: Failed to connect"
|
|
332
|
+
reason: classifyError(cause, "MysqlClient: Failed to connect", "connect")
|
|
203
333
|
})
|
|
204
334
|
))
|
|
205
335
|
} else {
|
|
@@ -214,11 +344,14 @@ export const make = (
|
|
|
214
344
|
).pipe(
|
|
215
345
|
Effect.timeoutOrElse({
|
|
216
346
|
duration: Duration.seconds(5),
|
|
217
|
-
|
|
347
|
+
orElse: () =>
|
|
218
348
|
Effect.fail(
|
|
219
349
|
new SqlError({
|
|
220
|
-
|
|
221
|
-
|
|
350
|
+
reason: new ConnectionError({
|
|
351
|
+
message: "MysqlClient: Connection timeout",
|
|
352
|
+
cause: new Error("connection timeout"),
|
|
353
|
+
operation: "connect"
|
|
354
|
+
})
|
|
222
355
|
})
|
|
223
356
|
)
|
|
224
357
|
})
|
|
@@ -230,7 +363,13 @@ export const make = (
|
|
|
230
363
|
Effect.callback<Mysql.PoolConnection, SqlError>((resume) => {
|
|
231
364
|
pool.getConnection((cause, conn) => {
|
|
232
365
|
if (cause) {
|
|
233
|
-
resume(
|
|
366
|
+
resume(
|
|
367
|
+
Effect.fail(
|
|
368
|
+
new SqlError({
|
|
369
|
+
reason: classifyError(cause, "Failed to acquire connection", "acquireConnection")
|
|
370
|
+
})
|
|
371
|
+
)
|
|
372
|
+
)
|
|
234
373
|
} else {
|
|
235
374
|
resume(Effect.succeed(conn))
|
|
236
375
|
}
|
|
@@ -268,40 +407,46 @@ export const make = (
|
|
|
268
407
|
})
|
|
269
408
|
|
|
270
409
|
/**
|
|
410
|
+
* Creates a layer from a `Config`-wrapped MySQL client configuration, providing both `MysqlClient` and `SqlClient`.
|
|
411
|
+
*
|
|
271
412
|
* @category layers
|
|
272
|
-
* @since
|
|
413
|
+
* @since 4.0.0
|
|
273
414
|
*/
|
|
274
415
|
export const layerConfig = (
|
|
275
416
|
config: Config.Wrap<MysqlClientConfig>
|
|
276
417
|
): Layer.Layer<MysqlClient | Client.SqlClient, Config.ConfigError | SqlError> =>
|
|
277
|
-
Layer.
|
|
278
|
-
Config.unwrap(config).
|
|
418
|
+
Layer.effectContext(
|
|
419
|
+
Config.unwrap(config).pipe(
|
|
279
420
|
Effect.flatMap(make),
|
|
280
421
|
Effect.map((client) =>
|
|
281
|
-
|
|
282
|
-
|
|
422
|
+
Context.make(MysqlClient, client).pipe(
|
|
423
|
+
Context.add(Client.SqlClient, client)
|
|
283
424
|
)
|
|
284
425
|
)
|
|
285
426
|
)
|
|
286
427
|
).pipe(Layer.provide(Reactivity.layer))
|
|
287
428
|
|
|
288
429
|
/**
|
|
430
|
+
* Creates a layer from a concrete MySQL client configuration, providing both `MysqlClient` and `SqlClient`.
|
|
431
|
+
*
|
|
289
432
|
* @category layers
|
|
290
|
-
* @since
|
|
433
|
+
* @since 4.0.0
|
|
291
434
|
*/
|
|
292
435
|
export const layer = (
|
|
293
436
|
config: MysqlClientConfig
|
|
294
437
|
): Layer.Layer<MysqlClient | Client.SqlClient, Config.ConfigError | SqlError> =>
|
|
295
|
-
Layer.
|
|
438
|
+
Layer.effectContext(
|
|
296
439
|
Effect.map(make(config), (client) =>
|
|
297
|
-
|
|
298
|
-
|
|
440
|
+
Context.make(MysqlClient, client).pipe(
|
|
441
|
+
Context.add(Client.SqlClient, client)
|
|
299
442
|
))
|
|
300
443
|
).pipe(Layer.provide(Reactivity.layer))
|
|
301
444
|
|
|
302
445
|
/**
|
|
446
|
+
* Creates the MySQL statement compiler, using `?` placeholders and backtick-escaped identifiers.
|
|
447
|
+
*
|
|
303
448
|
* @category compiler
|
|
304
|
-
* @since
|
|
449
|
+
* @since 4.0.0
|
|
305
450
|
*/
|
|
306
451
|
export const makeCompiler = (transform?: (_: string) => string) =>
|
|
307
452
|
Statement.makeCompiler({
|
|
@@ -331,11 +476,15 @@ function queryStream(
|
|
|
331
476
|
) {
|
|
332
477
|
return asyncPauseResume<any, SqlError>(Effect.fnUntraced(function*(emit) {
|
|
333
478
|
const query = (conn as any).query(sql, params).stream()
|
|
334
|
-
yield* Effect.addFinalizer(() => Effect.sync(() => query.destroy()))
|
|
479
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => query.destroy() as void))
|
|
335
480
|
|
|
336
481
|
let buffer: Array<any> = []
|
|
337
482
|
let taskPending = false
|
|
338
|
-
query.on(
|
|
483
|
+
query.on(
|
|
484
|
+
"error",
|
|
485
|
+
(cause: unknown) =>
|
|
486
|
+
emit.fail(new SqlError({ reason: classifyError(cause, "Failed to stream statement", "stream") }))
|
|
487
|
+
)
|
|
339
488
|
query.on("data", (row: any) => {
|
|
340
489
|
buffer.push(row)
|
|
341
490
|
if (!taskPending) {
|
package/src/MysqlMigrator.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
|
19
|
+
* @since 4.0.0
|
|
12
20
|
*/
|
|
13
21
|
export * from "effect/unstable/sql/Migrator"
|
|
14
22
|
|
|
15
23
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
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
|
|
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
|
|
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
|
|
8
|
+
* @since 4.0.0
|
|
9
9
|
*/
|
|
10
10
|
export * as MysqlClient from "./MysqlClient.ts"
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @since
|
|
13
|
+
* @since 4.0.0
|
|
14
14
|
*/
|
|
15
15
|
export * as MysqlMigrator from "./MysqlMigrator.ts"
|