@prisma/orm-target-mysql 8.0.0-rc.24-dev.28 → 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-_c_DZuYR.mjs","names":[],"sources":["../../../../3-targets/mysql/1-mysql/1-target/dist/runtime.mjs"],"sourcesContent":["import { t as mysqlTargetDescriptorMetaRuntime } from \"./descriptor-meta-runtime-BaIF7fOE.mjs\";\nimport { t as mysqlNowGenerators } from \"./date-time-now-generators-Cx_aQTSw.mjs\";\nimport { t as MysqlContractSerializer } from \"./mysql-contract-serializer-D7NjmI2L.mjs\";\nimport { structuredError } from \"@internal/utils/structured-error\";\nimport { type } from \"arktype\";\n//#region src/core/runtime/runtime-target.ts\n/** The runtime target descriptor of MySQL, or of a target that extends it. */\nfunction createMysqlRuntimeTargetDescriptor(options) {\n\tconst { descriptorMeta } = options;\n\treturn {\n\t\t...descriptorMeta,\n\t\tcodecs: () => [],\n\t\tcreate() {\n\t\t\treturn {\n\t\t\t\tfamilyId: \"sql\",\n\t\t\t\ttargetId: descriptorMeta.targetId\n\t\t\t};\n\t\t}\n\t};\n}\nconst mysqlRuntimeTargetDescriptor = createMysqlRuntimeTargetDescriptor({ descriptorMeta: mysqlTargetDescriptorMetaRuntime });\n//#endregion\n//#region src/core/transaction-isolation.ts\nconst mysqlIsolationLevels = {\n\tReadUncommitted: \"ReadUncommitted\",\n\tReadCommitted: \"ReadCommitted\",\n\tRepeatableRead: \"RepeatableRead\",\n\tSerializable: \"Serializable\"\n};\nconst mysqlIsolationLevelSchema = type.enumerated(...Object.values(mysqlIsolationLevels));\nfunction validateMysqlIsolationLevel(value) {\n\tconst result = mysqlIsolationLevelSchema(value);\n\tif (result instanceof type.errors) throw structuredError(\"RUNTIME.ARGUMENT_INVALID\", \"Invalid transaction isolation level\", {\n\t\twhy: result.summary,\n\t\tfix: \"Use ReadUncommitted, ReadCommitted, RepeatableRead, or Serializable.\",\n\t\tmeta: {\n\t\t\targument: \"isolationLevel\",\n\t\t\treceived: value\n\t\t}\n\t});\n\treturn result;\n}\n//#endregion\nexport { MysqlContractSerializer, createMysqlRuntimeTargetDescriptor, mysqlRuntimeTargetDescriptor as default, mysqlIsolationLevelSchema, mysqlIsolationLevels, mysqlNowGenerators, validateMysqlIsolationLevel };\n\n//# sourceMappingURL=runtime.mjs.map"],"mappings":";;;;;AAOA,SAAS,mCAAmC,SAAS;CACpD,MAAM,EAAE,mBAAmB;CAC3B,OAAO;EACN,GAAG;EACH,cAAc,CAAC;EACf,SAAS;GACR,OAAO;IACN,UAAU;IACV,UAAU,eAAe;GAC1B;EACD;CACD;AACD;AACA,MAAM,+BAA+B,mCAAmC,EAAE,gBAAgB,iCAAiC,CAAC;AAG5H,MAAM,uBAAuB;CAC5B,iBAAiB;CACjB,eAAe;CACf,gBAAgB;CAChB,cAAc;AACf;AACA,MAAM,4BAA4B,KAAK,WAAW,GAAG,OAAO,OAAO,oBAAoB,CAAC;AACxF,SAAS,4BAA4B,OAAO;CAC3C,MAAM,SAAS,0BAA0B,KAAK;CAC9C,IAAI,kBAAkB,KAAK,QAAQ,MAAM,gBAAgB,4BAA4B,uCAAuC;EAC3H,KAAK,OAAO;EACZ,KAAK;EACL,MAAM;GACL,UAAU;GACV,UAAU;EACX;CACD,CAAC;CACD,OAAO;AACR"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { a as MysqlRuntimeTargetMeta } from "./runtime-Ci3hPz1j.mjs";
|
|
2
|
+
import { n as MysqlSqlRenderer, t as MysqlContract } from "./sql-renderer-fnDhRUHs-CcsyIaZ4.mjs";
|
|
3
|
+
import { i as MysqlCodecRegistry } from "./codecs-DTfUoamS.mjs";
|
|
4
|
+
import { Adapter, AdapterProfile, AnyQueryAst, LoweredStatement, LowererContext } from "@prisma/orm-family-sql/relational-core/ast";
|
|
5
|
+
import { RuntimeAdapterInstance } from "@prisma/orm-framework/components/execution";
|
|
6
|
+
import { SqlRuntimeAdapterDescriptor } from "@prisma/orm-family-sql/runtime";
|
|
7
|
+
//#region ../../../3-targets/mysql/1-mysql/2-adapter/dist/runtime.d.mts
|
|
8
|
+
//#region src/core/runtime/mysql-adapter.d.ts
|
|
9
|
+
/** What a target that extends MySQL changes in the runtime adapter: its target id, its capabilities, and the renderer that writes its SQL. The profile id is `<targetId>/default@1`. */
|
|
10
|
+
interface MysqlAdapterOptions<TargetId extends string> {
|
|
11
|
+
readonly targetId: TargetId;
|
|
12
|
+
readonly capabilities: AdapterProfile<TargetId>['capabilities'];
|
|
13
|
+
readonly renderer: MysqlSqlRenderer;
|
|
14
|
+
}
|
|
15
|
+
declare class MysqlAdapterImpl<TargetId extends string> implements Adapter<AnyQueryAst, MysqlContract, LoweredStatement> {
|
|
16
|
+
#private;
|
|
17
|
+
readonly familyId: "sql";
|
|
18
|
+
readonly targetId: TargetId;
|
|
19
|
+
readonly profile: AdapterProfile<TargetId>;
|
|
20
|
+
constructor(options: MysqlAdapterOptions<TargetId>);
|
|
21
|
+
lower(ast: AnyQueryAst, context: LowererContext<MysqlContract>): LoweredStatement;
|
|
22
|
+
}
|
|
23
|
+
/** The runtime adapter of MySQL, or of a target that extends it: it lowers queries with the renderer it is given and reads the marker the control tables hold. */
|
|
24
|
+
declare function createMysqlAdapter<TargetId extends string>(options: MysqlAdapterOptions<TargetId>): Readonly<MysqlAdapterImpl<TargetId>>;
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/core/runtime/runtime-adapter.d.ts
|
|
27
|
+
type MysqlRuntimeAdapterInstance<TargetId extends string = 'mysql'> = RuntimeAdapterInstance<'sql', TargetId> & ReturnType<typeof createMysqlAdapter<TargetId>>;
|
|
28
|
+
type MysqlRuntimeAdapterDescriptor<TargetId extends string = 'mysql'> = SqlRuntimeAdapterDescriptor<TargetId, MysqlRuntimeAdapterInstance<TargetId>>;
|
|
29
|
+
/** What a target that extends MySQL changes in the runtime adapter descriptor. */
|
|
30
|
+
interface MysqlRuntimeAdapterOptions<TargetId extends string> {
|
|
31
|
+
/** The adapter's metadata: everything but what the factory supplies. */
|
|
32
|
+
readonly descriptorMeta: Omit<MysqlRuntimeAdapterDescriptor<TargetId>, 'codecs' | 'mutationDefaultGenerators' | 'rawCodecInferer' | 'create'>;
|
|
33
|
+
/** The target's runtime metadata, whose id and display name the renderer's errors show. Its id is the adapter metadata's. */
|
|
34
|
+
readonly target: Pick<MysqlRuntimeTargetMeta<NoInfer<TargetId>>, 'targetId' | 'displayName'>;
|
|
35
|
+
/** Builds the renderer that writes the target's SQL. */
|
|
36
|
+
readonly renderer: (codecs: MysqlCodecRegistry, target: Pick<MysqlRuntimeTargetMeta<TargetId>, 'targetId' | 'displayName'>) => MysqlSqlRenderer;
|
|
37
|
+
}
|
|
38
|
+
/** The runtime adapter descriptor of MySQL, or of a target that extends it. Its profile id is `<targetId>/default@1`. */
|
|
39
|
+
declare function createMysqlRuntimeAdapterDescriptor<TargetId extends string>(options: MysqlRuntimeAdapterOptions<TargetId>): MysqlRuntimeAdapterDescriptor<TargetId>;
|
|
40
|
+
declare const mysqlRuntimeAdapterDescriptor: MysqlRuntimeAdapterDescriptor<"mysql">;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { mysqlRuntimeAdapterDescriptor as a, createMysqlRuntimeAdapterDescriptor as i, MysqlRuntimeAdapterInstance as n, MysqlRuntimeAdapterOptions as r, MysqlRuntimeAdapterDescriptor as t };
|
|
43
|
+
//# sourceMappingURL=runtime-dn4-kzZV.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-dn4-kzZV.d.mts","names":[],"sources":["../../../../3-targets/mysql/1-mysql/2-adapter/dist/runtime.d.mts"],"mappings":";;;;;;;;;UAQU,oBAAoB;WACnB,UAAU;WACV,cAAc,eAAe;WAC7B,UAAU;;cAEP,iBAAiB,oCAAoC,QAAQ,aAAa,eAAe;;WAE5F;WACA,UAAU;WACV,SAAS,eAAe;EACjC,YAAY,SAAS,oBAAoB;EACzC,MAAM,KAAK,aAAa,SAAS,eAAe,iBAAiB;;;iBAGlD,mBAAmB,yBAAyB,SAAS,oBAAoB,YAAY,SAAS,iBAAiB;;;KAG3H,4BAA4B,qCAAqC,8BAA8B,YAAY,kBAAkB,mBAAmB;KAChJ,8BAA8B,qCAAqC,4BAA4B,UAAU,4BAA4B;;UAEhI,2BAA2B;;WAE1B,gBAAgB,KAAK,8BAA8B;;WAEnD,QAAQ,KAAK,uBAAuB,QAAQ;;WAE5C,WAAW,QAAQ,oBAAoB,QAAQ,KAAK,uBAAuB,2CAA2C;;;iBAGhH,oCAAoC,yBAAyB,SAAS,2BAA2B,YAAY,8BAA8B;cAC9I,+BAA+B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./sql-renderer-fnDhRUHs-CcsyIaZ4.mjs";
|
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
import { l as mysqlError } from "./errors-CWtFTnst-xBLJ-9Lp.mjs";
|
|
2
|
+
import { n as quoteIdentifier, t as escapeLiteral } from "./sql-utils-CveZhawQ-B2QmUlY0.mjs";
|
|
3
|
+
import { t as tokenizeMysqlSql } from "./sql-utils-DVH8boEI.mjs";
|
|
4
|
+
import { structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
5
|
+
import { collectOrderedParamRefs } from "@prisma/orm-family-sql/relational-core/ast";
|
|
6
|
+
import { InternalError, assertNever } from "@prisma/orm-framework/utils/internal-error";
|
|
7
|
+
//#region ../../../3-targets/mysql/1-mysql/2-adapter/dist/sql-renderer-DfPaqPkD.mjs
|
|
8
|
+
/** Refuses a lowered statement unless every placeholder is a numbered `?N` naming one of its parameters and every parameter has a placeholder. */
|
|
9
|
+
function assertPlaceholdersMatchParams(sql, paramCount) {
|
|
10
|
+
const tokens = tokenizeMysqlSql(sql).filter((token) => token.kind === "placeholder");
|
|
11
|
+
const placeholders = tokens.map((token) => token.text);
|
|
12
|
+
const numbers = tokens.map((token) => token.number ?? NaN);
|
|
13
|
+
if (numbers.every((number) => number >= 1 && number <= paramCount) && new Set(numbers).size === paramCount) return;
|
|
14
|
+
throw structuredError("RUNTIME.PARAM_PLACEHOLDER_MISMATCH", `The SQL has placeholders ${JSON.stringify(placeholders)} for ${paramCount} value(s); each value needs its own numbered placeholder, and the SQL may contain no other placeholder.`, {
|
|
15
|
+
why: "A placeholder that does not match a parameter binds a value to the wrong place in the statement, or leaves a value unbound.",
|
|
16
|
+
fix: "Pass values into raw SQL through interpolation rather than writing a `?` in the SQL text.",
|
|
17
|
+
meta: {
|
|
18
|
+
placeholders,
|
|
19
|
+
params: paramCount
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const ARTICLED_STATEMENT = {
|
|
24
|
+
insert: "an insert",
|
|
25
|
+
update: "an update",
|
|
26
|
+
delete: "a delete"
|
|
27
|
+
};
|
|
28
|
+
/** 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. */
|
|
29
|
+
const PROPOSED_ROW = quoteIdentifier("new");
|
|
30
|
+
/**
|
|
31
|
+
* 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`.
|
|
32
|
+
*/
|
|
33
|
+
const GROUP_CONCAT_HINT = "/*+ SET_VAR(group_concat_max_len = 4294967295) */";
|
|
34
|
+
/** MySQL's documented way to write an `OFFSET` with no `LIMIT`: the largest row count it takes. */
|
|
35
|
+
const NO_LIMIT = "18446744073709551615";
|
|
36
|
+
const BINARY_OPERATORS = {
|
|
37
|
+
eq: "=",
|
|
38
|
+
neq: "<>",
|
|
39
|
+
isNotDistinctFrom: "<=>",
|
|
40
|
+
gt: ">",
|
|
41
|
+
lt: "<",
|
|
42
|
+
gte: ">=",
|
|
43
|
+
lte: "<=",
|
|
44
|
+
like: "LIKE",
|
|
45
|
+
in: "IN",
|
|
46
|
+
notIn: "NOT IN"
|
|
47
|
+
};
|
|
48
|
+
/** 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. */
|
|
49
|
+
const OVERSIZED_ARRAY_TEXT = "CONCAT('array larger than max_allowed_packet: ', COUNT(*), ' rows')";
|
|
50
|
+
const ORDER_DIRECTION = {
|
|
51
|
+
asc: "ASC",
|
|
52
|
+
desc: "DESC"
|
|
53
|
+
};
|
|
54
|
+
/** A NULLS FIRST or NULLS LAST placement, which MySQL lacks, as a leading `IS NULL` sort key. */
|
|
55
|
+
const NULLS_KEY_DIRECTION = {
|
|
56
|
+
first: "DESC",
|
|
57
|
+
last: "ASC"
|
|
58
|
+
};
|
|
59
|
+
function nodeKind(value) {
|
|
60
|
+
return typeof value === "object" && value !== null && "kind" in value ? String(value.kind) : "unknown";
|
|
61
|
+
}
|
|
62
|
+
function invalid(node, message) {
|
|
63
|
+
return mysqlError("RUNTIME.AST_INVALID", message, { meta: { node } });
|
|
64
|
+
}
|
|
65
|
+
/** Whether an operand must be parenthesised before an operator is written after it. A new expression kind fails to compile here until someone decides. */
|
|
66
|
+
function needsGrouping(expr) {
|
|
67
|
+
switch (expr.kind) {
|
|
68
|
+
case "operation":
|
|
69
|
+
case "subquery": return true;
|
|
70
|
+
case "column-ref":
|
|
71
|
+
case "identifier-ref":
|
|
72
|
+
case "aggregate":
|
|
73
|
+
case "window-func":
|
|
74
|
+
case "function-call":
|
|
75
|
+
case "cast":
|
|
76
|
+
case "case":
|
|
77
|
+
case "json-object":
|
|
78
|
+
case "json-array-agg":
|
|
79
|
+
case "binary":
|
|
80
|
+
case "and":
|
|
81
|
+
case "or":
|
|
82
|
+
case "exists":
|
|
83
|
+
case "null-check":
|
|
84
|
+
case "not":
|
|
85
|
+
case "param-ref":
|
|
86
|
+
case "prepared-param-ref":
|
|
87
|
+
case "literal":
|
|
88
|
+
case "list":
|
|
89
|
+
case "raw-expr": return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** Refuses the expression a codec wrapped a parameter in unless it holds that parameter exactly once: a parameter dropped or repeated would leave the statement's placeholders out of step with its values. */
|
|
93
|
+
function assertWrapsParameterOnce(wrapped, parameter, codec) {
|
|
94
|
+
const parameters = wrapped.collectParamRefs();
|
|
95
|
+
if (parameters.length === 1 && parameters[0] === parameter) return;
|
|
96
|
+
throw structuredError("RUNTIME.CODEC_DESCRIPTOR_INVALID", `Codec "${codec.codecId}" wraps a value of this query in an expression that does not hold that value exactly once.`, {
|
|
97
|
+
why: "A codec descriptor wraps a parameter in an expression, such as a cast, that holds the parameter exactly once, so each value of the statement keeps its placeholder.",
|
|
98
|
+
fix: `Return the parameter itself, or one expression around it, from the wrapParameter method of codec "${codec.codecId}", or from wrappedParameter where its descriptor extends MysqlCodecDescriptor.`,
|
|
99
|
+
meta: {
|
|
100
|
+
codecId: codec.codecId,
|
|
101
|
+
parameters: parameters.length
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 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. It is built with the target it renders for, whose id its errors carry and whose display name its messages show. A target that extends MySQL subclasses it and overrides the protected methods where its SQL or its messages differ.
|
|
107
|
+
*/
|
|
108
|
+
var MysqlSqlRenderer = class {
|
|
109
|
+
codecs;
|
|
110
|
+
target;
|
|
111
|
+
constructor(codecs, target) {
|
|
112
|
+
this.codecs = codecs;
|
|
113
|
+
this.target = target;
|
|
114
|
+
}
|
|
115
|
+
render(ast, contract) {
|
|
116
|
+
const placeholderNumbers = /* @__PURE__ */ new Map();
|
|
117
|
+
const params = collectOrderedParamRefs(ast).map((ref, index) => {
|
|
118
|
+
placeholderNumbers.set(ref, index + 1);
|
|
119
|
+
return ref.kind === "prepared-param-ref" ? {
|
|
120
|
+
kind: "bind",
|
|
121
|
+
name: ref.name
|
|
122
|
+
} : {
|
|
123
|
+
kind: "literal",
|
|
124
|
+
value: ref.value
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
const ctx = {
|
|
128
|
+
contract,
|
|
129
|
+
codecs: this.codecs,
|
|
130
|
+
placeholderNumbers,
|
|
131
|
+
uses: { groupConcat: false }
|
|
132
|
+
};
|
|
133
|
+
const rendered = this.renderStatement(ast, ctx);
|
|
134
|
+
const sql = ctx.uses.groupConcat ? this.withGroupConcatHint(ast, rendered) : rendered;
|
|
135
|
+
assertPlaceholdersMatchParams(sql, params.length);
|
|
136
|
+
return Object.freeze({
|
|
137
|
+
sql,
|
|
138
|
+
params
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/** How an upsert names the row it proposes: MySQL declares it `AS new` and reads `new`.`column`. */
|
|
142
|
+
proposedRow() {
|
|
143
|
+
return {
|
|
144
|
+
alias: PROPOSED_ROW,
|
|
145
|
+
column: (quotedColumn) => `${PROPOSED_ROW}.${quotedColumn}`
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/** Why `RETURNING` on `statement` is refused: MySQL has none, so the SQL family's ORM reads written rows back with a select when the contract does not report `returning`. */
|
|
149
|
+
returningRefusal(statement) {
|
|
150
|
+
return `${this.target.displayName} cannot return the rows ${ARTICLED_STATEMENT[statement]} writes; it has no RETURNING`;
|
|
151
|
+
}
|
|
152
|
+
/** Why an ordered JSON array is refused, or `undefined` where the renderer builds it, as MySQL's does. */
|
|
153
|
+
orderedJsonArrayRefusal() {}
|
|
154
|
+
/** Why an update or delete whose `SET` or `WHERE` reads `table`, the table it writes, is refused, or `undefined` where the database runs it. MySQL refuses it with error 1093. The only form MySQL accepts reads the table through a derived table, which copies the table and locks every row it copies, so concurrent writes can deadlock; the renderer does not write it. */
|
|
155
|
+
writtenTableReadRefusal(table) {
|
|
156
|
+
return `${this.target.displayName} cannot run an UPDATE or DELETE whose filter or values read the table being written, ${table}`;
|
|
157
|
+
}
|
|
158
|
+
/** 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. */
|
|
159
|
+
withGroupConcatHint(ast, rendered) {
|
|
160
|
+
if (ast.kind !== "select" || !rendered.startsWith("SELECT ")) throw this.unsupported("ordered-array-outside-select", `${this.target.displayName} can build an ordered JSON array only in a SELECT statement, whose outermost SELECT carries the hint that raises group_concat_max_len`);
|
|
161
|
+
return `SELECT ${GROUP_CONCAT_HINT} ${rendered.slice(7)}`;
|
|
162
|
+
}
|
|
163
|
+
renderStatement(ast, ctx) {
|
|
164
|
+
switch (ast.kind) {
|
|
165
|
+
case "select": return this.renderSelect(ast, ctx);
|
|
166
|
+
case "raw-query": return this.renderParts(ast.parts, ctx);
|
|
167
|
+
case "insert": return this.renderInsert(ast, ctx);
|
|
168
|
+
case "update": return this.renderUpdate(ast, ctx);
|
|
169
|
+
case "delete": return this.renderDelete(ast, ctx);
|
|
170
|
+
default: throw new InternalError(`Unsupported AST node kind: ${nodeKind(ast)}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
unsupported(feature, message, guidance) {
|
|
174
|
+
return mysqlError("RUNTIME.AST_UNSUPPORTED", message, {
|
|
175
|
+
...guidance,
|
|
176
|
+
meta: {
|
|
177
|
+
target: this.target.targetId,
|
|
178
|
+
feature
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
refuseReturning(returning, statement) {
|
|
183
|
+
if (returning !== void 0 && returning.length > 0) throw this.unsupported("returning", this.returningRefusal(statement));
|
|
184
|
+
}
|
|
185
|
+
renderInsertValue(value, ctx) {
|
|
186
|
+
if (value === void 0 || value.kind === "default-value") return "DEFAULT";
|
|
187
|
+
return this.renderExpr(value, ctx);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* 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.
|
|
191
|
+
*/
|
|
192
|
+
renderInsert(ast, ctx) {
|
|
193
|
+
this.refuseReturning(ast.returning, "insert");
|
|
194
|
+
if (ast.rows.length === 0) throw invalid("insert", "INSERT requires at least one row");
|
|
195
|
+
const table = this.qualifyTable(ast.table, ctx);
|
|
196
|
+
const insertCtx = {
|
|
197
|
+
...ctx,
|
|
198
|
+
insertInto: {
|
|
199
|
+
alias: ast.table.alias ?? ast.table.name,
|
|
200
|
+
name: table
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
const columns = [...new Set(ast.rows.flatMap((row) => Object.keys(row)))];
|
|
204
|
+
const values = ast.rows.map((row) => `(${columns.map((column) => this.renderInsertValue(row[column], insertCtx)).join(", ")})`).join(", ");
|
|
205
|
+
const insert = `INSERT INTO ${table} (${columns.map(quoteIdentifier).join(", ")}) VALUES ${values}`;
|
|
206
|
+
const conflict = ast.onConflict;
|
|
207
|
+
if (conflict === void 0) return insert;
|
|
208
|
+
const action = conflict.action;
|
|
209
|
+
switch (action.kind) {
|
|
210
|
+
case "do-nothing": throw this.unsupported("insert-on-conflict-skip", `${this.target.displayName} cannot skip a conflicting row without also hiding other errors: INSERT IGNORE turns foreign-key and NOT NULL errors into warnings`);
|
|
211
|
+
case "do-update-set": {
|
|
212
|
+
if (conflict.columns.length > 0) throw this.unsupported("insert-on-conflict-target", `${this.target.displayName} cannot limit ON DUPLICATE KEY UPDATE to named conflict columns: it fires on any unique key`);
|
|
213
|
+
const assignments = Object.entries(action.set);
|
|
214
|
+
if (assignments.length === 0) throw invalid("insert-on-conflict", "An upsert requires at least one column to update");
|
|
215
|
+
const set = assignments.map(([column, value]) => `${quoteIdentifier(column)} = ${this.renderExpr(value, insertCtx)}`).join(", ");
|
|
216
|
+
const { alias } = this.proposedRow();
|
|
217
|
+
return `${insert}${alias === void 0 ? "" : ` AS ${alias}`} ON DUPLICATE KEY UPDATE ${set}`;
|
|
218
|
+
}
|
|
219
|
+
default: return assertNever(action, `Unsupported conflict action: ${nodeKind(action)}`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
renderUpdate(ast, ctx) {
|
|
223
|
+
this.refuseReturning(ast.returning, "update");
|
|
224
|
+
const assignments = Object.entries(ast.set);
|
|
225
|
+
if (assignments.length === 0) throw invalid("update", "UPDATE requires at least one column to set");
|
|
226
|
+
const target = this.renderTableSource(ast.table, ctx);
|
|
227
|
+
const writeCtx = this.writing(ast.table, ctx);
|
|
228
|
+
return `UPDATE ${target} SET ${assignments.map(([column, value]) => `${quoteIdentifier(column)} = ${this.renderExpr(value, writeCtx)}`).join(", ")}${ast.where ? ` WHERE ${this.renderExpr(ast.where, writeCtx)}` : ""}`;
|
|
229
|
+
}
|
|
230
|
+
renderDelete(ast, ctx) {
|
|
231
|
+
this.refuseReturning(ast.returning, "delete");
|
|
232
|
+
return `DELETE FROM ${this.renderTableSource(ast.table, ctx)}${ast.where ? ` WHERE ${this.renderExpr(ast.where, this.writing(ast.table, ctx))}` : ""}`;
|
|
233
|
+
}
|
|
234
|
+
writing(table, ctx) {
|
|
235
|
+
return {
|
|
236
|
+
...ctx,
|
|
237
|
+
writtenTable: this.qualifyTable(table, ctx)
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
renderLimitOffset(keyword, value, ctx) {
|
|
241
|
+
if (value === void 0) return "";
|
|
242
|
+
if (typeof value === "number") return `${keyword} ${value}`;
|
|
243
|
+
return `${keyword} ${value.kind === "param-ref" || value.kind === "prepared-param-ref" ? this.placeholder(value, ctx) : this.renderExpr(value, ctx)}`;
|
|
244
|
+
}
|
|
245
|
+
renderSelect(ast, ctx) {
|
|
246
|
+
if (ast.locking !== void 0 && ast.locking.length > 0) throw this.unsupported("locking-clause", `Row locks are not supported on ${this.target.displayName} yet, so a select cannot carry a locking clause such as FOR UPDATE`);
|
|
247
|
+
if (ast.distinctOn !== void 0 && ast.distinctOn.length > 0) throw this.unsupported("distinct-on", `${this.target.displayName} has no DISTINCT ON`);
|
|
248
|
+
return [
|
|
249
|
+
`SELECT ${ast.distinct ? "DISTINCT " : ""}${this.renderProjection(ast.projection, ctx)}`,
|
|
250
|
+
ast.from === void 0 ? "" : `FROM ${this.renderSource(ast.from, ctx)}`,
|
|
251
|
+
ast.joins?.length ? ast.joins.map((join) => this.renderJoin(join, ctx)).join(" ") : "",
|
|
252
|
+
ast.where ? `WHERE ${this.renderExpr(ast.where, ctx)}` : "",
|
|
253
|
+
ast.groupBy?.length ? `GROUP BY ${ast.groupBy.map((e) => this.renderExpr(e, ctx)).join(", ")}` : "",
|
|
254
|
+
ast.having ? `HAVING ${this.renderExpr(ast.having, ctx)}` : "",
|
|
255
|
+
ast.orderBy?.length ? `ORDER BY ${this.renderOrderByItems(ast.orderBy, ctx)}` : "",
|
|
256
|
+
ast.limit === void 0 && ast.offset !== void 0 ? `LIMIT ${NO_LIMIT}` : this.renderLimitOffset("LIMIT", ast.limit, ctx),
|
|
257
|
+
this.renderLimitOffset("OFFSET", ast.offset, ctx)
|
|
258
|
+
].filter((part) => part.length > 0).join(" ");
|
|
259
|
+
}
|
|
260
|
+
renderProjection(projection, ctx) {
|
|
261
|
+
return projection.map((item) => `${this.renderExpr(item.expr, ctx)} AS ${quoteIdentifier(item.alias)}`).join(", ");
|
|
262
|
+
}
|
|
263
|
+
qualifyTable(table, ctx) {
|
|
264
|
+
if (table.namespaceId === void 0) return quoteIdentifier(table.name);
|
|
265
|
+
if (ctx.contract === void 0) throw new InternalError(`Table "${table.name}" carries namespace "${table.namespaceId}" but no contract was supplied to resolve it`);
|
|
266
|
+
const namespace = ctx.contract.storage.namespaces[table.namespaceId];
|
|
267
|
+
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: {
|
|
268
|
+
table: table.name,
|
|
269
|
+
namespaceId: table.namespaceId,
|
|
270
|
+
reason: namespace === void 0 ? "not-present" : "not-materialised"
|
|
271
|
+
} });
|
|
272
|
+
return namespace.qualifyTable(table.name);
|
|
273
|
+
}
|
|
274
|
+
renderTableSource(source, ctx) {
|
|
275
|
+
const qualified = this.qualifyTable(source, ctx);
|
|
276
|
+
return source.alias ? `${qualified} AS ${quoteIdentifier(source.alias)}` : qualified;
|
|
277
|
+
}
|
|
278
|
+
renderSource(source, ctx) {
|
|
279
|
+
switch (source.kind) {
|
|
280
|
+
case "table-source": {
|
|
281
|
+
const qualified = this.qualifyTable(source, ctx);
|
|
282
|
+
const refusal = qualified === ctx.writtenTable ? this.writtenTableReadRefusal(qualified) : void 0;
|
|
283
|
+
if (refusal !== void 0) throw this.unsupported("write-reads-written-table", refusal, {
|
|
284
|
+
why: `${this.target.displayName} refuses such a statement with its error 1093.`,
|
|
285
|
+
fix: "Read the keys of the rows, and any values the write takes from this table, with a query first. Then update or delete those rows by key, writing those values; for a variant, one row at a time with update or delete. The filter is not checked again when the rows are written."
|
|
286
|
+
});
|
|
287
|
+
return this.renderTableSource(source, ctx);
|
|
288
|
+
}
|
|
289
|
+
case "derived-table-source": return `(${this.renderSelect(source.query, ctx)}) AS ${quoteIdentifier(source.alias)}`;
|
|
290
|
+
case "function-source": throw this.unsupported("function-source", `${this.target.displayName} cannot select from the set-returning function ${source.fn}`);
|
|
291
|
+
default: return assertNever(source, `Unsupported source node kind: ${nodeKind(source)}`);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
renderExpr(expr, ctx) {
|
|
295
|
+
switch (expr.kind) {
|
|
296
|
+
case "column-ref": return this.renderColumn(expr, ctx);
|
|
297
|
+
case "identifier-ref": return quoteIdentifier(expr.name);
|
|
298
|
+
case "operation": return this.renderOperation(expr, ctx);
|
|
299
|
+
case "subquery": return this.renderSubquery(expr, ctx);
|
|
300
|
+
case "aggregate": return this.renderAggregate(expr, ctx);
|
|
301
|
+
case "window-func": return this.renderWindowFunc(expr, ctx);
|
|
302
|
+
case "function-call": return this.renderFunctionCall(expr, ctx);
|
|
303
|
+
case "cast": return this.renderCast(expr, ctx);
|
|
304
|
+
case "case": return this.renderCase(expr, ctx);
|
|
305
|
+
case "json-object": return this.renderJsonObject(expr, ctx);
|
|
306
|
+
case "json-array-agg": return this.renderJsonArrayAgg(expr, ctx);
|
|
307
|
+
case "binary": return this.renderBinary(expr, ctx);
|
|
308
|
+
case "and": return expr.exprs.length === 0 ? "TRUE" : `(${expr.exprs.map((part) => this.renderExpr(part, ctx)).join(" AND ")})`;
|
|
309
|
+
case "or": return expr.exprs.length === 0 ? "FALSE" : `(${expr.exprs.map((part) => this.renderExpr(part, ctx)).join(" OR ")})`;
|
|
310
|
+
case "exists": return `${expr.notExists ? "NOT " : ""}EXISTS (${this.renderSelect(expr.subquery, ctx)})`;
|
|
311
|
+
case "null-check": return this.renderNullCheck(expr, ctx);
|
|
312
|
+
case "not": return `NOT (${this.renderExpr(expr.expr, ctx)})`;
|
|
313
|
+
case "param-ref":
|
|
314
|
+
case "prepared-param-ref": return this.renderParam(expr, ctx);
|
|
315
|
+
case "literal": return this.renderLiteral(expr);
|
|
316
|
+
case "list": return this.renderList(expr, ctx);
|
|
317
|
+
case "raw-expr": return this.renderParts(expr.parts, ctx);
|
|
318
|
+
default: return assertNever(expr, `Unsupported expression node kind: ${nodeKind(expr)}`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
/** 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`. */
|
|
322
|
+
assertNoDigitAfterParam(parts) {
|
|
323
|
+
parts.forEach((part, index) => {
|
|
324
|
+
const next = parts[index + 1];
|
|
325
|
+
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 would become part of the value's placeholder", {
|
|
326
|
+
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.",
|
|
327
|
+
fix: "Put a space or an operator between the interpolated value and the digit.",
|
|
328
|
+
meta: {
|
|
329
|
+
reason: "digit-after-value",
|
|
330
|
+
part: index + 1
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
renderParts(parts, ctx) {
|
|
336
|
+
this.assertNoDigitAfterParam(parts);
|
|
337
|
+
return parts.map((part) => {
|
|
338
|
+
if (typeof part === "string") return part;
|
|
339
|
+
switch (part.kind) {
|
|
340
|
+
case "select": return this.renderSelect(part, ctx);
|
|
341
|
+
case "insert": return this.renderInsert(part, ctx);
|
|
342
|
+
case "update": return this.renderUpdate(part, ctx);
|
|
343
|
+
case "delete": return this.renderDelete(part, ctx);
|
|
344
|
+
default: return this.renderExpr(part, ctx);
|
|
345
|
+
}
|
|
346
|
+
}).join("");
|
|
347
|
+
}
|
|
348
|
+
renderColumn(ref, ctx) {
|
|
349
|
+
const column = quoteIdentifier(ref.column);
|
|
350
|
+
const { insertInto } = ctx;
|
|
351
|
+
if (insertInto !== void 0) {
|
|
352
|
+
if (ref.table === "excluded") return this.proposedRow().column(column);
|
|
353
|
+
if (ref.table === insertInto.alias) return `${insertInto.name}.${column}`;
|
|
354
|
+
}
|
|
355
|
+
return `${quoteIdentifier(ref.table)}.${column}`;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* 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.
|
|
359
|
+
*/
|
|
360
|
+
renderLiteral(expr) {
|
|
361
|
+
const { value } = expr;
|
|
362
|
+
if (value === null || value === void 0) return "NULL";
|
|
363
|
+
if (typeof value === "number") {
|
|
364
|
+
if (!Number.isFinite(value)) throw this.unsupported("non-finite-number", `${this.target.displayName} has no literal for ${value}`);
|
|
365
|
+
return String(value);
|
|
366
|
+
}
|
|
367
|
+
if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
|
|
368
|
+
if (typeof value === "bigint") return String(value);
|
|
369
|
+
const kind = value instanceof Date ? "date" : Array.isArray(value) ? "array" : typeof value;
|
|
370
|
+
throw this.unsupported("value-literal", `Prisma writes only numbers, booleans and NULL into ${this.target.displayName} SQL as literals, and this query has ${/^[aeiou]/.test(kind) ? "an" : "a"} ${kind} literal; pass the value as a parameter instead`);
|
|
371
|
+
}
|
|
372
|
+
/** Renders each `{{self}}` and `{{argN}}` where the template writes it. */
|
|
373
|
+
renderOperation(expr, ctx) {
|
|
374
|
+
return expr.lowering.template.replace(/\{\{(self|arg(\d+))\}\}/g, (_match, _name, index) => {
|
|
375
|
+
if (index === void 0) return this.renderExpr(expr.self, ctx);
|
|
376
|
+
const arg = expr.args[Number(index)];
|
|
377
|
+
return arg === void 0 ? "" : this.renderExpr(arg, ctx);
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
renderSubquery(expr, ctx, columns = 1) {
|
|
381
|
+
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" } });
|
|
382
|
+
return `(${this.renderSelect(expr.query, ctx)})`;
|
|
383
|
+
}
|
|
384
|
+
grouped(expr, ctx) {
|
|
385
|
+
const rendered = this.renderExpr(expr, ctx);
|
|
386
|
+
return needsGrouping(expr) ? `(${rendered})` : rendered;
|
|
387
|
+
}
|
|
388
|
+
renderNullCheck(expr, ctx) {
|
|
389
|
+
return `${this.grouped(expr.expr, ctx)} ${expr.isNull ? "IS NULL" : "IS NOT NULL"}`;
|
|
390
|
+
}
|
|
391
|
+
renderBinary(expr, ctx) {
|
|
392
|
+
if (expr.right.kind === "list" && expr.right.values.length === 0) {
|
|
393
|
+
if (expr.op === "in") return "FALSE";
|
|
394
|
+
if (expr.op === "notIn") return "TRUE";
|
|
395
|
+
}
|
|
396
|
+
const left = this.grouped(expr.left, ctx);
|
|
397
|
+
const right = expr.right.kind === "subquery" && expr.left.kind === "list" ? this.renderSubquery(expr.right, ctx, expr.left.values.length) : this.renderExpr(expr.right, ctx);
|
|
398
|
+
if (expr.op === "isDistinctFrom") return `NOT (${left} <=> ${right})`;
|
|
399
|
+
return `${left} ${BINARY_OPERATORS[expr.op]} ${right}`;
|
|
400
|
+
}
|
|
401
|
+
renderList(expr, ctx) {
|
|
402
|
+
if (expr.values.length === 0) return "(NULL)";
|
|
403
|
+
return `(${expr.values.map((value) => this.renderExpr(value, ctx)).join(", ")})`;
|
|
404
|
+
}
|
|
405
|
+
renderAggregate(expr, ctx) {
|
|
406
|
+
const fn = expr.fn.toUpperCase();
|
|
407
|
+
return expr.expr ? `${fn}(${this.renderExpr(expr.expr, ctx)})` : `${fn}(*)`;
|
|
408
|
+
}
|
|
409
|
+
renderWindowFunc(expr, ctx) {
|
|
410
|
+
const args = expr.args.map((arg) => this.renderExpr(arg, ctx)).join(", ");
|
|
411
|
+
const over = [expr.partitionBy?.length ? `PARTITION BY ${expr.partitionBy.map((e) => this.renderExpr(e, ctx)).join(", ")}` : "", expr.orderBy?.length ? `ORDER BY ${this.renderOrderByItems(expr.orderBy, ctx)}` : ""].filter((part) => part.length > 0).join(" ");
|
|
412
|
+
return `${expr.fn.toUpperCase()}(${args}) OVER (${over})`;
|
|
413
|
+
}
|
|
414
|
+
renderFunctionCall(expr, ctx) {
|
|
415
|
+
return `${expr.fn}(${expr.args.map((arg) => this.renderExpr(arg, ctx)).join(", ")})`;
|
|
416
|
+
}
|
|
417
|
+
renderCast(expr, ctx) {
|
|
418
|
+
return `CAST(${this.renderExpr(expr.expr, ctx)} AS ${expr.targetType})`;
|
|
419
|
+
}
|
|
420
|
+
renderCase(expr, ctx) {
|
|
421
|
+
return `CASE ${expr.branches.map((branch) => `WHEN ${this.renderExpr(branch.condition, ctx)} THEN ${this.renderExpr(branch.value, ctx)}`).join(" ")}${expr.elseExpr === void 0 ? "" : ` ELSE ${this.renderExpr(expr.elseExpr, ctx)}`} END`;
|
|
422
|
+
}
|
|
423
|
+
descriptorOf(codec, ctx, use) {
|
|
424
|
+
const descriptor = ctx.codecs.descriptorFor(codec.codecId);
|
|
425
|
+
if (descriptor === void 0) throw structuredError("RUNTIME.PARAM_REF_MISSING_CODEC", `${use} uses codec "${codec.codecId}", which no extension given to the client provides.`, {
|
|
426
|
+
fix: `Add the extension that provides codec "${codec.codecId}" to the client's \`extensions\`.`,
|
|
427
|
+
meta: { codecId: codec.codecId }
|
|
428
|
+
});
|
|
429
|
+
return descriptor;
|
|
430
|
+
}
|
|
431
|
+
placeholder(ref, ctx) {
|
|
432
|
+
const number = ctx.placeholderNumbers.get(ref);
|
|
433
|
+
if (number === void 0) throw new InternalError("A param was written that the AST does not collect");
|
|
434
|
+
return `?${number}`;
|
|
435
|
+
}
|
|
436
|
+
/** A param as its numbered placeholder, in the expression its codec wraps it in, refusing one whose codec the MySQL registry lacks. */
|
|
437
|
+
renderParam(ref, ctx) {
|
|
438
|
+
const placeholder = this.placeholder(ref, ctx);
|
|
439
|
+
if (ref.codec === void 0 || ctx.wrappedParameter === ref) return placeholder;
|
|
440
|
+
const wrapped = this.descriptorOf(ref.codec, ctx, "A value in this query").wrapParameter(ref, ref.codec);
|
|
441
|
+
if (wrapped === ref) return placeholder;
|
|
442
|
+
assertWrapsParameterOnce(wrapped, ref, ref.codec);
|
|
443
|
+
const rendered = this.renderExpr(wrapped, {
|
|
444
|
+
...ctx,
|
|
445
|
+
wrappedParameter: ref
|
|
446
|
+
});
|
|
447
|
+
return wrapped.kind === "function-call" || wrapped.kind === "cast" ? rendered : `(${rendered})`;
|
|
448
|
+
}
|
|
449
|
+
projectThroughCodec(value, codec, ctx) {
|
|
450
|
+
return this.descriptorOf(codec, ctx, "A column this query reads in an include").projectJson(value, codec);
|
|
451
|
+
}
|
|
452
|
+
renderJsonValue(projection, ctx) {
|
|
453
|
+
return projection.accept({
|
|
454
|
+
codec: ({ value, codec }) => this.renderExpr(this.projectThroughCodec(value, codec, ctx), ctx),
|
|
455
|
+
native: ({ value }) => this.renderExpr(value, ctx),
|
|
456
|
+
document: ({ value }) => this.renderExpr(value, ctx)
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
renderJsonObject(expr, ctx) {
|
|
460
|
+
return `JSON_OBJECT(${expr.entries.flatMap((entry) => [`'${escapeLiteral(entry.key)}'`, this.renderJsonValue(entry.value, ctx)]).join(", ")})`;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* 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.
|
|
464
|
+
*/
|
|
465
|
+
renderJsonElementText(projection, ctx) {
|
|
466
|
+
const rendered = this.renderJsonValue(projection, ctx);
|
|
467
|
+
return projection.kind === "document" ? rendered : `JSON_EXTRACT(JSON_ARRAY(${rendered}), '$[0]')`;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* `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.
|
|
471
|
+
*/
|
|
472
|
+
renderJsonArrayAgg(expr, ctx) {
|
|
473
|
+
if (expr.orderBy === void 0) {
|
|
474
|
+
const aggregated = `JSON_ARRAYAGG(${this.renderJsonValue(expr.expr, ctx)})`;
|
|
475
|
+
return expr.onEmpty === "emptyArray" ? `COALESCE(${aggregated}, JSON_ARRAY())` : aggregated;
|
|
476
|
+
}
|
|
477
|
+
const refusal = this.orderedJsonArrayRefusal();
|
|
478
|
+
if (refusal !== void 0) throw this.unsupported("ordered-json-array", refusal);
|
|
479
|
+
ctx.uses.groupConcat = true;
|
|
480
|
+
const text = `CONCAT('[', GROUP_CONCAT(${this.renderJsonElementText(expr.expr, ctx)} ORDER BY ${this.renderOrderByItems(expr.orderBy, ctx)} SEPARATOR ','), ']')`;
|
|
481
|
+
return `CASE WHEN COUNT(*) = 0 THEN ${expr.onEmpty === "emptyArray" ? "JSON_ARRAY()" : "NULL"} ELSE CAST(COALESCE(${text}, ${OVERSIZED_ARRAY_TEXT}) AS JSON) END`;
|
|
482
|
+
}
|
|
483
|
+
renderOrderByItem(item, ctx) {
|
|
484
|
+
return `${item.nulls === void 0 ? "" : `${this.grouped(item.expr, ctx)} IS NULL ${NULLS_KEY_DIRECTION[item.nulls]}, `}${this.renderExpr(item.expr, ctx)} ${ORDER_DIRECTION[item.dir]}`;
|
|
485
|
+
}
|
|
486
|
+
renderOrderByItems(items, ctx) {
|
|
487
|
+
return items.map((item) => this.renderOrderByItem(item, ctx)).join(", ");
|
|
488
|
+
}
|
|
489
|
+
renderJoin(join, ctx) {
|
|
490
|
+
if (join.joinType === "full") throw this.unsupported("full-join", `${this.target.displayName} has no FULL JOIN`);
|
|
491
|
+
if (join.lateral) throw this.unsupported("lateral-join", `LATERAL joins are not supported on ${this.target.displayName} yet`);
|
|
492
|
+
return `${join.joinType.toUpperCase()} JOIN ${this.renderSource(join.source, ctx)} ON ${this.renderJoinOn(join.on, ctx)}`;
|
|
493
|
+
}
|
|
494
|
+
renderJoinOn(on, ctx) {
|
|
495
|
+
return on.kind === "eq-col-join-on" ? `${this.renderColumn(on.left, ctx)} = ${this.renderColumn(on.right, ctx)}` : this.renderExpr(on, ctx);
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
//#endregion
|
|
499
|
+
export { MysqlSqlRenderer as t };
|
|
500
|
+
|
|
501
|
+
//# sourceMappingURL=sql-renderer-DfPaqPkD-DFaweHvr.mjs.map
|