@prisma/orm-target-mysql 0.0.0-stage → 8.0.0-rc.21-dev.23
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/LICENSE +201 -0
- package/README.md +20 -2
- package/dist/adapter-_WBomuTw.d.mts +27 -0
- package/dist/adapter-_WBomuTw.d.mts.map +1 -0
- package/dist/adapter.d.mts +6 -0
- package/dist/adapter.mjs +3 -0
- package/dist/adapter__adapter.d.mts +2 -0
- package/dist/adapter__adapter.mjs +2 -0
- package/dist/adapter__codec-types.d.mts +3 -0
- package/dist/adapter__codec-types.mjs +1 -0
- package/dist/adapter__control.d.mts +2 -0
- package/dist/adapter__control.mjs +2 -0
- package/dist/adapter__runtime.d.mts +2 -0
- package/dist/adapter__runtime.mjs +417 -0
- package/dist/adapter__runtime.mjs.map +1 -0
- package/dist/codec-descriptor-DXyubAS6-siA0R8Ow.d.mts +43 -0
- package/dist/codec-descriptor-DXyubAS6-siA0R8Ow.d.mts.map +1 -0
- package/dist/codec-descriptor-Du6DSz-3-ytBCu_mq.mjs +93 -0
- package/dist/codec-descriptor-Du6DSz-3-ytBCu_mq.mjs.map +1 -0
- package/dist/codec-descriptor-J3TP08l8-ekLvUVxW.d.mts +1 -0
- package/dist/codec-descriptor-oLRh9E29.d.mts +2 -0
- package/dist/codec-ids-BHUwoNOM.d.mts +2 -0
- package/dist/codec-ids-C00hAFkc.mjs +2 -0
- package/dist/codec-ids-cjxtOcLM-vFeQhgPm.mjs +10 -0
- package/dist/codec-ids-cjxtOcLM-vFeQhgPm.mjs.map +1 -0
- package/dist/codec-ids-sMOU8F-B-BQbCq2dr.d.mts +10 -0
- package/dist/codec-ids-sMOU8F-B-BQbCq2dr.d.mts.map +1 -0
- package/dist/codec-types-Bd7DL1Mr-CZWNfnp9.d.mts +21 -0
- package/dist/codec-types-Bd7DL1Mr-CZWNfnp9.d.mts.map +1 -0
- package/dist/codec-types-Bo3Jfilx.d.mts +1 -0
- package/dist/codec-types-Ja2kLzLS.d.mts +1 -0
- package/dist/codecs-C00kjHgh.mjs +282 -0
- package/dist/codecs-C00kjHgh.mjs.map +1 -0
- package/dist/codecs-CO_VNEYU-CwAnKzRs.d.mts +102 -0
- package/dist/codecs-CO_VNEYU-CwAnKzRs.d.mts.map +1 -0
- package/dist/codecs-DM61agRr.d.mts +21 -0
- package/dist/codecs-DM61agRr.d.mts.map +1 -0
- package/dist/contract-contributions-B9njRJbt-ClEtrK2L.mjs +14 -0
- package/dist/contract-contributions-B9njRJbt-ClEtrK2L.mjs.map +1 -0
- package/dist/contract-free-BvCdx_Ee.mjs +71 -0
- package/dist/contract-free-BvCdx_Ee.mjs.map +1 -0
- package/dist/contract-free-Cw9Mjcro.d.mts +22 -0
- package/dist/contract-free-Cw9Mjcro.d.mts.map +1 -0
- package/dist/control-C9zxRXNN.mjs +74 -0
- package/dist/control-C9zxRXNN.mjs.map +1 -0
- package/dist/control-DHkZbo58.d.mts +25 -0
- package/dist/control-DHkZbo58.d.mts.map +1 -0
- package/dist/control-Ez_PtlFI.d.mts +121 -0
- package/dist/control-Ez_PtlFI.d.mts.map +1 -0
- package/dist/control-WTY7Jpxk.mjs +577 -0
- package/dist/control-WTY7Jpxk.mjs.map +1 -0
- package/dist/control-_4epnrIW.d.mts +27 -0
- package/dist/control-_4epnrIW.d.mts.map +1 -0
- package/dist/control-tables-CHw2F-rg.d.mts +9 -0
- package/dist/control-tables-CHw2F-rg.d.mts.map +1 -0
- package/dist/control-tables-CcQ77JE7-CxTQYoQJ.mjs +9 -0
- package/dist/control-tables-CcQ77JE7-CxTQYoQJ.mjs.map +1 -0
- package/dist/data-type-entries-B0AoBozh-f9AEUIUQ.mjs +42 -0
- package/dist/data-type-entries-B0AoBozh-f9AEUIUQ.mjs.map +1 -0
- package/dist/data-types-BpihGKoK-BMW-m4EN.d.mts +52 -0
- package/dist/data-types-BpihGKoK-BMW-m4EN.d.mts.map +1 -0
- package/dist/data-types-Dv9gwVRV-BZPzCWZk.mjs +181 -0
- package/dist/data-types-Dv9gwVRV-BZPzCWZk.mjs.map +1 -0
- package/dist/data-types-SXrh0Lou.d.mts +8 -0
- package/dist/data-types-SXrh0Lou.d.mts.map +1 -0
- package/dist/ddl-CT6DPEqg.d.mts +1 -0
- package/dist/ddl-DDmMHyA_-Bb8sXoS0.mjs +12 -0
- package/dist/ddl-DDmMHyA_-Bb8sXoS0.mjs.map +1 -0
- package/dist/default-normalizer-BBhGpw7r.d.mts +27 -0
- package/dist/default-normalizer-BBhGpw7r.d.mts.map +1 -0
- package/dist/default-normalizer-BDUgHXUn-Xk7HQJuI.mjs +90 -0
- package/dist/default-normalizer-BDUgHXUn-Xk7HQJuI.mjs.map +1 -0
- package/dist/descriptor-meta-BurjcSiU-Cbk2L1jf.mjs +82 -0
- package/dist/descriptor-meta-BurjcSiU-Cbk2L1jf.mjs.map +1 -0
- package/dist/descriptor-meta-runtime-Bk_00UrX-BLN4Ahpj.mjs +17 -0
- package/dist/descriptor-meta-runtime-Bk_00UrX-BLN4Ahpj.mjs.map +1 -0
- package/dist/driver.d.mts +3 -0
- package/dist/driver.mjs +2 -0
- package/dist/driver__control.d.mts +2 -0
- package/dist/driver__control.mjs +2 -0
- package/dist/driver__runtime.d.mts +2 -0
- package/dist/driver__runtime.mjs +325 -0
- package/dist/driver__runtime.mjs.map +1 -0
- package/dist/errors-BYhjQT7y.d.mts +10 -0
- package/dist/errors-BYhjQT7y.d.mts.map +1 -0
- package/dist/errors-rvH_F2Yj-BQrO_--u.mjs +20 -0
- package/dist/errors-rvH_F2Yj-BQrO_--u.mjs.map +1 -0
- package/dist/marker-lock-CmGvN4hw-Com29AtQ.mjs +51 -0
- package/dist/marker-lock-CmGvN4hw-Com29AtQ.mjs.map +1 -0
- package/dist/marker-lock-su6IxinO.d.mts +18 -0
- package/dist/marker-lock-su6IxinO.d.mts.map +1 -0
- package/dist/marker-read-aEaHihYj-Cyg16yn1.mjs +78 -0
- package/dist/marker-read-aEaHihYj-Cyg16yn1.mjs.map +1 -0
- package/dist/migration-DmlblTTw.d.mts +284 -0
- package/dist/migration-DmlblTTw.d.mts.map +1 -0
- package/dist/migration-tFuoN9GB.mjs +5 -0
- package/dist/mysql-contract-serializer-DLv0uW_f-Cg4A43Ry.mjs +160 -0
- package/dist/mysql-contract-serializer-DLv0uW_f-Cg4A43Ry.mjs.map +1 -0
- package/dist/nodes-CvcX47ot-B-ZaUYRj.mjs +25 -0
- package/dist/nodes-CvcX47ot-B-ZaUYRj.mjs.map +1 -0
- package/dist/nodes-xc0cR0_c-2YbhgEjb.d.mts +27 -0
- package/dist/nodes-xc0cR0_c-2YbhgEjb.d.mts.map +1 -0
- package/dist/pack-YVG-iBMQ.d.mts +1073 -0
- package/dist/pack-YVG-iBMQ.d.mts.map +1 -0
- package/dist/planner-target-details-D6g2uSp--C5NKHmCc.d.mts +12 -0
- package/dist/planner-target-details-D6g2uSp--C5NKHmCc.d.mts.map +1 -0
- package/dist/runner-C4r6yEd1-BWQrxW9q.mjs +1644 -0
- package/dist/runner-C4r6yEd1-BWQrxW9q.mjs.map +1 -0
- package/dist/runtime-BGyTXcQH.d.mts +36 -0
- package/dist/runtime-BGyTXcQH.d.mts.map +1 -0
- package/dist/runtime-CeuRr9nE.d.mts +29 -0
- package/dist/runtime-CeuRr9nE.d.mts.map +1 -0
- package/dist/runtime-Cl0BbTZq.d.mts +22 -0
- package/dist/runtime-Cl0BbTZq.d.mts.map +1 -0
- package/dist/sql-utils-BOS1c2QT.d.mts +30 -0
- package/dist/sql-utils-BOS1c2QT.d.mts.map +1 -0
- package/dist/sql-utils-Db0IQO_B-PaULnfrE.mjs +30 -0
- package/dist/sql-utils-Db0IQO_B-PaULnfrE.mjs.map +1 -0
- package/dist/sql-utils-RW0vJvDl.mjs +94 -0
- package/dist/sql-utils-RW0vJvDl.mjs.map +1 -0
- package/dist/statement-A6bbPBf1-q61iHQLb.mjs +483 -0
- package/dist/statement-A6bbPBf1-q61iHQLb.mjs.map +1 -0
- package/dist/target.d.mts +24 -0
- package/dist/target.mjs +19 -0
- package/dist/target__codec-descriptor.d.mts +3 -0
- package/dist/target__codec-descriptor.mjs +2 -0
- package/dist/target__codec-ids.d.mts +3 -0
- package/dist/target__codec-ids.mjs +3 -0
- package/dist/target__codec-types.d.mts +3 -0
- package/dist/target__codec-types.mjs +1 -0
- package/dist/target__codecs.d.mts +3 -0
- package/dist/target__codecs.mjs +2 -0
- package/dist/target__contract-free.d.mts +2 -0
- package/dist/target__contract-free.mjs +3 -0
- package/dist/target__control-tables.d.mts +2 -0
- package/dist/target__control-tables.mjs +2 -0
- package/dist/target__control.d.mts +3 -0
- package/dist/target__control.mjs +58 -0
- package/dist/target__control.mjs.map +1 -0
- package/dist/target__data-types.d.mts +3 -0
- package/dist/target__data-types.mjs +3 -0
- package/dist/target__ddl.d.mts +3 -0
- package/dist/target__ddl.mjs +2 -0
- package/dist/target__default-normalizer.d.mts +2 -0
- package/dist/target__default-normalizer.mjs +2 -0
- package/dist/target__errors.d.mts +2 -0
- package/dist/target__errors.mjs +2 -0
- package/dist/target__marker-lock.d.mts +2 -0
- package/dist/target__marker-lock.mjs +2 -0
- package/dist/target__migration.d.mts +2 -0
- package/dist/target__migration.mjs +3 -0
- package/dist/target__pack.d.mts +2 -0
- package/dist/target__pack.mjs +2 -0
- package/dist/target__runtime.d.mts +2 -0
- package/dist/target__runtime.mjs +17 -0
- package/dist/target__runtime.mjs.map +1 -0
- package/dist/target__sql-utils.d.mts +2 -0
- package/dist/target__sql-utils.mjs +3 -0
- package/package.json +71 -3
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
//#region ../../../3-targets/mysql/1-target/dist/default-normalizer-BDUgHXUn.mjs
|
|
2
|
+
const AUTOINCREMENT = {
|
|
3
|
+
kind: "function",
|
|
4
|
+
expression: "autoincrement()"
|
|
5
|
+
};
|
|
6
|
+
const NOW = {
|
|
7
|
+
kind: "function",
|
|
8
|
+
expression: "now()"
|
|
9
|
+
};
|
|
10
|
+
const CURRENT_TIMESTAMP = /^(?:current_timestamp|now|localtime|localtimestamp)(?:\s*\(\s*\d*\s*\))?$/i;
|
|
11
|
+
const SQL_ESCAPES = {
|
|
12
|
+
"0": "\0",
|
|
13
|
+
b: "\b",
|
|
14
|
+
n: "\n",
|
|
15
|
+
r: "\r",
|
|
16
|
+
t: " ",
|
|
17
|
+
Z: ""
|
|
18
|
+
};
|
|
19
|
+
const INTRODUCED_STRING = /^_[A-Za-z0-9]+'/;
|
|
20
|
+
function withoutBackslashEscapes(text) {
|
|
21
|
+
return text.replace(/\\(.)/gs, "$1");
|
|
22
|
+
}
|
|
23
|
+
/** The text of a MySQL string literal whose opening quote ends `start`, when the literal runs to the end of `text`. */
|
|
24
|
+
function stringLiteralBody(text, start) {
|
|
25
|
+
let body = "";
|
|
26
|
+
for (let index = start; index < text.length; index += 1) {
|
|
27
|
+
const char = text.charAt(index);
|
|
28
|
+
if (char === "\\") {
|
|
29
|
+
index += 1;
|
|
30
|
+
const escaped = text.charAt(index);
|
|
31
|
+
body += escaped === "%" || escaped === "_" ? `\\${escaped}` : SQL_ESCAPES[escaped] ?? escaped;
|
|
32
|
+
} else if (char === "'" && text.charAt(index + 1) === "'") {
|
|
33
|
+
body += "'";
|
|
34
|
+
index += 1;
|
|
35
|
+
} else if (char === "'") return index === text.length - 1 ? body : void 0;
|
|
36
|
+
else body += char;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The value of a default MySQL reports as a string with a character set introducer, such as `_utf8mb4\'abc\'`: the form a literal default on a text, blob or JSON column takes, because MySQL writes it as an expression. `undefined` for any other expression.
|
|
41
|
+
*/
|
|
42
|
+
function introducedStringValue(reported) {
|
|
43
|
+
const expression = withoutBackslashEscapes(reported.trim());
|
|
44
|
+
const opening = INTRODUCED_STRING.exec(expression);
|
|
45
|
+
return opening === null ? void 0 : stringLiteralBody(expression, opening[0].length);
|
|
46
|
+
}
|
|
47
|
+
function extraFlags(extra) {
|
|
48
|
+
return extra.toLowerCase().split(/\s+/);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Reads a column's reported default from `COLUMN_DEFAULT` and `EXTRA`. `auto_increment` is `autoincrement()`; a string with a character set introducer, the form MySQL reports for a literal default on a text, blob or JSON column, is that literal; an expression default that writes the current time, such as `CURRENT_TIMESTAMP(3)`, is `now()`; any other expression default is a function default kept as reported; and anything else is a literal. `undefined` when the column has no default.
|
|
52
|
+
*/
|
|
53
|
+
function readMysqlDefault(columnDefault, extra) {
|
|
54
|
+
const flags = extraFlags(extra);
|
|
55
|
+
if (flags.includes("auto_increment")) return AUTOINCREMENT;
|
|
56
|
+
if (columnDefault === null) return void 0;
|
|
57
|
+
if (flags.includes("default_generated")) {
|
|
58
|
+
const introduced = introducedStringValue(columnDefault);
|
|
59
|
+
if (introduced !== void 0) return {
|
|
60
|
+
kind: "literal",
|
|
61
|
+
literal: {
|
|
62
|
+
kind: "value",
|
|
63
|
+
body: introduced
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const expression = columnDefault.trim();
|
|
67
|
+
return CURRENT_TIMESTAMP.test(expression) ? NOW : {
|
|
68
|
+
kind: "function",
|
|
69
|
+
expression
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
kind: "literal",
|
|
74
|
+
literal: {
|
|
75
|
+
kind: "value",
|
|
76
|
+
body: columnDefault
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Names a contract's expression default the way {@link readMysqlDefault} names the same function in the database, so `` sql`CURRENT_TIMESTAMP(3)` `` and the database's `now()` compare equal. Every other default passes through unchanged.
|
|
82
|
+
*/
|
|
83
|
+
function mysqlResolveDefault(def, _column) {
|
|
84
|
+
if (def.kind !== "function") return def;
|
|
85
|
+
return CURRENT_TIMESTAMP.test(def.expression.trim()) ? NOW : def;
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
export { readMysqlDefault as n, mysqlResolveDefault as t };
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=default-normalizer-BDUgHXUn-Xk7HQJuI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-normalizer-BDUgHXUn-Xk7HQJuI.mjs","names":[],"sources":["../../../../3-targets/mysql/1-target/dist/default-normalizer-BDUgHXUn.mjs"],"sourcesContent":["//#region src/core/default-normalizer.ts\nconst AUTOINCREMENT = {\n\tkind: \"function\",\n\texpression: \"autoincrement()\"\n};\nconst NOW = {\n\tkind: \"function\",\n\texpression: \"now()\"\n};\nconst CURRENT_TIMESTAMP = /^(?:current_timestamp|now|localtime|localtimestamp)(?:\\s*\\(\\s*\\d*\\s*\\))?$/i;\nconst SQL_ESCAPES = {\n\t\"0\": \"\\0\",\n\tb: \"\\b\",\n\tn: \"\\n\",\n\tr: \"\\r\",\n\tt: \"\t\",\n\tZ: \"\u001a\"\n};\nconst INTRODUCED_STRING = /^_[A-Za-z0-9]+'/;\nfunction withoutBackslashEscapes(text) {\n\treturn text.replace(/\\\\(.)/gs, \"$1\");\n}\n/** The text of a MySQL string literal whose opening quote ends `start`, when the literal runs to the end of `text`. */\nfunction stringLiteralBody(text, start) {\n\tlet body = \"\";\n\tfor (let index = start; index < text.length; index += 1) {\n\t\tconst char = text.charAt(index);\n\t\tif (char === \"\\\\\") {\n\t\t\tindex += 1;\n\t\t\tconst escaped = text.charAt(index);\n\t\t\tbody += escaped === \"%\" || escaped === \"_\" ? `\\\\${escaped}` : SQL_ESCAPES[escaped] ?? escaped;\n\t\t} else if (char === \"'\" && text.charAt(index + 1) === \"'\") {\n\t\t\tbody += \"'\";\n\t\t\tindex += 1;\n\t\t} else if (char === \"'\") return index === text.length - 1 ? body : void 0;\n\t\telse body += char;\n\t}\n}\n/**\n* The value of a default MySQL reports as a string with a character set introducer, such as `_utf8mb4\\'abc\\'`: the form a literal default on a text, blob or JSON column takes, because MySQL writes it as an expression. `undefined` for any other expression.\n*/\nfunction introducedStringValue(reported) {\n\tconst expression = withoutBackslashEscapes(reported.trim());\n\tconst opening = INTRODUCED_STRING.exec(expression);\n\treturn opening === null ? void 0 : stringLiteralBody(expression, opening[0].length);\n}\nfunction extraFlags(extra) {\n\treturn extra.toLowerCase().split(/\\s+/);\n}\n/**\n* Reads a column's reported default from `COLUMN_DEFAULT` and `EXTRA`. `auto_increment` is `autoincrement()`; a string with a character set introducer, the form MySQL reports for a literal default on a text, blob or JSON column, is that literal; an expression default that writes the current time, such as `CURRENT_TIMESTAMP(3)`, is `now()`; any other expression default is a function default kept as reported; and anything else is a literal. `undefined` when the column has no default.\n*/\nfunction readMysqlDefault(columnDefault, extra) {\n\tconst flags = extraFlags(extra);\n\tif (flags.includes(\"auto_increment\")) return AUTOINCREMENT;\n\tif (columnDefault === null) return void 0;\n\tif (flags.includes(\"default_generated\")) {\n\t\tconst introduced = introducedStringValue(columnDefault);\n\t\tif (introduced !== void 0) return {\n\t\t\tkind: \"literal\",\n\t\t\tliteral: {\n\t\t\t\tkind: \"value\",\n\t\t\t\tbody: introduced\n\t\t\t}\n\t\t};\n\t\tconst expression = columnDefault.trim();\n\t\treturn CURRENT_TIMESTAMP.test(expression) ? NOW : {\n\t\t\tkind: \"function\",\n\t\t\texpression\n\t\t};\n\t}\n\treturn {\n\t\tkind: \"literal\",\n\t\tliteral: {\n\t\t\tkind: \"value\",\n\t\t\tbody: columnDefault\n\t\t}\n\t};\n}\n/**\n* Names a contract's expression default the way {@link readMysqlDefault} names the same function in the database, so `` sql`CURRENT_TIMESTAMP(3)` `` and the database's `now()` compare equal. Every other default passes through unchanged.\n*/\nfunction mysqlResolveDefault(def, _column) {\n\tif (def.kind !== \"function\") return def;\n\treturn CURRENT_TIMESTAMP.test(def.expression.trim()) ? NOW : def;\n}\n//#endregion\nexport { readMysqlDefault as n, mysqlResolveDefault as t };\n\n//# sourceMappingURL=default-normalizer-BDUgHXUn.mjs.map"],"mappings":";AACA,MAAM,gBAAgB;CACr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aAAa;EACtD,IAAI,eAAe,KAAK,GAAG,OAAO;GACjC,MAAM;GACN,SAAS;IACR,MAAM;IACN,MAAM;GACP;EACD;EACA,MAAM,aAAa,cAAc,KAAK;EACtC,OAAO,kBAAkB,KAAK,UAAU,IAAI,MAAM;GACjD,MAAM;GACN;EACD;CACD;CACA,OAAO;EACN,MAAM;EACN,SAAS;GACR,MAAM;GACN,MAAM;EACP;CACD;AACD;;;;AAIA,SAAS,oBAAoB,KAAK,SAAS;CAC1C,IAAI,IAAI,SAAS,YAAY,OAAO;CACpC,OAAO,kBAAkB,KAAK,IAAI,WAAW,KAAK,CAAC,IAAI,MAAM;AAC9D"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { a as MYSQL_TEXT_CODEC_ID, i as MYSQL_INT_CODEC_ID, n as MYSQL_DATETIME_CODEC_ID, t as MYSQL_BIGINT_CODEC_ID } from "./codec-ids-cjxtOcLM-vFeQhgPm.mjs";
|
|
2
|
+
import { f as mysqlTextDataTypes, u as mysqlInt } from "./data-types-Dv9gwVRV-BZPzCWZk.mjs";
|
|
3
|
+
import { t as mysqlDataTypeEntries } from "./data-type-entries-B0AoBozh-f9AEUIUQ.mjs";
|
|
4
|
+
import { t as mysqlTargetDescriptorMetaRuntime } from "./descriptor-meta-runtime-Bk_00UrX-BLN4Ahpj.mjs";
|
|
5
|
+
import { SQL_VARCHAR_CODEC_ID } from "@prisma/orm-family-sql/relational-core/ast";
|
|
6
|
+
import { UNBOUND_NAMESPACE_ID } from "@prisma/orm-framework/components/ir";
|
|
7
|
+
import { idGeneratorFunctionBindings, sqlIntegerArgumentGeneratorFunctions, sqlTargetTypeConstructors } from "@prisma/orm-family-sql/family/pack";
|
|
8
|
+
import { TIMESTAMP_NOW_GENERATOR_ID } from "@prisma/orm-framework/components/authoring";
|
|
9
|
+
import { singleGeneratorBinding } from "@prisma/orm-framework/components/components";
|
|
10
|
+
//#region ../../../3-targets/mysql/1-target/dist/descriptor-meta-BurjcSiU.mjs
|
|
11
|
+
/** The type constructors whose arguments are sizes, which take values of `mysql/int`. */
|
|
12
|
+
const mysqlAuthoringTypes = { .../* @__PURE__ */ sqlTargetTypeConstructors({ sizeType: "mysql/int" }) };
|
|
13
|
+
const mysqlGeneratorFunctions = [
|
|
14
|
+
...sqlIntegerArgumentGeneratorFunctions({ integer: mysqlInt.id }),
|
|
15
|
+
{
|
|
16
|
+
name: "now",
|
|
17
|
+
bindings: [singleGeneratorBinding({
|
|
18
|
+
codecIds: [MYSQL_DATETIME_CODEC_ID],
|
|
19
|
+
generatorId: TIMESTAMP_NOW_GENERATOR_ID
|
|
20
|
+
})]
|
|
21
|
+
},
|
|
22
|
+
...idGeneratorFunctionBindings({ text: [MYSQL_TEXT_CODEC_ID] })
|
|
23
|
+
];
|
|
24
|
+
/** The `now` generator MySQL binds. The SQL family registers the identifier generators. */
|
|
25
|
+
const mysqlGeneratorDescriptors = [{ id: TIMESTAMP_NOW_GENERATOR_ID }];
|
|
26
|
+
/**
|
|
27
|
+
* The base PSL scalars as zero-arg type constructors. Each names a codec; the column's database type is its data type's. The target contributes them, so PSL and the TypeScript builder's `type.*` see the same names.
|
|
28
|
+
*/
|
|
29
|
+
const mysqlScalarTypeConstructors = {
|
|
30
|
+
String: {
|
|
31
|
+
kind: "typeConstructor",
|
|
32
|
+
documentation: `Text of at most 191 characters, stored as MySQL varchar(191) so that it can be indexed.`,
|
|
33
|
+
output: {
|
|
34
|
+
codecId: SQL_VARCHAR_CODEC_ID,
|
|
35
|
+
typeParams: { length: 191 }
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
Int: {
|
|
39
|
+
kind: "typeConstructor",
|
|
40
|
+
inferred: true,
|
|
41
|
+
documentation: "A signed 32-bit integer stored as MySQL int and represented as a JavaScript number.",
|
|
42
|
+
output: { codecId: MYSQL_INT_CODEC_ID }
|
|
43
|
+
},
|
|
44
|
+
BigInt: {
|
|
45
|
+
kind: "typeConstructor",
|
|
46
|
+
inferred: true,
|
|
47
|
+
documentation: "A signed 64-bit integer stored as MySQL bigint and represented as a JavaScript bigint.",
|
|
48
|
+
output: { codecId: MYSQL_BIGINT_CODEC_ID }
|
|
49
|
+
},
|
|
50
|
+
DateTime: {
|
|
51
|
+
kind: "typeConstructor",
|
|
52
|
+
inferred: true,
|
|
53
|
+
documentation: "A date and time with millisecond precision, stored as MySQL datetime(3) in UTC and represented as a JavaScript Date.",
|
|
54
|
+
output: {
|
|
55
|
+
codecId: MYSQL_DATETIME_CODEC_ID,
|
|
56
|
+
typeParams: { precision: 3 }
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const mysqlTargetDescriptorMeta = {
|
|
61
|
+
...mysqlTargetDescriptorMetaRuntime,
|
|
62
|
+
defaultNamespaceId: UNBOUND_NAMESPACE_ID,
|
|
63
|
+
supportsNamespaces: false,
|
|
64
|
+
displayName: "MySQL",
|
|
65
|
+
authoring: {
|
|
66
|
+
type: {
|
|
67
|
+
...mysqlScalarTypeConstructors,
|
|
68
|
+
...mysqlAuthoringTypes
|
|
69
|
+
},
|
|
70
|
+
dataTypes: mysqlDataTypeEntries(),
|
|
71
|
+
textDataTypes: mysqlTextDataTypes
|
|
72
|
+
},
|
|
73
|
+
generatorFunctions: mysqlGeneratorFunctions,
|
|
74
|
+
controlMutationDefaults: {
|
|
75
|
+
defaultFunctionRegistry: /* @__PURE__ */ new Map(),
|
|
76
|
+
generatorDescriptors: mysqlGeneratorDescriptors
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
//#endregion
|
|
80
|
+
export { mysqlTargetDescriptorMeta as t };
|
|
81
|
+
|
|
82
|
+
//# sourceMappingURL=descriptor-meta-BurjcSiU-Cbk2L1jf.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor-meta-BurjcSiU-Cbk2L1jf.mjs","names":[],"sources":["../../../../3-targets/mysql/1-target/dist/descriptor-meta-BurjcSiU.mjs"],"sourcesContent":["import { a as MYSQL_TEXT_CODEC_ID, i as MYSQL_INT_CODEC_ID, n as MYSQL_DATETIME_CODEC_ID, t as MYSQL_BIGINT_CODEC_ID } from \"./codec-ids-cjxtOcLM.mjs\";\nimport { f as mysqlTextDataTypes, u as mysqlInt } from \"./data-types-Dv9gwVRV.mjs\";\nimport { t as mysqlDataTypeEntries } from \"./data-type-entries-B0AoBozh.mjs\";\nimport { t as mysqlTargetDescriptorMetaRuntime } from \"./descriptor-meta-runtime-Bk_00UrX.mjs\";\nimport { SQL_VARCHAR_CODEC_ID } from \"@internal/sql-relational-core/ast\";\nimport { UNBOUND_NAMESPACE_ID } from \"@internal/framework-components/ir\";\nimport { idGeneratorFunctionBindings, sqlIntegerArgumentGeneratorFunctions, sqlTargetTypeConstructors } from \"@internal/family-sql/pack\";\nimport { TIMESTAMP_NOW_GENERATOR_ID } from \"@internal/framework-components/authoring\";\nimport { singleGeneratorBinding } from \"@internal/framework-components/components\";\n//#region src/core/authoring.ts\n/** The type constructors whose arguments are sizes, which take values of `mysql/int`. */\nconst mysqlAuthoringTypes = { .../* @__PURE__ */ sqlTargetTypeConstructors({ sizeType: \"mysql/int\" }) };\n//#endregion\n//#region src/core/generator-functions.ts\nconst mysqlGeneratorFunctions = [\n\t...sqlIntegerArgumentGeneratorFunctions({ integer: mysqlInt.id }),\n\t{\n\t\tname: \"now\",\n\t\tbindings: [singleGeneratorBinding({\n\t\t\tcodecIds: [MYSQL_DATETIME_CODEC_ID],\n\t\t\tgeneratorId: TIMESTAMP_NOW_GENERATOR_ID\n\t\t})]\n\t},\n\t...idGeneratorFunctionBindings({ text: [MYSQL_TEXT_CODEC_ID] })\n];\n/** The `now` generator MySQL binds. The SQL family registers the identifier generators. */\nconst mysqlGeneratorDescriptors = [{ id: TIMESTAMP_NOW_GENERATOR_ID }];\n/**\n* The base PSL scalars as zero-arg type constructors. Each names a codec; the column's database type is its data type's. The target contributes them, so PSL and the TypeScript builder's `type.*` see the same names.\n*/\nconst mysqlScalarTypeConstructors = {\n\tString: {\n\t\tkind: \"typeConstructor\",\n\t\tdocumentation: `Text of at most 191 characters, stored as MySQL varchar(191) so that it can be indexed.`,\n\t\toutput: {\n\t\t\tcodecId: SQL_VARCHAR_CODEC_ID,\n\t\t\ttypeParams: { length: 191 }\n\t\t}\n\t},\n\tInt: {\n\t\tkind: \"typeConstructor\",\n\t\tinferred: true,\n\t\tdocumentation: \"A signed 32-bit integer stored as MySQL int and represented as a JavaScript number.\",\n\t\toutput: { codecId: MYSQL_INT_CODEC_ID }\n\t},\n\tBigInt: {\n\t\tkind: \"typeConstructor\",\n\t\tinferred: true,\n\t\tdocumentation: \"A signed 64-bit integer stored as MySQL bigint and represented as a JavaScript bigint.\",\n\t\toutput: { codecId: MYSQL_BIGINT_CODEC_ID }\n\t},\n\tDateTime: {\n\t\tkind: \"typeConstructor\",\n\t\tinferred: true,\n\t\tdocumentation: \"A date and time with millisecond precision, stored as MySQL datetime(3) in UTC and represented as a JavaScript Date.\",\n\t\toutput: {\n\t\t\tcodecId: MYSQL_DATETIME_CODEC_ID,\n\t\t\ttypeParams: { precision: 3 }\n\t\t}\n\t}\n};\nconst mysqlTargetDescriptorMeta = {\n\t...mysqlTargetDescriptorMetaRuntime,\n\tdefaultNamespaceId: UNBOUND_NAMESPACE_ID,\n\tsupportsNamespaces: false,\n\tdisplayName: \"MySQL\",\n\tauthoring: {\n\t\ttype: {\n\t\t\t...mysqlScalarTypeConstructors,\n\t\t\t...mysqlAuthoringTypes\n\t\t},\n\t\tdataTypes: mysqlDataTypeEntries(),\n\t\ttextDataTypes: mysqlTextDataTypes\n\t},\n\tgeneratorFunctions: mysqlGeneratorFunctions,\n\tcontrolMutationDefaults: {\n\t\tdefaultFunctionRegistry: /* @__PURE__ */ new Map(),\n\t\tgeneratorDescriptors: mysqlGeneratorDescriptors\n\t}\n};\n//#endregion\nexport { mysqlTargetDescriptorMeta as t };\n\n//# sourceMappingURL=descriptor-meta-BurjcSiU.mjs.map"],"mappings":";;;;;;;;;;;AAWA,MAAM,sBAAsB,EAAE,GAAmB,0CAA0B,EAAE,UAAU,YAAY,CAAC,EAAE;AAGtG,MAAM,0BAA0B;CAC/B,GAAG,qCAAqC,EAAE,SAAS,SAAS,GAAG,CAAC;CAChE;EACC,MAAM;EACN,UAAU,CAAC,uBAAuB;GACjC,UAAU,CAAC,uBAAuB;GAClC,aAAa;EACd,CAAC,CAAC;CACH;CACA,GAAG,4BAA4B,EAAE,MAAM,CAAC,mBAAmB,EAAE,CAAC;AAC/D;;AAEA,MAAM,4BAA4B,CAAC,EAAE,IAAI,2BAA2B,CAAC;;;;AAIrE,MAAM,8BAA8B;CACnC,QAAQ;EACP,MAAM;EACN,eAAe;EACf,QAAQ;GACP,SAAS;GACT,YAAY,EAAE,QAAQ,IAAI;EAC3B;CACD;CACA,KAAK;EACJ,MAAM;EACN,UAAU;EACV,eAAe;EACf,QAAQ,EAAE,SAAS,mBAAmB;CACvC;CACA,QAAQ;EACP,MAAM;EACN,UAAU;EACV,eAAe;EACf,QAAQ,EAAE,SAAS,sBAAsB;CAC1C;CACA,UAAU;EACT,MAAM;EACN,UAAU;EACV,eAAe;EACf,QAAQ;GACP,SAAS;GACT,YAAY,EAAE,WAAW,EAAE;EAC5B;CACD;AACD;AACA,MAAM,4BAA4B;CACjC,GAAG;CACH,oBAAoB;CACpB,oBAAoB;CACpB,aAAa;CACb,WAAW;EACV,MAAM;GACL,GAAG;GACH,GAAG;EACJ;EACA,WAAW,qBAAqB;EAChC,eAAe;CAChB;CACA,oBAAoB;CACpB,yBAAyB;EACxB,yCAAyC,IAAI,IAAI;EACjD,sBAAsB;CACvB;AACD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { i as mysqlDataTypes } from "./data-types-Dv9gwVRV-BZPzCWZk.mjs";
|
|
2
|
+
//#region ../../../3-targets/mysql/1-target/dist/descriptor-meta-runtime-Bk_00UrX.mjs
|
|
3
|
+
/** The runtime-safe part of the MySQL target's metadata: it leaves out `authoring`, which only contract construction reads. Every session runs in UTC, because the datetime codec reads and writes UTC. */
|
|
4
|
+
const mysqlTargetDescriptorMetaRuntime = {
|
|
5
|
+
kind: "target",
|
|
6
|
+
familyId: "sql",
|
|
7
|
+
targetId: "mysql",
|
|
8
|
+
id: "mysql",
|
|
9
|
+
version: "0.0.1",
|
|
10
|
+
capabilities: {},
|
|
11
|
+
dataTypes: mysqlDataTypes,
|
|
12
|
+
sessionSettings: { time_zone: "+00:00" }
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { mysqlTargetDescriptorMetaRuntime as t };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=descriptor-meta-runtime-Bk_00UrX-BLN4Ahpj.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor-meta-runtime-Bk_00UrX-BLN4Ahpj.mjs","names":[],"sources":["../../../../3-targets/mysql/1-target/dist/descriptor-meta-runtime-Bk_00UrX.mjs"],"sourcesContent":["import { i as mysqlDataTypes } from \"./data-types-Dv9gwVRV.mjs\";\n/** The runtime-safe part of the MySQL target's metadata: it leaves out `authoring`, which only contract construction reads. Every session runs in UTC, because the datetime codec reads and writes UTC. */\nconst mysqlTargetDescriptorMetaRuntime = {\n\tkind: \"target\",\n\tfamilyId: \"sql\",\n\ttargetId: \"mysql\",\n\tid: \"mysql\",\n\tversion: \"0.0.1\",\n\tcapabilities: {},\n\tdataTypes: mysqlDataTypes,\n\tsessionSettings: { time_zone: \"+00:00\" }\n};\n//#endregion\nexport { mysqlTargetDescriptorMetaRuntime as t };\n\n//# sourceMappingURL=descriptor-meta-runtime-Bk_00UrX.mjs.map"],"mappings":";;;AAEA,MAAM,mCAAmC;CACxC,MAAM;CACN,UAAU;CACV,UAAU;CACV,IAAI;CACJ,SAAS;CACT,cAAc,CAAC;CACf,WAAW;CACX,iBAAiB,EAAE,WAAW,SAAS;AACxC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { t as MysqlControlDriver } from "./control-DHkZbo58.mjs";
|
|
2
|
+
import { i as MysqlRuntimeDriver, n as MysqlDriverCreateOptions, r as MysqlPoolOptions, t as MysqlBinding } from "./runtime-BGyTXcQH.mjs";
|
|
3
|
+
export { type MysqlBinding, MysqlControlDriver, type MysqlDriverCreateOptions, type MysqlPoolOptions, type MysqlRuntimeDriver };
|
package/dist/driver.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as mysqlRuntimeDriverDescriptor, i as MysqlRuntimeDriver, n as MysqlDriverCreateOptions, r as MysqlPoolOptions, t as MysqlBinding } from "./runtime-BGyTXcQH.mjs";
|
|
2
|
+
export { type MysqlBinding, type MysqlDriverCreateOptions, type MysqlPoolOptions, type MysqlRuntimeDriver, mysqlRuntimeDriverDescriptor as default };
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { d as normalizeMysqlError, i as connectingCannotSucceed, l as mysqlDriverDescriptorMeta, n as acquireClientQueryLock, p as statementFor, s as isFatal, t as SessionSettingsGuard, u as mysqlPoolOptions } from "./statement-A6bbPBf1-q61iHQLb.mjs";
|
|
2
|
+
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
3
|
+
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
4
|
+
import { errorRuntime } from "@prisma/orm-framework/errors/execution";
|
|
5
|
+
import { createPool } from "mariadb";
|
|
6
|
+
import { EventEmitter } from "node:events";
|
|
7
|
+
import { finished } from "node:stream/promises";
|
|
8
|
+
//#region ../../../3-targets/mysql/3-driver/dist/runtime.mjs
|
|
9
|
+
function notConnected(message) {
|
|
10
|
+
return errorRuntime("DRIVER.NOT_CONNECTED", message, { fix: "Call connect(binding) before running queries, and do not use the driver after close()." });
|
|
11
|
+
}
|
|
12
|
+
/** Runs `request` on `client` in one round trip and returns its result: its `?N` placeholders written as `?`, and its values handed to the package, which writes them into the statement. Throws the package's error as it is. */
|
|
13
|
+
async function run(client, request) {
|
|
14
|
+
const { sql, values } = statementFor(client, request.sql, request.params ?? []);
|
|
15
|
+
return client.query(sql, values);
|
|
16
|
+
}
|
|
17
|
+
/** Starts streaming the rows of `request` on `client`, sent as {@link run} sends it. Throws the error to report, after noting in `outcome` whether it left the client unusable. */
|
|
18
|
+
function startStream(client, request, outcome) {
|
|
19
|
+
try {
|
|
20
|
+
const { sql, values } = statementFor(client, request.sql, request.params ?? []);
|
|
21
|
+
return client.queryStream(sql, values);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
throw settle(error, outcome);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function affectedRows(result) {
|
|
27
|
+
return typeof result === "object" && result !== null && "affectedRows" in result && typeof result.affectedRows === "number" ? result.affectedRows : 0;
|
|
28
|
+
}
|
|
29
|
+
/** The error to report for `error`, after noting in `outcome` whether it left the client unusable. */
|
|
30
|
+
function settle(error, outcome) {
|
|
31
|
+
if (isFatal(error)) outcome.destroy = true;
|
|
32
|
+
return normalizeMysqlError(error);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Whether the package has received the end of the result, so that any rows the caller has not read are already in the stream's buffer. The package pushes the end of the stream when MySQL's last packet arrives; Node records that in `_readableState.ended`, and its public API reports the end only after the caller has read every row.
|
|
36
|
+
*/
|
|
37
|
+
function resultReceived(rows) {
|
|
38
|
+
const state = Reflect.get(rows, "_readableState");
|
|
39
|
+
return typeof state === "object" && state !== null && "ended" in state && state.ended === true;
|
|
40
|
+
}
|
|
41
|
+
async function dropRest(rows) {
|
|
42
|
+
rows.close?.();
|
|
43
|
+
rows.resume();
|
|
44
|
+
await finished(rows);
|
|
45
|
+
}
|
|
46
|
+
/** The package can report an error on a stream after the caller stopped reading it, such as the one for a connection destroyed mid-result; the generator has already settled by then. */
|
|
47
|
+
function ignoreAfterStop() {}
|
|
48
|
+
var MysqlQueryable = class {
|
|
49
|
+
streams;
|
|
50
|
+
constructor(streams) {
|
|
51
|
+
this.streams = streams;
|
|
52
|
+
}
|
|
53
|
+
async *query(request) {
|
|
54
|
+
if (this.streams) {
|
|
55
|
+
yield* this.#streamRows(request);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const result = await this.#runReleasing(request);
|
|
59
|
+
for (const row of Array.isArray(result) ? result : []) yield blindCast(row);
|
|
60
|
+
}
|
|
61
|
+
async execute(request) {
|
|
62
|
+
return { affectedRows: affectedRows(await this.#runReleasing(request)) };
|
|
63
|
+
}
|
|
64
|
+
async #runReleasing(request) {
|
|
65
|
+
const client = await this.acquireClient();
|
|
66
|
+
const outcome = { destroy: false };
|
|
67
|
+
try {
|
|
68
|
+
const releaseLock = await acquireClientQueryLock(client);
|
|
69
|
+
try {
|
|
70
|
+
return await run(client, request);
|
|
71
|
+
} finally {
|
|
72
|
+
releaseLock();
|
|
73
|
+
}
|
|
74
|
+
} catch (error) {
|
|
75
|
+
throw settle(error, outcome);
|
|
76
|
+
} finally {
|
|
77
|
+
await this.releaseClient(client, outcome);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Streams the rows of `request` as they arrive; the package pauses the socket while the caller is busy. A caller that stops reading early is handled by {@link MysqlQueryable.#stopEarly}. A fatal error, such as a lost connection, destroys the client.
|
|
82
|
+
*/
|
|
83
|
+
async *#streamRows(request) {
|
|
84
|
+
const client = await this.acquireClient();
|
|
85
|
+
const outcome = { destroy: false };
|
|
86
|
+
const releaseLock = await acquireClientQueryLock(client);
|
|
87
|
+
try {
|
|
88
|
+
const rows = startStream(client, request, outcome);
|
|
89
|
+
rows.on("error", ignoreAfterStop);
|
|
90
|
+
let settled = false;
|
|
91
|
+
try {
|
|
92
|
+
for await (const row of rows.iterator({ destroyOnReturn: false })) yield blindCast(row);
|
|
93
|
+
settled = true;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
settled = true;
|
|
96
|
+
throw settle(error, outcome);
|
|
97
|
+
} finally {
|
|
98
|
+
if (!settled) await this.#stopEarly(rows, outcome);
|
|
99
|
+
if (outcome.destroy) rows.destroy();
|
|
100
|
+
}
|
|
101
|
+
} finally {
|
|
102
|
+
releaseLock();
|
|
103
|
+
await this.releaseClient(client, outcome);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Ends a stream the caller stopped reading early. Once the whole result has arrived, or on a held client whose session must survive, the rest is read and dropped and the client stays usable. A pooled client whose result is still arriving is destroyed instead, so a large result is not downloaded only to be thrown away; MySQL does not say how many rows remain. Destroying it mid-result makes the package open one short-lived extra connection to send `KILL`, because MySQL cannot cancel a statement on its own connection.
|
|
108
|
+
*/
|
|
109
|
+
async #stopEarly(rows, outcome) {
|
|
110
|
+
if (!this.holdsClient && !resultReceived(rows)) {
|
|
111
|
+
outcome.destroy = true;
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
await dropRest(rows).catch((error) => {
|
|
115
|
+
if (isFatal(error)) outcome.destroy = true;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* A queryable on a connection the caller holds, whose statements all run on the same session, in the order they are sent, under the client's lock. A statement sent while a stream on the connection is open waits for that stream to end; one awaited inside the stream's own loop never finishes, as on Postgres with a cursor.
|
|
121
|
+
*/
|
|
122
|
+
var MysqlHeldQueryable = class extends MysqlQueryable {
|
|
123
|
+
client;
|
|
124
|
+
held;
|
|
125
|
+
holdsClient = true;
|
|
126
|
+
constructor(client, held, streams) {
|
|
127
|
+
super(streams);
|
|
128
|
+
this.client = client;
|
|
129
|
+
this.held = held;
|
|
130
|
+
}
|
|
131
|
+
async acquireClient() {
|
|
132
|
+
this.held.running += 1;
|
|
133
|
+
return this.client;
|
|
134
|
+
}
|
|
135
|
+
async releaseClient() {
|
|
136
|
+
this.held.running -= 1;
|
|
137
|
+
}
|
|
138
|
+
/** Runs one of the package's transaction calls under the client's lock, taken as a statement takes it, so it keeps its place among the statements sent. */
|
|
139
|
+
async underLock(call) {
|
|
140
|
+
const client = await this.acquireClient();
|
|
141
|
+
try {
|
|
142
|
+
const releaseLock = await acquireClientQueryLock(client);
|
|
143
|
+
try {
|
|
144
|
+
await call();
|
|
145
|
+
} finally {
|
|
146
|
+
releaseLock();
|
|
147
|
+
}
|
|
148
|
+
} catch (error) {
|
|
149
|
+
throw normalizeMysqlError(error);
|
|
150
|
+
} finally {
|
|
151
|
+
await this.releaseClient();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
var MysqlConnectionImpl = class extends MysqlHeldQueryable {
|
|
156
|
+
#onRelease;
|
|
157
|
+
constructor(client, streams, onRelease) {
|
|
158
|
+
super(client, { running: 0 }, streams);
|
|
159
|
+
this.#onRelease = onRelease;
|
|
160
|
+
}
|
|
161
|
+
#released() {
|
|
162
|
+
const onRelease = this.#onRelease;
|
|
163
|
+
this.#onRelease = void 0;
|
|
164
|
+
onRelease?.();
|
|
165
|
+
}
|
|
166
|
+
async beginTransaction() {
|
|
167
|
+
await this.underLock(() => this.client.beginTransaction());
|
|
168
|
+
return new MysqlTransactionImpl(this.client, this.held, this.streams);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Returns the connection to the pool, as the Postgres driver's `release()` does. A connection with a statement still running, such as a stream the caller dropped, is destroyed instead: the package's release sends `ROLLBACK` behind that statement and waits for it, which would never finish, where `pg`'s release does not wait on the server.
|
|
172
|
+
*/
|
|
173
|
+
async release() {
|
|
174
|
+
if (this.held.running > 0) return this.destroy();
|
|
175
|
+
try {
|
|
176
|
+
await this.client.release();
|
|
177
|
+
} finally {
|
|
178
|
+
this.#released();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
async destroy(_reason) {
|
|
182
|
+
this.client.destroy();
|
|
183
|
+
this.#released();
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
var MysqlTransactionImpl = class extends MysqlHeldQueryable {
|
|
187
|
+
async commit() {
|
|
188
|
+
await this.underLock(() => this.client.commit());
|
|
189
|
+
}
|
|
190
|
+
async rollback() {
|
|
191
|
+
await this.underLock(() => this.client.rollback());
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
/** How many clients the driver has handed out and not had back, a held connection or one lent to a single statement, so `close()` can wait until every one is back. */
|
|
195
|
+
var ClientsInUse = class {
|
|
196
|
+
#count = 0;
|
|
197
|
+
#idle = [];
|
|
198
|
+
acquired() {
|
|
199
|
+
this.#count += 1;
|
|
200
|
+
}
|
|
201
|
+
released() {
|
|
202
|
+
this.#count -= 1;
|
|
203
|
+
if (this.#count === 0) for (const resolve of this.#idle.splice(0)) resolve();
|
|
204
|
+
}
|
|
205
|
+
none() {
|
|
206
|
+
return this.#count === 0 ? Promise.resolve() : new Promise((resolve) => this.#idle.push(resolve));
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
/** The pool reports a connection it failed to open on its `'error'` event, and again as the cause of a `getConnection` that times out; the driver reports it there. */
|
|
210
|
+
function ignoreConnectionFailure() {}
|
|
211
|
+
/**
|
|
212
|
+
* The statements waiting for a connection from the pool. The pool keeps retrying a connection it cannot open, with a growing pause between attempts, and fails a waiting `getConnection` only when `connectionTimeoutMillis` ends; the package reports each failure to its `logger.error` as it happens, together with every failed statement. `pg.Pool` instead rejects a pending connect whose connection fails, at once. So the driver fails the waiting statements at once with a failure no retry can get past. It keeps no failure: a later statement waits for the pool's next attempt.
|
|
213
|
+
*/
|
|
214
|
+
var WaitingForConnection = class {
|
|
215
|
+
#fail = /* @__PURE__ */ new Set();
|
|
216
|
+
async race(getting) {
|
|
217
|
+
let fail = () => {};
|
|
218
|
+
const failed = new Promise((_, reject) => {
|
|
219
|
+
fail = reject;
|
|
220
|
+
});
|
|
221
|
+
this.#fail.add(fail);
|
|
222
|
+
try {
|
|
223
|
+
return await Promise.race([getting, failed]);
|
|
224
|
+
} finally {
|
|
225
|
+
this.#fail.delete(fail);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/** Reacts to an error the package reports: only a failure to connect, which the package marks fatal, that no retry can get past. A statement can fail with the same error number, such as 1524 for a missing authentication plugin, but not fatally. */
|
|
229
|
+
reported(error) {
|
|
230
|
+
if (!isFatal(error) || !connectingCannotSucceed(error)) return;
|
|
231
|
+
for (const fail of this.#fail) fail(error);
|
|
232
|
+
this.#fail.clear();
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
/** Gives a connection the pool hands over after its statement stopped waiting back to the pool. */
|
|
236
|
+
function releaseLate(getting) {
|
|
237
|
+
getting.then((late) => late.release(), ignoreConnectionFailure).catch(ignoreConnectionFailure);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* The MySQL runtime driver: a `mariadb` pool. Every statement takes one round trip over the text protocol, the package writing its values into it. A query reads its whole result before the first row unless `stream` is set. The pool runs the session setup once on each physical connection, and the driver then sets the target's session settings on it; a connection goes back to the pool after each statement as it is; a broken connection is destroyed. `close()` waits for every connection and stream it has handed out before it ends the pool.
|
|
241
|
+
*/
|
|
242
|
+
var MysqlDriver = class extends MysqlQueryable {
|
|
243
|
+
familyId = "sql";
|
|
244
|
+
targetId = "mysql";
|
|
245
|
+
holdsClient = false;
|
|
246
|
+
#state = { kind: "unbound" };
|
|
247
|
+
#inUse = new ClientsInUse();
|
|
248
|
+
#options;
|
|
249
|
+
#sessionSettings;
|
|
250
|
+
constructor(options = {}) {
|
|
251
|
+
super(options.stream ?? false);
|
|
252
|
+
this.#options = options;
|
|
253
|
+
this.#sessionSettings = new SessionSettingsGuard(options.sessionSettings ?? {});
|
|
254
|
+
}
|
|
255
|
+
get state() {
|
|
256
|
+
return this.#state.kind;
|
|
257
|
+
}
|
|
258
|
+
async connect(binding) {
|
|
259
|
+
if (this.#state.kind === "connected") throw errorRuntime("DRIVER.ALREADY_CONNECTED", "MySQL driver already connected", { fix: "Call close() before connecting again." });
|
|
260
|
+
const waiting = new WaitingForConnection();
|
|
261
|
+
const pool = createPool({
|
|
262
|
+
...mysqlPoolOptions(binding.url, this.#options.poolOptions),
|
|
263
|
+
logger: { error: (error) => waiting.reported(error) }
|
|
264
|
+
});
|
|
265
|
+
if (pool instanceof EventEmitter) pool.on("error", ignoreConnectionFailure);
|
|
266
|
+
this.#state = {
|
|
267
|
+
kind: "connected",
|
|
268
|
+
pool,
|
|
269
|
+
waiting
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
async acquireConnection() {
|
|
273
|
+
return new MysqlConnectionImpl(await this.acquireClient(), this.streams, () => this.#inUse.released());
|
|
274
|
+
}
|
|
275
|
+
async close() {
|
|
276
|
+
if (this.#state.kind !== "connected") return;
|
|
277
|
+
const { pool } = this.#state;
|
|
278
|
+
this.#state = { kind: "closed" };
|
|
279
|
+
await this.#inUse.none();
|
|
280
|
+
await pool.end();
|
|
281
|
+
}
|
|
282
|
+
async acquireClient() {
|
|
283
|
+
if (this.#state.kind !== "connected") throw notConnected(this.#state.kind === "closed" ? "MySQL driver is closed" : "MySQL driver not connected");
|
|
284
|
+
const { pool, waiting } = this.#state;
|
|
285
|
+
this.#inUse.acquired();
|
|
286
|
+
const getting = pool.getConnection();
|
|
287
|
+
let client;
|
|
288
|
+
try {
|
|
289
|
+
client = await waiting.race(getting);
|
|
290
|
+
} catch (error) {
|
|
291
|
+
releaseLate(getting);
|
|
292
|
+
this.#inUse.released();
|
|
293
|
+
throw normalizeMysqlError(error);
|
|
294
|
+
}
|
|
295
|
+
try {
|
|
296
|
+
await this.#sessionSettings.ensure(client);
|
|
297
|
+
} catch (error) {
|
|
298
|
+
client.destroy();
|
|
299
|
+
this.#inUse.released();
|
|
300
|
+
throw normalizeMysqlError(error);
|
|
301
|
+
}
|
|
302
|
+
return client;
|
|
303
|
+
}
|
|
304
|
+
async releaseClient(client, { destroy }) {
|
|
305
|
+
try {
|
|
306
|
+
if (destroy) client.destroy();
|
|
307
|
+
else await client.release();
|
|
308
|
+
} finally {
|
|
309
|
+
this.#inUse.released();
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
const mysqlRuntimeDriverDescriptor = {
|
|
314
|
+
...mysqlDriverDescriptorMeta,
|
|
315
|
+
create(options, sessionSettings) {
|
|
316
|
+
return new MysqlDriver({
|
|
317
|
+
...options,
|
|
318
|
+
...ifDefined("sessionSettings", sessionSettings)
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
//#endregion
|
|
323
|
+
export { mysqlRuntimeDriverDescriptor as default };
|
|
324
|
+
|
|
325
|
+
//# sourceMappingURL=driver__runtime.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver__runtime.mjs","names":["#streamRows","#runReleasing","#stopEarly","#onRelease","#released","#count","#idle","#fail","#options","#sessionSettings","#state","#inUse"],"sources":["../../../../3-targets/mysql/3-driver/dist/runtime.mjs"],"sourcesContent":["import { a as connectingCannotSucceed, c as isFatal, f as mysqlPoolOptions, l as normalizeMysqlError, n as SessionSettingsGuard, p as acquireClientQueryLock, t as statementFor, u as mysqlDriverDescriptorMeta } from \"./statement-A6bbPBf1.mjs\";\nimport { errorRuntime } from \"@internal/errors/execution\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { createPool } from \"mariadb\";\nimport { ifDefined } from \"@internal/utils/defined\";\nimport { EventEmitter } from \"node:events\";\nimport { finished } from \"node:stream/promises\";\n//#region src/core/runtime/mysql-driver.ts\nfunction notConnected(message) {\n\treturn errorRuntime(\"DRIVER.NOT_CONNECTED\", message, { fix: \"Call connect(binding) before running queries, and do not use the driver after close().\" });\n}\n/** Runs `request` on `client` in one round trip and returns its result: its `?N` placeholders written as `?`, and its values handed to the package, which writes them into the statement. Throws the package's error as it is. */\nasync function run(client, request) {\n\tconst { sql, values } = statementFor(client, request.sql, request.params ?? []);\n\treturn client.query(sql, values);\n}\n/** Starts streaming the rows of `request` on `client`, sent as {@link run} sends it. Throws the error to report, after noting in `outcome` whether it left the client unusable. */\nfunction startStream(client, request, outcome) {\n\ttry {\n\t\tconst { sql, values } = statementFor(client, request.sql, request.params ?? []);\n\t\treturn client.queryStream(sql, values);\n\t} catch (error) {\n\t\tthrow settle(error, outcome);\n\t}\n}\nfunction affectedRows(result) {\n\treturn typeof result === \"object\" && result !== null && \"affectedRows\" in result && typeof result.affectedRows === \"number\" ? result.affectedRows : 0;\n}\n/** The error to report for `error`, after noting in `outcome` whether it left the client unusable. */\nfunction settle(error, outcome) {\n\tif (isFatal(error)) outcome.destroy = true;\n\treturn normalizeMysqlError(error);\n}\n/**\n* Whether the package has received the end of the result, so that any rows the caller has not read are already in the stream's buffer. The package pushes the end of the stream when MySQL's last packet arrives; Node records that in `_readableState.ended`, and its public API reports the end only after the caller has read every row.\n*/\nfunction resultReceived(rows) {\n\tconst state = Reflect.get(rows, \"_readableState\");\n\treturn typeof state === \"object\" && state !== null && \"ended\" in state && state.ended === true;\n}\nasync function dropRest(rows) {\n\trows.close?.();\n\trows.resume();\n\tawait finished(rows);\n}\n/** The package can report an error on a stream after the caller stopped reading it, such as the one for a connection destroyed mid-result; the generator has already settled by then. */\nfunction ignoreAfterStop() {}\nvar MysqlQueryable = class {\n\tstreams;\n\tconstructor(streams) {\n\t\tthis.streams = streams;\n\t}\n\tasync *query(request) {\n\t\tif (this.streams) {\n\t\t\tyield* this.#streamRows(request);\n\t\t\treturn;\n\t\t}\n\t\tconst result = await this.#runReleasing(request);\n\t\tfor (const row of Array.isArray(result) ? result : []) yield blindCast(row);\n\t}\n\tasync execute(request) {\n\t\treturn { affectedRows: affectedRows(await this.#runReleasing(request)) };\n\t}\n\tasync #runReleasing(request) {\n\t\tconst client = await this.acquireClient();\n\t\tconst outcome = { destroy: false };\n\t\ttry {\n\t\t\tconst releaseLock = await acquireClientQueryLock(client);\n\t\t\ttry {\n\t\t\t\treturn await run(client, request);\n\t\t\t} finally {\n\t\t\t\treleaseLock();\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthrow settle(error, outcome);\n\t\t} finally {\n\t\t\tawait this.releaseClient(client, outcome);\n\t\t}\n\t}\n\t/**\n\t* Streams the rows of `request` as they arrive; the package pauses the socket while the caller is busy. A caller that stops reading early is handled by {@link MysqlQueryable.#stopEarly}. A fatal error, such as a lost connection, destroys the client.\n\t*/\n\tasync *#streamRows(request) {\n\t\tconst client = await this.acquireClient();\n\t\tconst outcome = { destroy: false };\n\t\tconst releaseLock = await acquireClientQueryLock(client);\n\t\ttry {\n\t\t\tconst rows = startStream(client, request, outcome);\n\t\t\trows.on(\"error\", ignoreAfterStop);\n\t\t\tlet settled = false;\n\t\t\ttry {\n\t\t\t\tfor await (const row of rows.iterator({ destroyOnReturn: false })) yield blindCast(row);\n\t\t\t\tsettled = true;\n\t\t\t} catch (error) {\n\t\t\t\tsettled = true;\n\t\t\t\tthrow settle(error, outcome);\n\t\t\t} finally {\n\t\t\t\tif (!settled) await this.#stopEarly(rows, outcome);\n\t\t\t\tif (outcome.destroy) rows.destroy();\n\t\t\t}\n\t\t} finally {\n\t\t\treleaseLock();\n\t\t\tawait this.releaseClient(client, outcome);\n\t\t}\n\t}\n\t/**\n\t* Ends a stream the caller stopped reading early. Once the whole result has arrived, or on a held client whose session must survive, the rest is read and dropped and the client stays usable. A pooled client whose result is still arriving is destroyed instead, so a large result is not downloaded only to be thrown away; MySQL does not say how many rows remain. Destroying it mid-result makes the package open one short-lived extra connection to send `KILL`, because MySQL cannot cancel a statement on its own connection.\n\t*/\n\tasync #stopEarly(rows, outcome) {\n\t\tif (!this.holdsClient && !resultReceived(rows)) {\n\t\t\toutcome.destroy = true;\n\t\t\treturn;\n\t\t}\n\t\tawait dropRest(rows).catch((error) => {\n\t\t\tif (isFatal(error)) outcome.destroy = true;\n\t\t});\n\t}\n};\n/**\n* A queryable on a connection the caller holds, whose statements all run on the same session, in the order they are sent, under the client's lock. A statement sent while a stream on the connection is open waits for that stream to end; one awaited inside the stream's own loop never finishes, as on Postgres with a cursor.\n*/\nvar MysqlHeldQueryable = class extends MysqlQueryable {\n\tclient;\n\theld;\n\tholdsClient = true;\n\tconstructor(client, held, streams) {\n\t\tsuper(streams);\n\t\tthis.client = client;\n\t\tthis.held = held;\n\t}\n\tasync acquireClient() {\n\t\tthis.held.running += 1;\n\t\treturn this.client;\n\t}\n\tasync releaseClient() {\n\t\tthis.held.running -= 1;\n\t}\n\t/** Runs one of the package's transaction calls under the client's lock, taken as a statement takes it, so it keeps its place among the statements sent. */\n\tasync underLock(call) {\n\t\tconst client = await this.acquireClient();\n\t\ttry {\n\t\t\tconst releaseLock = await acquireClientQueryLock(client);\n\t\t\ttry {\n\t\t\t\tawait call();\n\t\t\t} finally {\n\t\t\t\treleaseLock();\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthrow normalizeMysqlError(error);\n\t\t} finally {\n\t\t\tawait this.releaseClient();\n\t\t}\n\t}\n};\nvar MysqlConnectionImpl = class extends MysqlHeldQueryable {\n\t#onRelease;\n\tconstructor(client, streams, onRelease) {\n\t\tsuper(client, { running: 0 }, streams);\n\t\tthis.#onRelease = onRelease;\n\t}\n\t#released() {\n\t\tconst onRelease = this.#onRelease;\n\t\tthis.#onRelease = void 0;\n\t\tonRelease?.();\n\t}\n\tasync beginTransaction() {\n\t\tawait this.underLock(() => this.client.beginTransaction());\n\t\treturn new MysqlTransactionImpl(this.client, this.held, this.streams);\n\t}\n\t/**\n\t* Returns the connection to the pool, as the Postgres driver's `release()` does. A connection with a statement still running, such as a stream the caller dropped, is destroyed instead: the package's release sends `ROLLBACK` behind that statement and waits for it, which would never finish, where `pg`'s release does not wait on the server.\n\t*/\n\tasync release() {\n\t\tif (this.held.running > 0) return this.destroy();\n\t\ttry {\n\t\t\tawait this.client.release();\n\t\t} finally {\n\t\t\tthis.#released();\n\t\t}\n\t}\n\tasync destroy(_reason) {\n\t\tthis.client.destroy();\n\t\tthis.#released();\n\t}\n};\nvar MysqlTransactionImpl = class extends MysqlHeldQueryable {\n\tasync commit() {\n\t\tawait this.underLock(() => this.client.commit());\n\t}\n\tasync rollback() {\n\t\tawait this.underLock(() => this.client.rollback());\n\t}\n};\n/** How many clients the driver has handed out and not had back, a held connection or one lent to a single statement, so `close()` can wait until every one is back. */\nvar ClientsInUse = class {\n\t#count = 0;\n\t#idle = [];\n\tacquired() {\n\t\tthis.#count += 1;\n\t}\n\treleased() {\n\t\tthis.#count -= 1;\n\t\tif (this.#count === 0) for (const resolve of this.#idle.splice(0)) resolve();\n\t}\n\tnone() {\n\t\treturn this.#count === 0 ? Promise.resolve() : new Promise((resolve) => this.#idle.push(resolve));\n\t}\n};\n/** The pool reports a connection it failed to open on its `'error'` event, and again as the cause of a `getConnection` that times out; the driver reports it there. */\nfunction ignoreConnectionFailure() {}\n/**\n* The statements waiting for a connection from the pool. The pool keeps retrying a connection it cannot open, with a growing pause between attempts, and fails a waiting `getConnection` only when `connectionTimeoutMillis` ends; the package reports each failure to its `logger.error` as it happens, together with every failed statement. `pg.Pool` instead rejects a pending connect whose connection fails, at once. So the driver fails the waiting statements at once with a failure no retry can get past. It keeps no failure: a later statement waits for the pool's next attempt.\n*/\nvar WaitingForConnection = class {\n\t#fail = /* @__PURE__ */ new Set();\n\tasync race(getting) {\n\t\tlet fail = () => {};\n\t\tconst failed = new Promise((_, reject) => {\n\t\t\tfail = reject;\n\t\t});\n\t\tthis.#fail.add(fail);\n\t\ttry {\n\t\t\treturn await Promise.race([getting, failed]);\n\t\t} finally {\n\t\t\tthis.#fail.delete(fail);\n\t\t}\n\t}\n\t/** Reacts to an error the package reports: only a failure to connect, which the package marks fatal, that no retry can get past. A statement can fail with the same error number, such as 1524 for a missing authentication plugin, but not fatally. */\n\treported(error) {\n\t\tif (!isFatal(error) || !connectingCannotSucceed(error)) return;\n\t\tfor (const fail of this.#fail) fail(error);\n\t\tthis.#fail.clear();\n\t}\n};\n/** Gives a connection the pool hands over after its statement stopped waiting back to the pool. */\nfunction releaseLate(getting) {\n\tgetting.then((late) => late.release(), ignoreConnectionFailure).catch(ignoreConnectionFailure);\n}\n/**\n* The MySQL runtime driver: a `mariadb` pool. Every statement takes one round trip over the text protocol, the package writing its values into it. A query reads its whole result before the first row unless `stream` is set. The pool runs the session setup once on each physical connection, and the driver then sets the target's session settings on it; a connection goes back to the pool after each statement as it is; a broken connection is destroyed. `close()` waits for every connection and stream it has handed out before it ends the pool.\n*/\nvar MysqlDriver = class extends MysqlQueryable {\n\tfamilyId = \"sql\";\n\ttargetId = \"mysql\";\n\tholdsClient = false;\n\t#state = { kind: \"unbound\" };\n\t#inUse = new ClientsInUse();\n\t#options;\n\t#sessionSettings;\n\tconstructor(options = {}) {\n\t\tsuper(options.stream ?? false);\n\t\tthis.#options = options;\n\t\tthis.#sessionSettings = new SessionSettingsGuard(options.sessionSettings ?? {});\n\t}\n\tget state() {\n\t\treturn this.#state.kind;\n\t}\n\tasync connect(binding) {\n\t\tif (this.#state.kind === \"connected\") throw errorRuntime(\"DRIVER.ALREADY_CONNECTED\", \"MySQL driver already connected\", { fix: \"Call close() before connecting again.\" });\n\t\tconst waiting = new WaitingForConnection();\n\t\tconst pool = createPool({\n\t\t\t...mysqlPoolOptions(binding.url, this.#options.poolOptions),\n\t\t\tlogger: { error: (error) => waiting.reported(error) }\n\t\t});\n\t\tif (pool instanceof EventEmitter) pool.on(\"error\", ignoreConnectionFailure);\n\t\tthis.#state = {\n\t\t\tkind: \"connected\",\n\t\t\tpool,\n\t\t\twaiting\n\t\t};\n\t}\n\tasync acquireConnection() {\n\t\treturn new MysqlConnectionImpl(await this.acquireClient(), this.streams, () => this.#inUse.released());\n\t}\n\tasync close() {\n\t\tif (this.#state.kind !== \"connected\") return;\n\t\tconst { pool } = this.#state;\n\t\tthis.#state = { kind: \"closed\" };\n\t\tawait this.#inUse.none();\n\t\tawait pool.end();\n\t}\n\tasync acquireClient() {\n\t\tif (this.#state.kind !== \"connected\") throw notConnected(this.#state.kind === \"closed\" ? \"MySQL driver is closed\" : \"MySQL driver not connected\");\n\t\tconst { pool, waiting } = this.#state;\n\t\tthis.#inUse.acquired();\n\t\tconst getting = pool.getConnection();\n\t\tlet client;\n\t\ttry {\n\t\t\tclient = await waiting.race(getting);\n\t\t} catch (error) {\n\t\t\treleaseLate(getting);\n\t\t\tthis.#inUse.released();\n\t\t\tthrow normalizeMysqlError(error);\n\t\t}\n\t\ttry {\n\t\t\tawait this.#sessionSettings.ensure(client);\n\t\t} catch (error) {\n\t\t\tclient.destroy();\n\t\t\tthis.#inUse.released();\n\t\t\tthrow normalizeMysqlError(error);\n\t\t}\n\t\treturn client;\n\t}\n\tasync releaseClient(client, { destroy }) {\n\t\ttry {\n\t\t\tif (destroy) client.destroy();\n\t\t\telse await client.release();\n\t\t} finally {\n\t\t\tthis.#inUse.released();\n\t\t}\n\t}\n};\n//#endregion\n//#region src/core/runtime/runtime-driver.ts\nconst mysqlRuntimeDriverDescriptor = {\n\t...mysqlDriverDescriptorMeta,\n\tcreate(options, sessionSettings) {\n\t\treturn new MysqlDriver({\n\t\t\t...options,\n\t\t\t...ifDefined(\"sessionSettings\", sessionSettings)\n\t\t});\n\t}\n};\n//#endregion\nexport { mysqlRuntimeDriverDescriptor as default };\n\n//# sourceMappingURL=runtime.mjs.map"],"mappings":";;;;;;;;AAQA,SAAS,aAAa,SAAS;CAC9B,OAAO,aAAa,wBAAwB,SAAS,EAAE,KAAK,yFAAyF,CAAC;AACvJ;;AAEA,eAAe,IAAI,QAAQ,SAAS;CACnC,MAAM,EAAE,KAAK,WAAW,aAAa,QAAQ,QAAQ,KAAK,QAAQ,UAAU,CAAC,CAAC;CAC9E,OAAO,OAAO,MAAM,KAAK,MAAM;AAChC;;AAEA,SAAS,YAAY,QAAQ,SAAS,SAAS;CAC9C,IAAI;EACH,MAAM,EAAE,KAAK,WAAW,aAAa,QAAQ,QAAQ,KAAK,QAAQ,UAAU,CAAC,CAAC;EAC9E,OAAO,OAAO,YAAY,KAAK,MAAM;CACtC,SAAS,OAAO;EACf,MAAM,OAAO,OAAO,OAAO;CAC5B;AACD;AACA,SAAS,aAAa,QAAQ;CAC7B,OAAO,OAAO,WAAW,YAAY,WAAW,QAAQ,kBAAkB,UAAU,OAAO,OAAO,iBAAiB,WAAW,OAAO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-error";
|
|
2
|
+
//#region ../../../3-targets/mysql/1-target/dist/errors.d.mts
|
|
3
|
+
//#region src/core/errors.d.ts
|
|
4
|
+
type MysqlTargetErrorCode = 'CONTRACT.ARGUMENT_INVALID' | 'CONTRACT.CONSTRAINT_INVALID' | 'CONTRACT.IDENTIFIER_INVALID' | 'CONTRACT.NAMESPACE_INVALID' | 'CONTRACT.TARGET_MISMATCH' | 'CONTRACT.TYPE_PARAMS_INVALID' | 'MIGRATION.CONTRACT_SPACE_VIOLATION' | 'MIGRATION.MARKER_LOCK_TIMEOUT' | 'MIGRATION.MYSQL_CONTROL_STACK_MISSING' | 'RUNTIME.AST_INVALID' | 'RUNTIME.AST_UNSUPPORTED' | 'RUNTIME.CHARACTER_SET_UNSUPPORTED' | 'RUNTIME.DECODE_FAILED' | 'RUNTIME.ENCODE_FAILED' | 'RUNTIME.SQL_MODE_UNSUPPORTED';
|
|
5
|
+
declare function mysqlError(code: MysqlTargetErrorCode, message: string, options?: StructuredErrorOptions): StructuredError;
|
|
6
|
+
/** The refusal of a query a later slice of the MySQL target can render: `what` names the feature, as in `Lowering queries`. */
|
|
7
|
+
declare function mysqlQueryNotYetSupported(what: string): StructuredError;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { mysqlQueryNotYetSupported as n, mysqlError as t };
|
|
10
|
+
//# sourceMappingURL=errors-BYhjQT7y.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors-BYhjQT7y.d.mts","names":[],"sources":["../../../../3-targets/mysql/1-target/dist/errors.d.mts"],"mappings":";;;KAEK;iBACY,WAAW,MAAM,sBAAsB,iBAAiB,UAAU,yBAAyB;;iBAE3F,0BAA0B,eAAe"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
2
|
+
//#region ../../../3-targets/mysql/1-target/dist/errors-rvH_F2Yj.mjs
|
|
3
|
+
function mysqlError(code, message, options) {
|
|
4
|
+
return structuredError(code, message, options);
|
|
5
|
+
}
|
|
6
|
+
/** The refusal of a query a later slice of the MySQL target can render: `what` names the feature, as in `Lowering queries`. */
|
|
7
|
+
function mysqlQueryNotYetSupported(what) {
|
|
8
|
+
return mysqlError("RUNTIME.AST_UNSUPPORTED", `${what} is not yet supported on MySQL.`, {
|
|
9
|
+
why: "The MySQL target renders reads; writes and some query forms are not built yet.",
|
|
10
|
+
fix: "Use a Postgres or SQLite target for this query until the MySQL target supports it.",
|
|
11
|
+
meta: {
|
|
12
|
+
target: "mysql",
|
|
13
|
+
feature: what
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { mysqlQueryNotYetSupported as n, mysqlError as t };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=errors-rvH_F2Yj-BQrO_--u.mjs.map
|