@prisma/orm-target-mysql 8.0.0-rc.24-dev.27 → 8.0.0-rc.24-dev.29
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/adapter-D4QpAe2i.d.mts +374 -0
- package/dist/adapter-D4QpAe2i.d.mts.map +1 -0
- package/dist/adapter.d.mts +8 -6
- package/dist/adapter.mjs +5 -3
- package/dist/adapter__adapter.d.mts +1 -1
- package/dist/adapter__adapter.mjs +1 -1
- package/dist/adapter__codec-types.d.mts +2 -2
- package/dist/adapter__control.d.mts +1 -1
- package/dist/adapter__control.mjs +1 -1
- package/dist/adapter__runtime.d.mts +2 -2
- package/dist/adapter__runtime.mjs +2 -501
- package/dist/adapter__sql-renderer.d.mts +3 -0
- package/dist/adapter__sql-renderer.mjs +2 -0
- package/dist/aggregates-BK8qyA2x.d.mts +164 -0
- package/dist/aggregates-BK8qyA2x.d.mts.map +1 -0
- package/dist/aggregates-Bk6CCgQ-.mjs +145 -0
- package/dist/aggregates-Bk6CCgQ-.mjs.map +1 -0
- package/dist/codec-descriptor-B1fMmxOK-D59zKJws.d.mts +1 -0
- package/dist/{codec-descriptor-3xp1XvVH-DfPKpYeP.mjs → codec-descriptor-ByN7iIha-48yW7oDN.mjs} +23 -16
- package/dist/codec-descriptor-ByN7iIha-48yW7oDN.mjs.map +1 -0
- package/dist/codec-descriptor-CqM_hQjY.d.mts +2 -0
- package/dist/{codec-descriptor-DXyubAS6-XDBj6Yet.d.mts → codec-descriptor-DXsJwUng-D4abEAFs.d.mts} +10 -5
- package/dist/codec-descriptor-DXsJwUng-D4abEAFs.d.mts.map +1 -0
- package/dist/codec-ids-DHeJ2SMJ-Uz1FAFmQ.d.mts +26 -0
- package/dist/codec-ids-DHeJ2SMJ-Uz1FAFmQ.d.mts.map +1 -0
- package/dist/codec-ids-DuWt4aOn-DiyLf9dW.mjs +26 -0
- package/dist/codec-ids-DuWt4aOn-DiyLf9dW.mjs.map +1 -0
- package/dist/codec-types-BQBBUlf_.d.mts +1 -0
- package/dist/{codec-types-Bai_CFkk-DmZ74URd.d.mts → codec-types-C4Q_JJgX-CUPkvPDx.d.mts} +11 -5
- package/dist/codec-types-C4Q_JJgX-CUPkvPDx.d.mts.map +1 -0
- package/dist/codec-types-DxSSgcpB.d.mts +1 -0
- package/dist/{codecs-BMidk26M-B_iWNti6.d.mts → codecs-D35fqdXJ-BZwilYUu.d.mts} +115 -7
- package/dist/codecs-D35fqdXJ-BZwilYUu.d.mts.map +1 -0
- package/dist/{codecs-CIJRyUd3.d.mts → codecs-DTfUoamS.d.mts} +3 -3
- package/dist/{codecs-CIJRyUd3.d.mts.map → codecs-DTfUoamS.d.mts.map} +1 -1
- package/dist/{codecs-wVJlFapM.mjs → codecs-DVX-3El1.mjs} +429 -12
- package/dist/codecs-DVX-3El1.mjs.map +1 -0
- package/dist/{control-Dj8nIA1M.d.mts → control-B7v7zc3l.d.mts} +272 -13
- package/dist/control-B7v7zc3l.d.mts.map +1 -0
- package/dist/{control-D7_IpeiU.d.mts → control-BFe8NrSk.d.mts} +22 -5
- package/dist/control-BFe8NrSk.d.mts.map +1 -0
- package/dist/{control-BiZaCqna.mjs → control-BTolgwH5.mjs} +28 -13
- package/dist/control-BTolgwH5.mjs.map +1 -0
- package/dist/{control-CTfV1Zag.mjs → control-CZSBblPm.mjs} +26 -19
- package/dist/control-CZSBblPm.mjs.map +1 -0
- package/dist/{control-WNuLF2Wh.d.mts → control-DqJJGh-5.d.mts} +3 -3
- package/dist/control-DqJJGh-5.d.mts.map +1 -0
- package/dist/{control-RYDTbndD.mjs → control-DtXS4WsY.mjs} +9 -14
- package/dist/control-DtXS4WsY.mjs.map +1 -0
- package/dist/data-type-entries-DlbQ1Bvl-BFkHeHVz.mjs +108 -0
- package/dist/data-type-entries-DlbQ1Bvl-BFkHeHVz.mjs.map +1 -0
- package/dist/{data-types-65iVc7q1.d.mts → data-types-COQT9bVG.d.mts} +2 -2
- package/dist/data-types-COQT9bVG.d.mts.map +1 -0
- package/dist/data-types-CU_43cNv-CQ8eHx3H.mjs +461 -0
- package/dist/data-types-CU_43cNv-CQ8eHx3H.mjs.map +1 -0
- package/dist/{data-types-D2HAT-Qf-CSdDz1Pk.d.mts → data-types-C_vInIbm-Gt1XINav.d.mts} +58 -4
- package/dist/data-types-C_vInIbm-Gt1XINav.d.mts.map +1 -0
- package/dist/{date-time-now-generators-BKakW3gd-CIFPuRdM.mjs → date-time-now-generators-Cx_aQTSw-ay1tlvw6.mjs} +4 -15
- package/dist/date-time-now-generators-Cx_aQTSw-ay1tlvw6.mjs.map +1 -0
- package/dist/default-normalizer-C9c043DP-DPhwJOC4.mjs +175 -0
- package/dist/default-normalizer-C9c043DP-DPhwJOC4.mjs.map +1 -0
- package/dist/default-normalizer-zXWtDBp_.d.mts +31 -0
- package/dist/default-normalizer-zXWtDBp_.d.mts.map +1 -0
- package/dist/{descriptor-meta-e29H69KN-t-S8_DYh.mjs → descriptor-meta-BFQUMwkh-Bc3o-ZMV.mjs} +19 -12
- package/dist/descriptor-meta-BFQUMwkh-Bc3o-ZMV.mjs.map +1 -0
- package/dist/{descriptor-meta-BF6YvSag-ChHHvlHc.mjs → descriptor-meta-BHSEcFWR-41BcRcOy.mjs} +219 -25
- package/dist/descriptor-meta-BHSEcFWR-41BcRcOy.mjs.map +1 -0
- package/dist/descriptor-meta-runtime-BaIF7fOE-BX9t3rkk.mjs +17 -0
- package/dist/descriptor-meta-runtime-BaIF7fOE-BX9t3rkk.mjs.map +1 -0
- package/dist/descriptor-meta-runtime-DEKunXiL.d.mts +22 -0
- package/dist/descriptor-meta-runtime-DEKunXiL.d.mts.map +1 -0
- package/dist/driver.d.mts +3 -3
- package/dist/driver.mjs +2 -2
- package/dist/driver__control.d.mts +2 -2
- package/dist/driver__control.mjs +1 -1
- package/dist/driver__runtime.d.mts +2 -2
- package/dist/driver__runtime.mjs +1 -1
- package/dist/{errors-DjCkC9IM.d.mts → errors-B81Qeu5_.d.mts} +3 -2
- package/dist/errors-B81Qeu5_.d.mts.map +1 -0
- package/dist/{errors-Cng94tYg-DTH51xWG.mjs → errors-CWtFTnst-xBLJ-9Lp.mjs} +43 -17
- package/dist/errors-CWtFTnst-xBLJ-9Lp.mjs.map +1 -0
- package/dist/{marker-lock-Bwew7cAs-ElLxlCQp.mjs → marker-lock-B7CyXf2F-CakjZnQP.mjs} +3 -3
- package/dist/{marker-lock-Bwew7cAs-ElLxlCQp.mjs.map → marker-lock-B7CyXf2F-CakjZnQP.mjs.map} +1 -1
- package/dist/{marker-read-D1hp62hF-3-4fEgDD.mjs → marker-read-D1hp62hF-BSXs2TVo.mjs} +3 -3
- package/dist/{marker-read-D1hp62hF-3-4fEgDD.mjs.map → marker-read-D1hp62hF-BSXs2TVo.mjs.map} +1 -1
- package/dist/{migration-DILkj7kB.d.mts → migration-O-3NHVlW.d.mts} +2 -5
- package/dist/migration-O-3NHVlW.d.mts.map +1 -0
- package/dist/{mysql-contract-serializer-BnTKRSsN-BnV7fdYd.mjs → mysql-contract-serializer-D7NjmI2L-gTs-kAW1.mjs} +4 -4
- package/dist/{mysql-contract-serializer-BnTKRSsN-BnV7fdYd.mjs.map → mysql-contract-serializer-D7NjmI2L-gTs-kAW1.mjs.map} +1 -1
- package/dist/{mysql-database-CHl9-oSL-B1arvq6Q.mjs → mysql-database-ByniOtau-BKBIGgSm.mjs} +45 -17
- package/dist/mysql-database-ByniOtau-BKBIGgSm.mjs.map +1 -0
- package/dist/{now-expression-DVD18CUc-DJqdZY96.mjs → now-expression-DDHpZL6o-Ixs-vg-B.mjs} +3 -3
- package/dist/{now-expression-DVD18CUc-DJqdZY96.mjs.map → now-expression-DDHpZL6o-Ixs-vg-B.mjs.map} +1 -1
- package/dist/{pack-CqULIal0.d.mts → pack-C5_g-3YX.d.mts} +272 -11
- package/dist/{pack-CqULIal0.d.mts.map → pack-C5_g-3YX.d.mts.map} +1 -1
- package/dist/{require-temporal-DeDQhbTn-CdpjEWCB.mjs → require-temporal-DDdrgVtL-VOKxTqhD.mjs} +3 -3
- package/dist/{require-temporal-DeDQhbTn-CdpjEWCB.mjs.map → require-temporal-DDdrgVtL-VOKxTqhD.mjs.map} +1 -1
- package/dist/{runner-DEKKxDyw-Cdo1Ysod.mjs → runner-IjNtlp_v-DLCqpSh5.mjs} +68 -72
- package/dist/runner-IjNtlp_v-DLCqpSh5.mjs.map +1 -0
- package/dist/runtime-Bw6vKz9t.mjs +96 -0
- package/dist/runtime-Bw6vKz9t.mjs.map +1 -0
- package/dist/{runtime-DB0w8R7i.mjs → runtime-CHWztV6c.mjs} +66 -46
- package/dist/runtime-CHWztV6c.mjs.map +1 -0
- package/dist/{runtime-DN20lWEg.d.mts → runtime-CQ1V-8Yh.d.mts} +11 -4
- package/dist/runtime-CQ1V-8Yh.d.mts.map +1 -0
- package/dist/{runtime-CbqytTbM.d.mts → runtime-Ci3hPz1j.d.mts} +16 -5
- package/dist/runtime-Ci3hPz1j.d.mts.map +1 -0
- package/dist/{runtime-DUDdsFyy.mjs → runtime-_c_DZuYR.mjs} +18 -13
- package/dist/runtime-_c_DZuYR.mjs.map +1 -0
- package/dist/runtime-dn4-kzZV.d.mts +43 -0
- package/dist/runtime-dn4-kzZV.d.mts.map +1 -0
- package/dist/sql-renderer-CrnJ8cCo.d.mts +1 -0
- package/dist/sql-renderer-DfPaqPkD-DFaweHvr.mjs +501 -0
- package/dist/sql-renderer-DfPaqPkD-DFaweHvr.mjs.map +1 -0
- package/dist/sql-renderer-fnDhRUHs-CcsyIaZ4.d.mts +95 -0
- package/dist/sql-renderer-fnDhRUHs-CcsyIaZ4.d.mts.map +1 -0
- package/dist/{sql-utils-Cmv_TVa8-CNW3UmfQ.mjs → sql-utils-CveZhawQ-B2QmUlY0.mjs} +3 -3
- package/dist/{sql-utils-Cmv_TVa8-CNW3UmfQ.mjs.map → sql-utils-CveZhawQ-B2QmUlY0.mjs.map} +1 -1
- package/dist/{sql-utils-BE8tDXHs.mjs → sql-utils-DVH8boEI.mjs} +3 -6
- package/dist/sql-utils-DVH8boEI.mjs.map +1 -0
- package/dist/{statement-CT5tB4uX-CHqHFM3z.mjs → statement-a2Eekpu6-BDJa255m.mjs} +73 -67
- package/dist/statement-a2Eekpu6-BDJa255m.mjs.map +1 -0
- package/dist/target.d.mts +18 -16
- package/dist/target.mjs +21 -19
- package/dist/target__aggregates.d.mts +2 -0
- package/dist/target__aggregates.mjs +2 -0
- package/dist/target__codec-descriptor.d.mts +2 -2
- package/dist/target__codec-descriptor.mjs +1 -1
- package/dist/target__codec-ids.d.mts +2 -2
- package/dist/target__codec-ids.mjs +2 -2
- package/dist/target__codec-types.d.mts +2 -2
- package/dist/target__codecs.d.mts +2 -2
- package/dist/target__codecs.mjs +2 -2
- package/dist/target__control.d.mts +1 -1
- package/dist/target__control.mjs +2 -2
- package/dist/target__data-types.d.mts +3 -3
- package/dist/target__data-types.mjs +3 -3
- package/dist/target__default-normalizer.d.mts +2 -2
- package/dist/target__default-normalizer.mjs +2 -2
- package/dist/target__descriptor-meta-runtime.d.mts +2 -0
- package/dist/target__descriptor-meta-runtime.mjs +2 -0
- package/dist/target__errors.d.mts +1 -1
- package/dist/target__errors.mjs +1 -1
- package/dist/target__marker-lock.mjs +1 -1
- package/dist/target__migration.d.mts +1 -1
- package/dist/target__migration.mjs +1 -1
- package/dist/target__pack.d.mts +1 -1
- package/dist/target__pack.mjs +1 -1
- package/dist/target__runtime.d.mts +2 -2
- package/dist/target__runtime.mjs +4 -4
- package/dist/target__sql-utils.mjs +2 -2
- package/dist/target__types.mjs +1 -1
- package/package.json +13 -10
- package/dist/adapter-1Kd67Gfa.d.mts +0 -66
- package/dist/adapter-1Kd67Gfa.d.mts.map +0 -1
- package/dist/adapter__runtime.mjs.map +0 -1
- package/dist/codec-descriptor-3xp1XvVH-DfPKpYeP.mjs.map +0 -1
- package/dist/codec-descriptor-BRcKIX3h.d.mts +0 -2
- package/dist/codec-descriptor-DXyubAS6-XDBj6Yet.d.mts.map +0 -1
- package/dist/codec-descriptor-J3TP08l8-BmdgkIU6.d.mts +0 -1
- package/dist/codec-ids-CrR9Xi7r-CjbGCS3o.mjs +0 -20
- package/dist/codec-ids-CrR9Xi7r-CjbGCS3o.mjs.map +0 -1
- package/dist/codec-ids-Dgh5IpML-DGXIq6j8.d.mts +0 -20
- package/dist/codec-ids-Dgh5IpML-DGXIq6j8.d.mts.map +0 -1
- package/dist/codec-types-BS-lWfda.d.mts +0 -1
- package/dist/codec-types-Bai_CFkk-DmZ74URd.d.mts.map +0 -1
- package/dist/codec-types-Dk2h5dBB.d.mts +0 -1
- package/dist/codecs-BMidk26M-B_iWNti6.d.mts.map +0 -1
- package/dist/codecs-wVJlFapM.mjs.map +0 -1
- package/dist/control-BiZaCqna.mjs.map +0 -1
- package/dist/control-CTfV1Zag.mjs.map +0 -1
- package/dist/control-D7_IpeiU.d.mts.map +0 -1
- package/dist/control-Dj8nIA1M.d.mts.map +0 -1
- package/dist/control-RYDTbndD.mjs.map +0 -1
- package/dist/control-WNuLF2Wh.d.mts.map +0 -1
- package/dist/data-type-entries-C7VH2IHc-DM6TbTaz.mjs +0 -59
- package/dist/data-type-entries-C7VH2IHc-DM6TbTaz.mjs.map +0 -1
- package/dist/data-types-65iVc7q1.d.mts.map +0 -1
- package/dist/data-types-D2HAT-Qf-CSdDz1Pk.d.mts.map +0 -1
- package/dist/data-types-DOaaPS93-lycGybNk.mjs +0 -289
- package/dist/data-types-DOaaPS93-lycGybNk.mjs.map +0 -1
- package/dist/date-time-now-generators-BKakW3gd-CIFPuRdM.mjs.map +0 -1
- package/dist/default-normalizer-C8pc7SbL-BXd70q02.mjs +0 -100
- package/dist/default-normalizer-C8pc7SbL-BXd70q02.mjs.map +0 -1
- package/dist/default-normalizer-D-8Ii0df.d.mts +0 -27
- package/dist/default-normalizer-D-8Ii0df.d.mts.map +0 -1
- package/dist/descriptor-meta-BF6YvSag-ChHHvlHc.mjs.map +0 -1
- package/dist/descriptor-meta-e29H69KN-t-S8_DYh.mjs.map +0 -1
- package/dist/errors-Cng94tYg-DTH51xWG.mjs.map +0 -1
- package/dist/errors-DjCkC9IM.d.mts.map +0 -1
- package/dist/migration-DILkj7kB.d.mts.map +0 -1
- package/dist/mysql-database-CHl9-oSL-B1arvq6Q.mjs.map +0 -1
- package/dist/runner-DEKKxDyw-Cdo1Ysod.mjs.map +0 -1
- package/dist/runtime-CbqytTbM.d.mts.map +0 -1
- package/dist/runtime-Cm-T3hbP.d.mts +0 -29
- package/dist/runtime-Cm-T3hbP.d.mts.map +0 -1
- package/dist/runtime-DB0w8R7i.mjs.map +0 -1
- package/dist/runtime-DN20lWEg.d.mts.map +0 -1
- package/dist/runtime-DUDdsFyy.mjs.map +0 -1
- package/dist/sql-utils-BE8tDXHs.mjs.map +0 -1
- package/dist/statement-CT5tB4uX-CHqHFM3z.mjs.map +0 -1
|
@@ -1,501 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { n as quoteIdentifier, t as escapeLiteral } from "./sql-utils-Cmv_TVa8-CNW3UmfQ.mjs";
|
|
4
|
-
import { a as mysqlCodecDescriptorRegistry, t as assembleMysqlCodecRegistry } from "./codecs-wVJlFapM.mjs";
|
|
5
|
-
import { t as mysqlNowGenerators } from "./date-time-now-generators-BKakW3gd-CIFPuRdM.mjs";
|
|
6
|
-
import { t as tokenizeMysqlSql } from "./sql-utils-BE8tDXHs.mjs";
|
|
7
|
-
import { r as mysqlAdapterDescriptorMeta, t as mysqlAdapterCapabilities } from "./descriptor-meta-e29H69KN-t-S8_DYh.mjs";
|
|
8
|
-
import { r as readMarkerResult } from "./marker-read-D1hp62hF-3-4fEgDD.mjs";
|
|
9
|
-
import { InternalError, assertNever } from "@prisma/orm-framework/utils/internal-error";
|
|
10
|
-
import { structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
11
|
-
import { collectOrderedParamRefs, isDdlNode } from "@prisma/orm-family-sql/relational-core/ast";
|
|
12
|
-
import { APP_SPACE_ID } from "@prisma/orm-framework/components/control";
|
|
13
|
-
import { timestampNowRuntimeGenerator } from "@prisma/orm-family-sql/family/runtime";
|
|
14
|
-
//#region ../../../3-targets/mysql/1-mysql/2-adapter/dist/runtime.mjs
|
|
15
|
-
const INT_MIN = -(2 ** 31);
|
|
16
|
-
const INT_MAX = 2 ** 31 - 1;
|
|
17
|
-
function refuse(value) {
|
|
18
|
-
throw structuredError("RUNTIME.RAW_SQL_UNSUPPORTED_INTERPOLATION", "MySQL has no codec for this JS value in raw SQL: wrap it in `param(...)` with an explicit codec", { meta: { valueType: typeof value } });
|
|
19
|
-
}
|
|
20
|
-
/** The codec of a bare value interpolated into `fns.raw` or the raw lane on a MySQL client: integers, bigints and strings. */
|
|
21
|
-
const mysqlRawCodecInferer = { inferCodec(value) {
|
|
22
|
-
switch (typeof value) {
|
|
23
|
-
case "number":
|
|
24
|
-
if (!Number.isSafeInteger(value)) return refuse(value);
|
|
25
|
-
return value >= INT_MIN && value <= INT_MAX ? MYSQL_INT_CODEC_ID : refuse(value);
|
|
26
|
-
case "bigint": return MYSQL_BIGINT_CODEC_ID;
|
|
27
|
-
case "string": return MYSQL_TEXT_CODEC_ID;
|
|
28
|
-
default: return refuse(value);
|
|
29
|
-
}
|
|
30
|
-
} };
|
|
31
|
-
/** Refuses a lowered statement unless every placeholder is a numbered `?N` naming one of its parameters and every parameter has a placeholder. */
|
|
32
|
-
function assertPlaceholdersMatchParams(sql, paramCount) {
|
|
33
|
-
const tokens = tokenizeMysqlSql(sql).filter((token) => token.kind === "placeholder");
|
|
34
|
-
const placeholders = tokens.map((token) => token.text);
|
|
35
|
-
const numbers = tokens.map((token) => token.number ?? NaN);
|
|
36
|
-
if (numbers.every((number) => number >= 1 && number <= paramCount) && new Set(numbers).size === paramCount) return;
|
|
37
|
-
throw structuredError("RUNTIME.PARAM_PLACEHOLDER_MISMATCH", `The lowered MySQL statement writes placeholders ${JSON.stringify(placeholders)} for ${paramCount} parameter(s); each parameter must be written as its own numbered placeholder, and no other placeholder may appear.`, {
|
|
38
|
-
why: "A placeholder that does not match a parameter binds a value to the wrong place in the statement, or leaves a value unbound.",
|
|
39
|
-
fix: "Pass values into raw SQL through interpolation rather than writing a `?` in the SQL text.",
|
|
40
|
-
meta: {
|
|
41
|
-
placeholders,
|
|
42
|
-
params: paramCount
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
/** The name an upsert gives the row it proposes, which its update reads as `new`.`column`; the ORM writes that row as `excluded`, as Postgres names it. */
|
|
47
|
-
const PROPOSED_ROW = "new";
|
|
48
|
-
/**
|
|
49
|
-
* Raises `group_concat_max_len` for this statement only, past any result a connection can send, so an ordered include does not depend on how the driver set up its session. MySQL takes `SET_VAR` only on the outermost `SELECT`.
|
|
50
|
-
*/
|
|
51
|
-
const GROUP_CONCAT_HINT = "/*+ SET_VAR(group_concat_max_len = 4294967295) */";
|
|
52
|
-
/** MySQL's documented way to write an `OFFSET` with no `LIMIT`: the largest row count it takes. */
|
|
53
|
-
const NO_LIMIT = "18446744073709551615";
|
|
54
|
-
function nodeKind(value) {
|
|
55
|
-
return typeof value === "object" && value !== null && "kind" in value ? String(value.kind) : "unknown";
|
|
56
|
-
}
|
|
57
|
-
function unsupported(feature, message) {
|
|
58
|
-
return mysqlError("RUNTIME.AST_UNSUPPORTED", message, { meta: {
|
|
59
|
-
target: "mysql",
|
|
60
|
-
feature
|
|
61
|
-
} });
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Lowers a query AST to MySQL SQL. Each param is written as `?N`, N being its position in `collectOrderedParamRefs`, the order the runtime encodes and middleware edits params in; a param written twice is bound once. The driver fills the placeholders.
|
|
65
|
-
*/
|
|
66
|
-
function renderMysqlSql(ast, contract, codecs) {
|
|
67
|
-
const placeholderNumbers = /* @__PURE__ */ new Map();
|
|
68
|
-
const params = collectOrderedParamRefs(ast).map((ref, index) => {
|
|
69
|
-
placeholderNumbers.set(ref, index + 1);
|
|
70
|
-
return ref.kind === "prepared-param-ref" ? {
|
|
71
|
-
kind: "bind",
|
|
72
|
-
name: ref.name
|
|
73
|
-
} : {
|
|
74
|
-
kind: "literal",
|
|
75
|
-
value: ref.value
|
|
76
|
-
};
|
|
77
|
-
});
|
|
78
|
-
const ctx = {
|
|
79
|
-
contract,
|
|
80
|
-
codecs,
|
|
81
|
-
placeholderNumbers,
|
|
82
|
-
uses: { groupConcat: false }
|
|
83
|
-
};
|
|
84
|
-
const rendered = renderStatement(ast, ctx);
|
|
85
|
-
const sql = ctx.uses.groupConcat ? withGroupConcatHint(ast, rendered) : rendered;
|
|
86
|
-
assertPlaceholdersMatchParams(sql, params.length);
|
|
87
|
-
return Object.freeze({
|
|
88
|
-
sql,
|
|
89
|
-
params
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
/** Puts `GROUP_CONCAT_HINT` on the outermost `SELECT`; a statement without one would leave `GROUP_CONCAT` at the session's limit, which can cut an array after an element and still read as JSON, so it is refused. */
|
|
93
|
-
function withGroupConcatHint(ast, rendered) {
|
|
94
|
-
if (ast.kind !== "select" || !rendered.startsWith("SELECT ")) throw unsupported("ordered-array-outside-select", "MySQL can build an ordered JSON array only in a SELECT statement, whose outermost SELECT carries the hint that raises group_concat_max_len");
|
|
95
|
-
return `SELECT ${GROUP_CONCAT_HINT} ${rendered.slice(7)}`;
|
|
96
|
-
}
|
|
97
|
-
function renderStatement(ast, ctx) {
|
|
98
|
-
switch (ast.kind) {
|
|
99
|
-
case "select": return renderSelect(ast, ctx);
|
|
100
|
-
case "raw-query": return renderParts(ast.parts, ctx);
|
|
101
|
-
case "insert": return renderInsert(ast, ctx);
|
|
102
|
-
case "update": return renderUpdate(ast, ctx);
|
|
103
|
-
case "delete": return renderDelete(ast, ctx);
|
|
104
|
-
default: throw new InternalError(`Unsupported AST node kind: ${nodeKind(ast)}`);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
function invalid(node, message) {
|
|
108
|
-
return mysqlError("RUNTIME.AST_INVALID", message, { meta: { node } });
|
|
109
|
-
}
|
|
110
|
-
/** MySQL has no `RETURNING`: the SQL family's ORM reads written rows back with a select when the contract does not report `returning`. */
|
|
111
|
-
function refuseReturning(returning, what) {
|
|
112
|
-
if (returning !== void 0 && returning.length > 0) throw unsupported("returning", `MySQL cannot return the rows ${what} writes; it has no RETURNING`);
|
|
113
|
-
}
|
|
114
|
-
function renderInsertValue(value, ctx) {
|
|
115
|
-
if (value === void 0 || value.kind === "default-value") return "DEFAULT";
|
|
116
|
-
return renderExpr(value, ctx);
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* An insert, with the bare table name: MySQL's `INSERT` takes no alias, so a column of the table is qualified by its name. A row without a value for a column gets `DEFAULT`. An upsert names its proposed row `new` and updates the existing row on any duplicate key. MySQL cannot limit `ON DUPLICATE KEY UPDATE` to named conflict columns, so the adapter does not report `insertOnConflictTarget` and an upsert that names them is refused. Skipping a conflicting row is refused: `INSERT IGNORE` also hides foreign-key and `NOT NULL` errors.
|
|
120
|
-
*/
|
|
121
|
-
function renderInsert(ast, ctx) {
|
|
122
|
-
refuseReturning(ast.returning, "an insert");
|
|
123
|
-
if (ast.rows.length === 0) throw invalid("insert", "INSERT requires at least one row");
|
|
124
|
-
const table = qualifyTable(ast.table, ctx);
|
|
125
|
-
const insertCtx = {
|
|
126
|
-
...ctx,
|
|
127
|
-
insertInto: {
|
|
128
|
-
alias: ast.table.alias ?? ast.table.name,
|
|
129
|
-
name: table
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
const columns = [...new Set(ast.rows.flatMap((row) => Object.keys(row)))];
|
|
133
|
-
const values = ast.rows.map((row) => `(${columns.map((column) => renderInsertValue(row[column], insertCtx)).join(", ")})`).join(", ");
|
|
134
|
-
const insert = `INSERT INTO ${table} (${columns.map(quoteIdentifier).join(", ")}) VALUES ${values}`;
|
|
135
|
-
const conflict = ast.onConflict;
|
|
136
|
-
if (conflict === void 0) return insert;
|
|
137
|
-
const action = conflict.action;
|
|
138
|
-
switch (action.kind) {
|
|
139
|
-
case "do-nothing": throw unsupported("insert-on-conflict-skip", "MySQL cannot skip a conflicting row without also hiding other errors: INSERT IGNORE turns foreign-key and NOT NULL errors into warnings");
|
|
140
|
-
case "do-update-set": {
|
|
141
|
-
if (conflict.columns.length > 0) throw unsupported("insert-on-conflict-target", "MySQL cannot limit ON DUPLICATE KEY UPDATE to named conflict columns: it fires on any unique key");
|
|
142
|
-
const assignments = Object.entries(action.set);
|
|
143
|
-
if (assignments.length === 0) throw invalid("insert-on-conflict", "An upsert requires at least one column to update");
|
|
144
|
-
const set = assignments.map(([column, value]) => `${quoteIdentifier(column)} = ${renderExpr(value, insertCtx)}`).join(", ");
|
|
145
|
-
return `${insert} AS ${quoteIdentifier(PROPOSED_ROW)} ON DUPLICATE KEY UPDATE ${set}`;
|
|
146
|
-
}
|
|
147
|
-
default: return assertNever(action, `Unsupported conflict action: ${nodeKind(action)}`);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
function renderUpdate(ast, ctx) {
|
|
151
|
-
refuseReturning(ast.returning, "an update");
|
|
152
|
-
const assignments = Object.entries(ast.set);
|
|
153
|
-
if (assignments.length === 0) throw invalid("update", "UPDATE requires at least one column to set");
|
|
154
|
-
const set = assignments.map(([column, value]) => `${quoteIdentifier(column)} = ${renderExpr(value, ctx)}`).join(", ");
|
|
155
|
-
const where = ast.where ? ` WHERE ${renderExpr(ast.where, ctx)}` : "";
|
|
156
|
-
return `UPDATE ${renderTableSource(ast.table, ctx)} SET ${set}${where}`;
|
|
157
|
-
}
|
|
158
|
-
function renderDelete(ast, ctx) {
|
|
159
|
-
refuseReturning(ast.returning, "a delete");
|
|
160
|
-
const where = ast.where ? ` WHERE ${renderExpr(ast.where, ctx)}` : "";
|
|
161
|
-
return `DELETE FROM ${renderTableSource(ast.table, ctx)}${where}`;
|
|
162
|
-
}
|
|
163
|
-
function renderLimitOffset(keyword, value, ctx) {
|
|
164
|
-
if (value === void 0) return "";
|
|
165
|
-
if (typeof value === "number") return `${keyword} ${value}`;
|
|
166
|
-
return `${keyword} ${value.kind === "param-ref" || value.kind === "prepared-param-ref" ? placeholder(value, ctx) : renderExpr(value, ctx)}`;
|
|
167
|
-
}
|
|
168
|
-
function renderSelect(ast, ctx) {
|
|
169
|
-
if (ast.locking !== void 0 && ast.locking.length > 0) throw unsupported("locking-clause", "Row locks are not supported on MySQL yet, so a select cannot carry a locking clause such as FOR UPDATE");
|
|
170
|
-
if (ast.distinctOn !== void 0 && ast.distinctOn.length > 0) throw unsupported("distinct-on", "MySQL has no DISTINCT ON");
|
|
171
|
-
return [
|
|
172
|
-
`SELECT ${ast.distinct ? "DISTINCT " : ""}${renderProjection(ast.projection, ctx)}`,
|
|
173
|
-
ast.from === void 0 ? "" : `FROM ${renderSource(ast.from, ctx)}`,
|
|
174
|
-
ast.joins?.length ? ast.joins.map((join) => renderJoin(join, ctx)).join(" ") : "",
|
|
175
|
-
ast.where ? `WHERE ${renderExpr(ast.where, ctx)}` : "",
|
|
176
|
-
ast.groupBy?.length ? `GROUP BY ${ast.groupBy.map((e) => renderExpr(e, ctx)).join(", ")}` : "",
|
|
177
|
-
ast.having ? `HAVING ${renderExpr(ast.having, ctx)}` : "",
|
|
178
|
-
ast.orderBy?.length ? `ORDER BY ${renderOrderByItems(ast.orderBy, ctx)}` : "",
|
|
179
|
-
ast.limit === void 0 && ast.offset !== void 0 ? `LIMIT ${NO_LIMIT}` : renderLimitOffset("LIMIT", ast.limit, ctx),
|
|
180
|
-
renderLimitOffset("OFFSET", ast.offset, ctx)
|
|
181
|
-
].filter((part) => part.length > 0).join(" ");
|
|
182
|
-
}
|
|
183
|
-
function renderProjection(projection, ctx) {
|
|
184
|
-
return projection.map((item) => `${renderExpr(item.expr, ctx)} AS ${quoteIdentifier(item.alias)}`).join(", ");
|
|
185
|
-
}
|
|
186
|
-
function qualifyTable(table, ctx) {
|
|
187
|
-
if (table.namespaceId === void 0) return quoteIdentifier(table.name);
|
|
188
|
-
if (ctx.contract === void 0) throw new InternalError(`Table "${table.name}" carries namespace "${table.namespaceId}" but no contract was supplied to resolve it`);
|
|
189
|
-
const namespace = ctx.contract.storage.namespaces[table.namespaceId];
|
|
190
|
-
if (namespace?.qualifyTable === void 0) throw structuredError("RUNTIME.NAMESPACE_UNKNOWN", `Table "${table.name}" references namespace "${table.namespaceId}" which the contract does not materialise for SQL rendering`, { meta: {
|
|
191
|
-
table: table.name,
|
|
192
|
-
namespaceId: table.namespaceId,
|
|
193
|
-
reason: namespace === void 0 ? "not-present" : "not-materialised"
|
|
194
|
-
} });
|
|
195
|
-
return namespace.qualifyTable(table.name);
|
|
196
|
-
}
|
|
197
|
-
function renderTableSource(source, ctx) {
|
|
198
|
-
const qualified = qualifyTable(source, ctx);
|
|
199
|
-
return source.alias ? `${qualified} AS ${quoteIdentifier(source.alias)}` : qualified;
|
|
200
|
-
}
|
|
201
|
-
function renderSource(source, ctx) {
|
|
202
|
-
switch (source.kind) {
|
|
203
|
-
case "table-source": return renderTableSource(source, ctx);
|
|
204
|
-
case "derived-table-source": return `(${renderSelect(source.query, ctx)}) AS ${quoteIdentifier(source.alias)}`;
|
|
205
|
-
case "function-source": throw unsupported("function-source", `MySQL cannot select from the set-returning function ${source.fn}`);
|
|
206
|
-
default: return assertNever(source, `Unsupported source node kind: ${nodeKind(source)}`);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
function renderExpr(expr, ctx) {
|
|
210
|
-
switch (expr.kind) {
|
|
211
|
-
case "column-ref": return renderColumn(expr, ctx);
|
|
212
|
-
case "identifier-ref": return quoteIdentifier(expr.name);
|
|
213
|
-
case "operation": return renderOperation(expr, ctx);
|
|
214
|
-
case "subquery": return renderSubquery(expr, ctx);
|
|
215
|
-
case "aggregate": return renderAggregate(expr, ctx);
|
|
216
|
-
case "window-func": return renderWindowFunc(expr, ctx);
|
|
217
|
-
case "function-call": return renderFunctionCall(expr, ctx);
|
|
218
|
-
case "cast": return renderCast(expr, ctx);
|
|
219
|
-
case "case": return renderCase(expr, ctx);
|
|
220
|
-
case "json-object": return renderJsonObject(expr, ctx);
|
|
221
|
-
case "json-array-agg": return renderJsonArrayAgg(expr, ctx);
|
|
222
|
-
case "binary": return renderBinary(expr, ctx);
|
|
223
|
-
case "and": return expr.exprs.length === 0 ? "TRUE" : `(${expr.exprs.map((part) => renderExpr(part, ctx)).join(" AND ")})`;
|
|
224
|
-
case "or": return expr.exprs.length === 0 ? "FALSE" : `(${expr.exprs.map((part) => renderExpr(part, ctx)).join(" OR ")})`;
|
|
225
|
-
case "exists": return `${expr.notExists ? "NOT " : ""}EXISTS (${renderSelect(expr.subquery, ctx)})`;
|
|
226
|
-
case "null-check": return renderNullCheck(expr, ctx);
|
|
227
|
-
case "not": return `NOT (${renderExpr(expr.expr, ctx)})`;
|
|
228
|
-
case "param-ref":
|
|
229
|
-
case "prepared-param-ref": return renderParam(expr, ctx);
|
|
230
|
-
case "literal": return renderLiteral(expr);
|
|
231
|
-
case "list": return renderList(expr, ctx);
|
|
232
|
-
case "raw-expr": return renderParts(expr.parts, ctx);
|
|
233
|
-
default: return assertNever(expr, `Unsupported expression node kind: ${nodeKind(expr)}`);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
/** Refuses raw SQL text that puts a digit right after an interpolated value: the value's `?N` and the digit would read as one larger placeholder, `?1` and `0` as `?10`. */
|
|
237
|
-
function assertNoDigitAfterParam(parts) {
|
|
238
|
-
parts.forEach((part, index) => {
|
|
239
|
-
const next = parts[index + 1];
|
|
240
|
-
if (typeof part !== "string" && (part.kind === "param-ref" || part.kind === "prepared-param-ref") && typeof next === "string" && /^\d/.test(next)) throw structuredError("RUNTIME.PARAM_PLACEHOLDER_MISMATCH", "Raw SQL puts a digit right after an interpolated value, which MySQL lowering would read as part of the value's placeholder", {
|
|
241
|
-
why: "Each value is written as a numbered placeholder, ?N, so a digit that follows it in the SQL text makes a different placeholder: ?1 followed by 0 reads as ?10.",
|
|
242
|
-
fix: "Put a space or an operator between the interpolated value and the digit.",
|
|
243
|
-
meta: {
|
|
244
|
-
reason: "digit-after-value",
|
|
245
|
-
part: index + 1
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
function renderParts(parts, ctx) {
|
|
251
|
-
assertNoDigitAfterParam(parts);
|
|
252
|
-
return parts.map((part) => {
|
|
253
|
-
if (typeof part === "string") return part;
|
|
254
|
-
switch (part.kind) {
|
|
255
|
-
case "select": return renderSelect(part, ctx);
|
|
256
|
-
case "insert": return renderInsert(part, ctx);
|
|
257
|
-
case "update": return renderUpdate(part, ctx);
|
|
258
|
-
case "delete": return renderDelete(part, ctx);
|
|
259
|
-
default: return renderExpr(part, ctx);
|
|
260
|
-
}
|
|
261
|
-
}).join("");
|
|
262
|
-
}
|
|
263
|
-
function renderColumn(ref, ctx) {
|
|
264
|
-
const column = quoteIdentifier(ref.column);
|
|
265
|
-
const { insertInto } = ctx;
|
|
266
|
-
if (insertInto !== void 0) {
|
|
267
|
-
if (ref.table === "excluded") return `${quoteIdentifier(PROPOSED_ROW)}.${column}`;
|
|
268
|
-
if (ref.table === insertInto.alias) return `${insertInto.name}.${column}`;
|
|
269
|
-
}
|
|
270
|
-
return `${quoteIdentifier(ref.table)}.${column}`;
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* A literal the code wrote: a number, a bigint, a boolean or NULL, such as the ORM's `1` and `fns.and(true, …)`. A `LiteralExpr` does not say where its value came from, and no part of Prisma writes a text, date or JSON literal into a MySQL runtime statement, so those are refused: a value of that kind can only be a caller's, which belongs in a param, sent apart from the SQL.
|
|
274
|
-
*/
|
|
275
|
-
function renderLiteral(expr) {
|
|
276
|
-
const { value } = expr;
|
|
277
|
-
if (value === null || value === void 0) return "NULL";
|
|
278
|
-
if (typeof value === "number") {
|
|
279
|
-
if (!Number.isFinite(value)) throw unsupported("non-finite-number", `MySQL has no literal for ${value}`);
|
|
280
|
-
return String(value);
|
|
281
|
-
}
|
|
282
|
-
if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
|
|
283
|
-
if (typeof value === "bigint") return String(value);
|
|
284
|
-
throw unsupported("value-literal", `MySQL lowering writes only numbers, booleans and NULL as literals; a ${value instanceof Date ? "date" : Array.isArray(value) ? "array" : typeof value} value must be a param`);
|
|
285
|
-
}
|
|
286
|
-
/** Renders each `{{self}}` and `{{argN}}` where the template writes it. */
|
|
287
|
-
function renderOperation(expr, ctx) {
|
|
288
|
-
return expr.lowering.template.replace(/\{\{(self|arg(\d+))\}\}/g, (_match, _name, index) => {
|
|
289
|
-
if (index === void 0) return renderExpr(expr.self, ctx);
|
|
290
|
-
const arg = expr.args[Number(index)];
|
|
291
|
-
return arg === void 0 ? "" : renderExpr(arg, ctx);
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
function renderSubquery(expr, ctx, columns = 1) {
|
|
295
|
-
if (expr.query.projection.length !== columns) throw structuredError("RUNTIME.AST_INVALID", columns === 1 ? "Subquery expressions must project exactly one column" : `A subquery compared with a row value of ${columns} columns must project ${columns} columns`, { meta: { node: "subquery" } });
|
|
296
|
-
return `(${renderSelect(expr.query, ctx)})`;
|
|
297
|
-
}
|
|
298
|
-
/** Whether an operand must be parenthesised before an operator is written after it. A new expression kind fails to compile here until someone decides. */
|
|
299
|
-
function needsGrouping(expr) {
|
|
300
|
-
switch (expr.kind) {
|
|
301
|
-
case "operation":
|
|
302
|
-
case "subquery": return true;
|
|
303
|
-
case "column-ref":
|
|
304
|
-
case "identifier-ref":
|
|
305
|
-
case "aggregate":
|
|
306
|
-
case "window-func":
|
|
307
|
-
case "function-call":
|
|
308
|
-
case "cast":
|
|
309
|
-
case "case":
|
|
310
|
-
case "json-object":
|
|
311
|
-
case "json-array-agg":
|
|
312
|
-
case "binary":
|
|
313
|
-
case "and":
|
|
314
|
-
case "or":
|
|
315
|
-
case "exists":
|
|
316
|
-
case "null-check":
|
|
317
|
-
case "not":
|
|
318
|
-
case "param-ref":
|
|
319
|
-
case "prepared-param-ref":
|
|
320
|
-
case "literal":
|
|
321
|
-
case "list":
|
|
322
|
-
case "raw-expr": return false;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
function grouped(expr, ctx) {
|
|
326
|
-
const rendered = renderExpr(expr, ctx);
|
|
327
|
-
return needsGrouping(expr) ? `(${rendered})` : rendered;
|
|
328
|
-
}
|
|
329
|
-
function renderNullCheck(expr, ctx) {
|
|
330
|
-
return `${grouped(expr.expr, ctx)} ${expr.isNull ? "IS NULL" : "IS NOT NULL"}`;
|
|
331
|
-
}
|
|
332
|
-
const BINARY_OPERATORS = {
|
|
333
|
-
eq: "=",
|
|
334
|
-
neq: "<>",
|
|
335
|
-
isNotDistinctFrom: "<=>",
|
|
336
|
-
gt: ">",
|
|
337
|
-
lt: "<",
|
|
338
|
-
gte: ">=",
|
|
339
|
-
lte: "<=",
|
|
340
|
-
like: "LIKE",
|
|
341
|
-
in: "IN",
|
|
342
|
-
notIn: "NOT IN"
|
|
343
|
-
};
|
|
344
|
-
function renderBinary(expr, ctx) {
|
|
345
|
-
if (expr.right.kind === "list" && expr.right.values.length === 0) {
|
|
346
|
-
if (expr.op === "in") return "FALSE";
|
|
347
|
-
if (expr.op === "notIn") return "TRUE";
|
|
348
|
-
}
|
|
349
|
-
const left = grouped(expr.left, ctx);
|
|
350
|
-
const right = expr.right.kind === "subquery" && expr.left.kind === "list" ? renderSubquery(expr.right, ctx, expr.left.values.length) : renderExpr(expr.right, ctx);
|
|
351
|
-
if (expr.op === "isDistinctFrom") return `NOT (${left} <=> ${right})`;
|
|
352
|
-
return `${left} ${BINARY_OPERATORS[expr.op]} ${right}`;
|
|
353
|
-
}
|
|
354
|
-
function renderList(expr, ctx) {
|
|
355
|
-
if (expr.values.length === 0) return "(NULL)";
|
|
356
|
-
return `(${expr.values.map((value) => renderExpr(value, ctx)).join(", ")})`;
|
|
357
|
-
}
|
|
358
|
-
function renderAggregate(expr, ctx) {
|
|
359
|
-
const fn = expr.fn.toUpperCase();
|
|
360
|
-
return expr.expr ? `${fn}(${renderExpr(expr.expr, ctx)})` : `${fn}(*)`;
|
|
361
|
-
}
|
|
362
|
-
function renderWindowFunc(expr, ctx) {
|
|
363
|
-
const args = expr.args.map((arg) => renderExpr(arg, ctx)).join(", ");
|
|
364
|
-
const over = [expr.partitionBy?.length ? `PARTITION BY ${expr.partitionBy.map((e) => renderExpr(e, ctx)).join(", ")}` : "", expr.orderBy?.length ? `ORDER BY ${renderOrderByItems(expr.orderBy, ctx)}` : ""].filter((part) => part.length > 0).join(" ");
|
|
365
|
-
return `${expr.fn.toUpperCase()}(${args}) OVER (${over})`;
|
|
366
|
-
}
|
|
367
|
-
function renderFunctionCall(expr, ctx) {
|
|
368
|
-
return `${expr.fn}(${expr.args.map((arg) => renderExpr(arg, ctx)).join(", ")})`;
|
|
369
|
-
}
|
|
370
|
-
function renderCast(expr, ctx) {
|
|
371
|
-
return `CAST(${renderExpr(expr.expr, ctx)} AS ${expr.targetType})`;
|
|
372
|
-
}
|
|
373
|
-
function renderCase(expr, ctx) {
|
|
374
|
-
return `CASE ${expr.branches.map((branch) => `WHEN ${renderExpr(branch.condition, ctx)} THEN ${renderExpr(branch.value, ctx)}`).join(" ")}${expr.elseExpr === void 0 ? "" : ` ELSE ${renderExpr(expr.elseExpr, ctx)}`} END`;
|
|
375
|
-
}
|
|
376
|
-
function descriptorOf(codec, ctx, use) {
|
|
377
|
-
const descriptor = ctx.codecs.descriptorFor(codec.codecId);
|
|
378
|
-
if (descriptor === void 0) throw structuredError("RUNTIME.PARAM_REF_MISSING_CODEC", `MySQL lowering: ${use} carries codecId "${codec.codecId}" but the MySQL codec registry has no entry for it. Register the extension pack that contributes this codec.`, { meta: { codecId: codec.codecId } });
|
|
379
|
-
return descriptor;
|
|
380
|
-
}
|
|
381
|
-
function placeholder(ref, ctx) {
|
|
382
|
-
const number = ctx.placeholderNumbers.get(ref);
|
|
383
|
-
if (number === void 0) throw new InternalError("A param was written that the AST does not collect");
|
|
384
|
-
return `?${number}`;
|
|
385
|
-
}
|
|
386
|
-
/** A param as its numbered placeholder, refusing one whose codec the MySQL registry lacks. */
|
|
387
|
-
function renderParam(ref, ctx) {
|
|
388
|
-
if (ref.codec !== void 0) descriptorOf(ref.codec, ctx, "a parameter");
|
|
389
|
-
return placeholder(ref, ctx);
|
|
390
|
-
}
|
|
391
|
-
function projectThroughCodec(value, codec, ctx) {
|
|
392
|
-
return descriptorOf(codec, ctx, "a JSON projection").projectJson(value, codec);
|
|
393
|
-
}
|
|
394
|
-
function renderJsonValue(projection, ctx) {
|
|
395
|
-
return projection.accept({
|
|
396
|
-
codec: ({ value, codec }) => renderExpr(projectThroughCodec(value, codec, ctx), ctx),
|
|
397
|
-
native: ({ value }) => renderExpr(value, ctx),
|
|
398
|
-
document: ({ value }) => renderExpr(value, ctx)
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
function renderJsonObject(expr, ctx) {
|
|
402
|
-
return `JSON_OBJECT(${expr.entries.flatMap((entry) => [`'${escapeLiteral(entry.key)}'`, renderJsonValue(entry.value, ctx)]).join(", ")})`;
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
* The element of an ordered JSON array, as JSON text. A document already is JSON; a scalar goes through `JSON_ARRAY`, so a string arrives quoted and escaped.
|
|
406
|
-
*/
|
|
407
|
-
function renderJsonElementText(projection, ctx) {
|
|
408
|
-
const rendered = renderJsonValue(projection, ctx);
|
|
409
|
-
return projection.kind === "document" ? rendered : `JSON_EXTRACT(JSON_ARRAY(${rendered}), '$[0]')`;
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
* `JSON_ARRAYAGG` takes no `ORDER BY`, and MySQL drops a derived table's `ORDER BY` when the outer query aggregates, so an ordered array is built as text with `GROUP_CONCAT`, which keeps its own order, and cast to JSON. The statement raises `group_concat_max_len` past any result a connection can send (see `GROUP_CONCAT_HINT`), so `GROUP_CONCAT` never cuts the text short. Text longer than `max_allowed_packet` makes `CONCAT` return NULL with only a warning, which would read as an empty include; so an empty array is written only when there are no rows, and a NULL text with rows is replaced by text that is not JSON, which fails the cast and the statement with MySQL's invalid-JSON error. `JSON_ARRAYAGG` fails on its own when its result exceeds a packet. An empty array is `JSON_ARRAY()`, so the column stays JSON and a nested include stays an array.
|
|
413
|
-
*/
|
|
414
|
-
function renderJsonArrayAgg(expr, ctx) {
|
|
415
|
-
if (expr.orderBy === void 0) {
|
|
416
|
-
const aggregated = `JSON_ARRAYAGG(${renderJsonValue(expr.expr, ctx)})`;
|
|
417
|
-
return expr.onEmpty === "emptyArray" ? `COALESCE(${aggregated}, JSON_ARRAY())` : aggregated;
|
|
418
|
-
}
|
|
419
|
-
ctx.uses.groupConcat = true;
|
|
420
|
-
const text = `CONCAT('[', GROUP_CONCAT(${renderJsonElementText(expr.expr, ctx)} ORDER BY ${renderOrderByItems(expr.orderBy, ctx)} SEPARATOR ','), ']')`;
|
|
421
|
-
return `CASE WHEN COUNT(*) = 0 THEN ${expr.onEmpty === "emptyArray" ? "JSON_ARRAY()" : "NULL"} ELSE CAST(COALESCE(${text}, ${OVERSIZED_ARRAY_TEXT}) AS JSON) END`;
|
|
422
|
-
}
|
|
423
|
-
/** Text that is not JSON, written in place of an array MySQL could not build because it is larger than a packet, so the cast fails. MySQL's error does not show this text: the user sees `Invalid JSON text in argument 1 to function cast_as_json`, which names neither the include nor the packet size. The text counts the rows only so that MySQL evaluates it when it is reached, not while preparing the statement. */
|
|
424
|
-
const OVERSIZED_ARRAY_TEXT = "CONCAT('array larger than max_allowed_packet: ', COUNT(*), ' rows')";
|
|
425
|
-
const ORDER_DIRECTION = {
|
|
426
|
-
asc: "ASC",
|
|
427
|
-
desc: "DESC"
|
|
428
|
-
};
|
|
429
|
-
/** A NULLS FIRST or NULLS LAST placement, which MySQL lacks, as a leading `IS NULL` sort key. */
|
|
430
|
-
const NULLS_KEY_DIRECTION = {
|
|
431
|
-
first: "DESC",
|
|
432
|
-
last: "ASC"
|
|
433
|
-
};
|
|
434
|
-
function renderOrderByItem(item, ctx) {
|
|
435
|
-
return `${item.nulls === void 0 ? "" : `${grouped(item.expr, ctx)} IS NULL ${NULLS_KEY_DIRECTION[item.nulls]}, `}${renderExpr(item.expr, ctx)} ${ORDER_DIRECTION[item.dir]}`;
|
|
436
|
-
}
|
|
437
|
-
function renderOrderByItems(items, ctx) {
|
|
438
|
-
return items.map((item) => renderOrderByItem(item, ctx)).join(", ");
|
|
439
|
-
}
|
|
440
|
-
function renderJoin(join, ctx) {
|
|
441
|
-
if (join.joinType === "full") throw unsupported("full-join", "MySQL has no FULL JOIN");
|
|
442
|
-
if (join.lateral) throw unsupported("lateral-join", "LATERAL joins are not supported on MySQL yet");
|
|
443
|
-
return `${join.joinType.toUpperCase()} JOIN ${renderSource(join.source, ctx)} ON ${renderJoinOn(join.on, ctx)}`;
|
|
444
|
-
}
|
|
445
|
-
function renderJoinOn(on, ctx) {
|
|
446
|
-
return on.kind === "eq-col-join-on" ? `${renderColumn(on.left, ctx)} = ${renderColumn(on.right, ctx)}` : renderExpr(on, ctx);
|
|
447
|
-
}
|
|
448
|
-
function markerQuery(queryable) {
|
|
449
|
-
return { async query(sql, params) {
|
|
450
|
-
const rows = [];
|
|
451
|
-
for await (const row of queryable.query({
|
|
452
|
-
sql,
|
|
453
|
-
...params ? { params } : {}
|
|
454
|
-
})) rows.push(row);
|
|
455
|
-
return { rows };
|
|
456
|
-
} };
|
|
457
|
-
}
|
|
458
|
-
var MysqlAdapterImpl = class {
|
|
459
|
-
familyId = "sql";
|
|
460
|
-
targetId = "mysql";
|
|
461
|
-
profile;
|
|
462
|
-
#codecs;
|
|
463
|
-
constructor(codecs) {
|
|
464
|
-
this.#codecs = codecs;
|
|
465
|
-
this.profile = Object.freeze({
|
|
466
|
-
id: "mysql/default@1",
|
|
467
|
-
target: "mysql",
|
|
468
|
-
capabilities: mysqlAdapterCapabilities,
|
|
469
|
-
readMarker: (queryable) => readMarkerResult(markerQuery(queryable), APP_SPACE_ID)
|
|
470
|
-
});
|
|
471
|
-
}
|
|
472
|
-
lower(ast, context) {
|
|
473
|
-
if (isDdlNode(ast)) throw structuredError("RUNTIME.DDL_UNSUPPORTED", "lower() does not lower DDL on the runtime adapter: DDL lowering belongs to the control adapter.", { meta: { surface: "runtime-adapter" } });
|
|
474
|
-
return renderMysqlSql(ast, context.contract, this.#codecs);
|
|
475
|
-
}
|
|
476
|
-
};
|
|
477
|
-
/** The MySQL runtime adapter: it lowers queries with the MySQL renderer and reads the marker 2b's control tables hold. */
|
|
478
|
-
function createMysqlAdapter(codecs) {
|
|
479
|
-
return Object.freeze(new MysqlAdapterImpl(codecs));
|
|
480
|
-
}
|
|
481
|
-
/** The `now()` generators of the MySQL date and time types: the SQL family's `timestampNow` for a `Date`, and the target's for every other value. */
|
|
482
|
-
function createMysqlMutationDefaultGenerators() {
|
|
483
|
-
return [timestampNowRuntimeGenerator(), ...mysqlNowGenerators.map(({ id, generate }) => ({
|
|
484
|
-
id,
|
|
485
|
-
generate,
|
|
486
|
-
stability: "query"
|
|
487
|
-
}))];
|
|
488
|
-
}
|
|
489
|
-
const mysqlRuntimeAdapterDescriptor = {
|
|
490
|
-
...mysqlAdapterDescriptorMeta,
|
|
491
|
-
codecs: () => Array.from(mysqlCodecDescriptorRegistry.values()),
|
|
492
|
-
mutationDefaultGenerators: createMysqlMutationDefaultGenerators,
|
|
493
|
-
rawCodecInferer: mysqlRawCodecInferer,
|
|
494
|
-
create(stack) {
|
|
495
|
-
return createMysqlAdapter(assembleMysqlCodecRegistry(stack.target, stack.extensions));
|
|
496
|
-
}
|
|
497
|
-
};
|
|
498
|
-
//#endregion
|
|
499
|
-
export { mysqlRuntimeAdapterDescriptor as default };
|
|
500
|
-
|
|
501
|
-
//# sourceMappingURL=adapter__runtime.mjs.map
|
|
1
|
+
import { n as mysqlRuntimeAdapterDescriptor, t as createMysqlRuntimeAdapterDescriptor } from "./runtime-Bw6vKz9t.mjs";
|
|
2
|
+
export { createMysqlRuntimeAdapterDescriptor, mysqlRuntimeAdapterDescriptor as default };
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { CodecRef } from "@prisma/orm-framework/components/codec";
|
|
2
|
+
import { JsonValue } from "@prisma/orm-framework/contract/types";
|
|
3
|
+
import { SqlAggregateLowering } from "@prisma/orm-family-sql/relational-core/aggregate-descriptor-registry";
|
|
4
|
+
//#region ../../../3-targets/mysql/1-mysql/1-target/dist/aggregates.d.mts
|
|
5
|
+
//#region src/core/aggregates.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Every aggregate overload the MySQL target contributes. The adapter lists these on `types.aggregateDescriptors`, from where emission derives result types and the runtime builds its resolution registry.
|
|
8
|
+
*/
|
|
9
|
+
declare const mysqlAggregateDescriptors: readonly [{
|
|
10
|
+
readonly operation: "count";
|
|
11
|
+
readonly input: {
|
|
12
|
+
readonly kind: "any";
|
|
13
|
+
};
|
|
14
|
+
readonly output: {
|
|
15
|
+
readonly kind: "codec";
|
|
16
|
+
readonly codecId: "mysql/bigintnumber@1";
|
|
17
|
+
};
|
|
18
|
+
readonly nullable: false;
|
|
19
|
+
readonly emptyResultWire: "0";
|
|
20
|
+
}, {
|
|
21
|
+
readonly operation: "countBigInt";
|
|
22
|
+
readonly input: {
|
|
23
|
+
readonly kind: "any";
|
|
24
|
+
};
|
|
25
|
+
readonly output: {
|
|
26
|
+
readonly kind: "codec";
|
|
27
|
+
readonly codecId: "mysql/bigint@1";
|
|
28
|
+
};
|
|
29
|
+
readonly nullable: false;
|
|
30
|
+
readonly emptyResultWire: "0";
|
|
31
|
+
readonly lower: SqlAggregateLowering;
|
|
32
|
+
}, ...({
|
|
33
|
+
readonly operation: "sum";
|
|
34
|
+
readonly input: {
|
|
35
|
+
readonly kind: "codec";
|
|
36
|
+
readonly codecId: "mysql/int@1" | "mysql/bigint@1" | "mysql/bigintnumber@1";
|
|
37
|
+
};
|
|
38
|
+
readonly output: {
|
|
39
|
+
readonly kind: "codec";
|
|
40
|
+
readonly codecId: "mysql/bigintnumber@1";
|
|
41
|
+
};
|
|
42
|
+
readonly nullable: true;
|
|
43
|
+
} | {
|
|
44
|
+
readonly lower: SqlAggregateLowering;
|
|
45
|
+
readonly operation: "sumBigInt";
|
|
46
|
+
readonly input: {
|
|
47
|
+
readonly kind: "codec";
|
|
48
|
+
readonly codecId: "mysql/int@1" | "mysql/bigint@1" | "mysql/bigintnumber@1";
|
|
49
|
+
};
|
|
50
|
+
readonly output: {
|
|
51
|
+
readonly kind: "codec";
|
|
52
|
+
readonly codecId: "mysql/bigint@1";
|
|
53
|
+
};
|
|
54
|
+
readonly nullable: true;
|
|
55
|
+
} | {
|
|
56
|
+
readonly lower: SqlAggregateLowering;
|
|
57
|
+
readonly operation: "avg";
|
|
58
|
+
readonly input: {
|
|
59
|
+
readonly kind: "codec";
|
|
60
|
+
readonly codecId: "mysql/int@1" | "mysql/bigint@1" | "mysql/bigintnumber@1";
|
|
61
|
+
};
|
|
62
|
+
readonly output: {
|
|
63
|
+
readonly kind: "codec";
|
|
64
|
+
readonly codecId: "mysql/double@1";
|
|
65
|
+
};
|
|
66
|
+
readonly nullable: true;
|
|
67
|
+
} | {
|
|
68
|
+
readonly operation: "sum";
|
|
69
|
+
readonly input: {
|
|
70
|
+
readonly kind: "codec";
|
|
71
|
+
readonly codecId: "mysql/double@1";
|
|
72
|
+
};
|
|
73
|
+
readonly output: {
|
|
74
|
+
readonly kind: "codec";
|
|
75
|
+
readonly codecId: "mysql/double@1";
|
|
76
|
+
};
|
|
77
|
+
readonly nullable: true;
|
|
78
|
+
} | {
|
|
79
|
+
readonly operation: "avg";
|
|
80
|
+
readonly input: {
|
|
81
|
+
readonly kind: "codec";
|
|
82
|
+
readonly codecId: "mysql/double@1";
|
|
83
|
+
};
|
|
84
|
+
readonly output: {
|
|
85
|
+
readonly kind: "codec";
|
|
86
|
+
readonly codecId: "mysql/double@1";
|
|
87
|
+
};
|
|
88
|
+
readonly nullable: true;
|
|
89
|
+
} | {
|
|
90
|
+
readonly operation: "min";
|
|
91
|
+
readonly input: {
|
|
92
|
+
readonly kind: "trait";
|
|
93
|
+
readonly trait: "numeric";
|
|
94
|
+
};
|
|
95
|
+
readonly output: {
|
|
96
|
+
readonly kind: "self";
|
|
97
|
+
};
|
|
98
|
+
readonly nullable: true;
|
|
99
|
+
} | {
|
|
100
|
+
readonly operation: "min";
|
|
101
|
+
readonly input: {
|
|
102
|
+
readonly kind: "trait";
|
|
103
|
+
readonly trait: "textual";
|
|
104
|
+
};
|
|
105
|
+
readonly output: {
|
|
106
|
+
readonly kind: "self";
|
|
107
|
+
};
|
|
108
|
+
readonly nullable: true;
|
|
109
|
+
} | {
|
|
110
|
+
readonly operation: "min";
|
|
111
|
+
readonly input: {
|
|
112
|
+
readonly kind: "codec";
|
|
113
|
+
readonly codecId: "mysql/datetime@1" | "mysql/datetime-temporal@1" | "mysql/datetime-string@1" | "mysql/timestamp-date@1" | "mysql/timestamp-temporal@1" | "mysql/timestamp-string@1" | "mysql/date-string@1" | "mysql/date-temporal@1" | "mysql/time-string@1" | "mysql/time-temporal@1";
|
|
114
|
+
};
|
|
115
|
+
readonly output: {
|
|
116
|
+
readonly kind: "self";
|
|
117
|
+
};
|
|
118
|
+
readonly nullable: true;
|
|
119
|
+
} | {
|
|
120
|
+
readonly operation: "max";
|
|
121
|
+
readonly input: {
|
|
122
|
+
readonly kind: "trait";
|
|
123
|
+
readonly trait: "numeric";
|
|
124
|
+
};
|
|
125
|
+
readonly output: {
|
|
126
|
+
readonly kind: "self";
|
|
127
|
+
};
|
|
128
|
+
readonly nullable: true;
|
|
129
|
+
} | {
|
|
130
|
+
readonly operation: "max";
|
|
131
|
+
readonly input: {
|
|
132
|
+
readonly kind: "trait";
|
|
133
|
+
readonly trait: "textual";
|
|
134
|
+
};
|
|
135
|
+
readonly output: {
|
|
136
|
+
readonly kind: "self";
|
|
137
|
+
};
|
|
138
|
+
readonly nullable: true;
|
|
139
|
+
} | {
|
|
140
|
+
readonly operation: "max";
|
|
141
|
+
readonly input: {
|
|
142
|
+
readonly kind: "codec";
|
|
143
|
+
readonly codecId: "mysql/datetime@1" | "mysql/datetime-temporal@1" | "mysql/datetime-string@1" | "mysql/timestamp-date@1" | "mysql/timestamp-temporal@1" | "mysql/timestamp-string@1" | "mysql/date-string@1" | "mysql/date-temporal@1" | "mysql/time-string@1" | "mysql/time-temporal@1";
|
|
144
|
+
};
|
|
145
|
+
readonly output: {
|
|
146
|
+
readonly kind: "self";
|
|
147
|
+
};
|
|
148
|
+
readonly nullable: true;
|
|
149
|
+
} | {
|
|
150
|
+
readonly operation: "sum";
|
|
151
|
+
readonly input: {
|
|
152
|
+
readonly kind: "codec";
|
|
153
|
+
readonly codecId: "mysql/decimal@1";
|
|
154
|
+
};
|
|
155
|
+
readonly output: {
|
|
156
|
+
readonly kind: "codec";
|
|
157
|
+
readonly codecId: "mysql/decimal@1";
|
|
158
|
+
readonly typeParams: (input: CodecRef | undefined) => JsonValue | undefined;
|
|
159
|
+
};
|
|
160
|
+
readonly nullable: true;
|
|
161
|
+
})[]];
|
|
162
|
+
//#endregion
|
|
163
|
+
export { mysqlAggregateDescriptors as t };
|
|
164
|
+
//# sourceMappingURL=aggregates-BK8qyA2x.d.mts.map
|