@prisma/orm-family-sql 8.0.0-rc.1-dev.41 → 8.0.0-rc.1-dev.43
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/{aggregate-descriptor-registry-DSap8YyW.mjs → aggregate-descriptor-registry-CTo0ry7h.mjs} +2 -2
- package/dist/{aggregate-descriptor-registry-DSap8YyW.mjs.map → aggregate-descriptor-registry-CTo0ry7h.mjs.map} +1 -1
- package/dist/{ast-B-eeN74F.mjs → ast-BJdOHZrL.mjs} +2 -2
- package/dist/{ast-B-eeN74F.mjs.map → ast-BJdOHZrL.mjs.map} +1 -1
- package/dist/{ast-DRbUiQ-9.d.mts → ast-D8qqdDX_.d.mts} +5 -82
- package/dist/ast-D8qqdDX_.d.mts.map +1 -0
- package/dist/builder.d.mts +2 -2
- package/dist/builder__runtime.d.mts +6 -6
- package/dist/builder__runtime.mjs +2 -2
- package/dist/builder__types.d.mts +2 -2
- package/dist/{control-DI9DC2AS.d.mts → control-DssujEJW.d.mts} +7 -6
- package/dist/control-DssujEJW.d.mts.map +1 -0
- package/dist/{control-adapter-C99J7aEF-DsxImHyk.d.mts → control-adapter-C99J7aEF-Vx9xXYOy.d.mts} +5 -4
- package/dist/control-adapter-C99J7aEF-Vx9xXYOy.d.mts.map +1 -0
- package/dist/control-adapter-CLID4Q6Z.d.mts +1 -0
- package/dist/{db-C5jmOFPM-BGm-QfKd.d.mts → db-C5jmOFPM-Cd-fni61.d.mts} +6 -6
- package/dist/{db-C5jmOFPM-BGm-QfKd.d.mts.map → db-C5jmOFPM-Cd-fni61.d.mts.map} +1 -1
- package/dist/{ddl-types-CnLSuwXa-Bv46yIe9.d.mts → ddl-types-BtT82FGO-Du_-9SlZ.d.mts} +3 -3
- package/dist/{ddl-types-CnLSuwXa-Bv46yIe9.d.mts.map → ddl-types-BtT82FGO-Du_-9SlZ.d.mts.map} +1 -1
- package/dist/{diff-DVvZXmFv.d.mts → diff-pl1Xal4J.d.mts} +3 -3
- package/dist/{diff-DVvZXmFv.d.mts.map → diff-pl1Xal4J.d.mts.map} +1 -1
- package/dist/driver-types-BQtRkOJ0-Bv2RPSfr.d.mts +81 -0
- package/dist/driver-types-BQtRkOJ0-Bv2RPSfr.d.mts.map +1 -0
- package/dist/{expression-CYVKobXp.mjs → expression-D30W-gkF.mjs} +2 -2
- package/dist/{expression-CYVKobXp.mjs.map → expression-D30W-gkF.mjs.map} +1 -1
- package/dist/{expression-D7H1kyVG.d.mts → expression-Q_yaDQPb.d.mts} +2 -2
- package/dist/{expression-D7H1kyVG.d.mts.map → expression-Q_yaDQPb.d.mts.map} +1 -1
- package/dist/family.d.mts +7 -7
- package/dist/family__control-adapter.d.mts +2 -2
- package/dist/family__control.d.mts +2 -2
- package/dist/family__diff.d.mts +2 -2
- package/dist/family__migration.d.mts +1 -1
- package/dist/family__runtime.d.mts +1 -1
- package/dist/index-DIHXLCbY.d.mts +84 -0
- package/dist/index-DIHXLCbY.d.mts.map +1 -0
- package/dist/{middleware-Bp5oIYM0-Ek8bISDH.d.mts → middleware-BS7u8VFR-DyUcAFid.d.mts} +3 -3
- package/dist/{middleware-Bp5oIYM0-Ek8bISDH.d.mts.map → middleware-BS7u8VFR-DyUcAFid.d.mts.map} +1 -1
- package/dist/middleware-Cy_OqpBi.d.mts +1 -0
- package/dist/{migration-Dtymew3g.d.mts → migration-CGlaINey.d.mts} +2 -2
- package/dist/{migration-Dtymew3g.d.mts.map → migration-CGlaINey.d.mts.map} +1 -1
- package/dist/orm-client.d.mts +7 -7
- package/dist/orm-client.mjs +32 -49
- package/dist/orm-client.mjs.map +1 -1
- package/dist/{plan-DfLDIdep-6R1mLkcW.d.mts → plan-BC_trt1i-In5gOKCT.d.mts} +3 -3
- package/dist/plan-BC_trt1i-In5gOKCT.d.mts.map +1 -0
- package/dist/plan-DrOMooQt.d.mts +2 -0
- package/dist/prepared-query-BDLztUzY-CaDR0Rqc.mjs +14 -0
- package/dist/prepared-query-BDLztUzY-CaDR0Rqc.mjs.map +1 -0
- package/dist/{index-Ddquditw.d.mts → prepared-statement-z9bBbTph-BlzhaRTY.d.mts} +96 -142
- package/dist/prepared-statement-z9bBbTph-BlzhaRTY.d.mts.map +1 -0
- package/dist/query-lane-context-D62vkQhf.d.mts +1 -0
- package/dist/{query-lane-context-DyDSQVS--CyCznt67.d.mts → query-lane-context-gwWUcacE-DdWNrc8q.d.mts} +3 -3
- package/dist/{query-lane-context-DyDSQVS--CyCznt67.d.mts.map → query-lane-context-gwWUcacE-DdWNrc8q.d.mts.map} +1 -1
- package/dist/relational-core.d.mts +12 -11
- package/dist/relational-core.mjs +3 -3
- package/dist/relational-core__aggregate-descriptor-registry.d.mts +1 -1
- package/dist/relational-core__aggregate-descriptor-registry.mjs +1 -1
- package/dist/relational-core__ast.d.mts +4 -3
- package/dist/relational-core__ast.mjs +2 -2
- package/dist/relational-core__codec-descriptor-registry.d.mts +2 -2
- package/dist/relational-core__contract-free.d.mts +2 -2
- package/dist/relational-core__contract-free.mjs +1 -1
- package/dist/relational-core__contract-free.mjs.map +1 -1
- package/dist/relational-core__expression.d.mts +1 -1
- package/dist/relational-core__expression.mjs +1 -1
- package/dist/relational-core__middleware.d.mts +2 -2
- package/dist/relational-core__plan.d.mts +3 -3
- package/dist/relational-core__query-lane-context.d.mts +2 -2
- package/dist/relational-core__types.d.mts +2 -2
- package/dist/{runtime-CjXCGPS4.d.mts → runtime-cPrAp99G.d.mts} +3 -2
- package/dist/runtime-cPrAp99G.d.mts.map +1 -0
- package/dist/runtime.d.mts +5 -4
- package/dist/runtime.mjs +187 -130
- package/dist/runtime.mjs.map +1 -1
- package/dist/runtime__internal__prepared-query.d.mts +2 -0
- package/dist/runtime__internal__prepared-query.mjs +2 -0
- package/dist/{sql-execution-plan-qxvHnFcA-HjRSS3l9.d.mts → sql-execution-plan-D0ZTnszb-DnCRtfQO.d.mts} +3 -3
- package/dist/sql-execution-plan-D0ZTnszb-DnCRtfQO.d.mts.map +1 -0
- package/dist/types-0c4HyrXd.d.mts +1 -0
- package/dist/{types-CSP6WmWn-DVuxsZJW.mjs → types-B7_v-z12-De5tf8LE.mjs} +3 -3
- package/dist/types-B7_v-z12-De5tf8LE.mjs.map +1 -0
- package/dist/{types-CLN9Y3BH-BHUrV7MD.d.mts → types-C9FZXc9Q-C6LM1k-O.d.mts} +14 -11
- package/dist/types-C9FZXc9Q-C6LM1k-O.d.mts.map +1 -0
- package/dist/{types-ZzeQKmYD-kI_QWHEx.d.mts → types-DH6Sqzxu-DfzaLX0o.d.mts} +3 -3
- package/dist/{types-ZzeQKmYD-kI_QWHEx.d.mts.map → types-DH6Sqzxu-DfzaLX0o.d.mts.map} +1 -1
- package/dist/{types-IqZMLrFC-Dk3bHKmk.d.mts → types-IqZMLrFC-B0YziCVx.d.mts} +2 -2
- package/dist/{types-IqZMLrFC-Dk3bHKmk.d.mts.map → types-IqZMLrFC-B0YziCVx.d.mts.map} +1 -1
- package/package.json +19 -18
- package/dist/ast-DRbUiQ-9.d.mts.map +0 -1
- package/dist/control-DI9DC2AS.d.mts.map +0 -1
- package/dist/control-adapter-BdOcXTOm.d.mts +0 -1
- package/dist/control-adapter-C99J7aEF-DsxImHyk.d.mts.map +0 -1
- package/dist/index-Ddquditw.d.mts.map +0 -1
- package/dist/middleware-aFpB1ZhU.d.mts +0 -1
- package/dist/plan-DfLDIdep-6R1mLkcW.d.mts.map +0 -1
- package/dist/plan-HWPzzUxh.d.mts +0 -2
- package/dist/query-lane-context-qfJzguc9.d.mts +0 -1
- package/dist/runtime-CjXCGPS4.d.mts.map +0 -1
- package/dist/sql-execution-plan-qxvHnFcA-HjRSS3l9.d.mts.map +0 -1
- package/dist/types-4u1EPYY6.d.mts +0 -1
- package/dist/types-CLN9Y3BH-BHUrV7MD.d.mts.map +0 -1
- package/dist/types-CSP6WmWn-DVuxsZJW.mjs.map +0 -1
package/dist/orm-client.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as resolveStorageTable } from "./resolve-storage-table-DZsfnzeW.mjs";
|
|
2
2
|
import { i as isUniqueConstraintViolation } from "./dist-x6jvtkKM.mjs";
|
|
3
|
-
import { C as LiteralExpr, D as OrExpr, F as SubqueryExpr, I as TableSource, L as UpdateAst, O as OrderByItem, P as SelectAst, R as WindowFuncExpr, S as ListExpression, T as NullCheckExpr, U as isWhereExpr, V as isAggregateFn, _ as InsertAst, b as JsonArrayAggExpr, c as DeleteAst, f as EqColJoinOn, j as ProjectionItem, k as ParamRef, l as DerivedTableSource, n as AndExpr, o as ColumnRef, p as ExistsExpr, r as BinaryExpr, s as DefaultValueExpr, t as AggregateExpr, v as InsertOnConflict, w as NotExpr, x as JsonObjectExpr, y as JoinAst } from "./types-
|
|
3
|
+
import { C as LiteralExpr, D as OrExpr, F as SubqueryExpr, I as TableSource, L as UpdateAst, O as OrderByItem, P as SelectAst, R as WindowFuncExpr, S as ListExpression, T as NullCheckExpr, U as isWhereExpr, V as isAggregateFn, _ as InsertAst, b as JsonArrayAggExpr, c as DeleteAst, f as EqColJoinOn, j as ProjectionItem, k as ParamRef, l as DerivedTableSource, n as AndExpr, o as ColumnRef, p as ExistsExpr, r as BinaryExpr, s as DefaultValueExpr, t as AggregateExpr, v as InsertOnConflict, w as NotExpr, x as JsonObjectExpr, y as JoinAst } from "./types-B7_v-z12-De5tf8LE.mjs";
|
|
4
4
|
import { t as collectOrderedParamRefs } from "./util-DQQgv2j1-D6INZaRG.mjs";
|
|
5
|
-
import { n as JsonDocumentProjection, r as NativeJsonValueProjection, t as CodecJsonValueProjection } from "./ast-
|
|
5
|
+
import { n as JsonDocumentProjection, r as NativeJsonValueProjection, t as CodecJsonValueProjection } from "./ast-BJdOHZrL.mjs";
|
|
6
6
|
import { n as codecRefForStorageColumn } from "./codec-descriptor-registry-N0dhtKaH.mjs";
|
|
7
7
|
import { structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
8
8
|
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
@@ -547,9 +547,6 @@ async function acquireRuntimeScope(runtime) {
|
|
|
547
547
|
};
|
|
548
548
|
return { scope: connection };
|
|
549
549
|
}
|
|
550
|
-
function executeQueryPlan(scope, plan) {
|
|
551
|
-
return scope.execute(plan);
|
|
552
|
-
}
|
|
553
550
|
function deriveParamsFromAst(ast) {
|
|
554
551
|
return { params: collectOrderedParamRefs(ast).map((p) => p.kind === "param-ref" ? p.value : void 0) };
|
|
555
552
|
}
|
|
@@ -1790,6 +1787,9 @@ function compileSelectWithIncludes(contract, aggregates, namespaceId, tableName,
|
|
|
1790
1787
|
const { params } = deriveParamsFromAst(ast);
|
|
1791
1788
|
return buildOrmQueryPlan(contract, ast, params, state.annotations);
|
|
1792
1789
|
}
|
|
1790
|
+
function queryPlanRows(scope, plan) {
|
|
1791
|
+
return scope.query(plan);
|
|
1792
|
+
}
|
|
1793
1793
|
function emptyState() {
|
|
1794
1794
|
return {
|
|
1795
1795
|
filters: [],
|
|
@@ -1885,7 +1885,7 @@ function dispatchCollectionRows(options) {
|
|
|
1885
1885
|
const { context, runtime, state, tableName, modelName, namespaceId } = options;
|
|
1886
1886
|
const { contract } = context;
|
|
1887
1887
|
const polyInfo = resolvePolymorphismInfo(contract, namespaceId, modelName);
|
|
1888
|
-
if (state.includes.length === 0) return mapResultRows(
|
|
1888
|
+
if (state.includes.length === 0) return mapResultRows(queryPlanRows(runtime, compileSelect(contract, namespaceId, tableName, state, modelName)), polyInfo ? (rawRow) => blindCast(mapPolymorphicRow(contract, namespaceId, modelName, polyInfo, rawRow, state.variantName)) : (rawRow) => blindCast(mapStorageRowToModelFields(contract, namespaceId, modelName, rawRow)));
|
|
1889
1889
|
return dispatchWithIncludes(options);
|
|
1890
1890
|
}
|
|
1891
1891
|
function dispatchWithIncludes(options) {
|
|
@@ -1894,7 +1894,7 @@ function dispatchWithIncludes(options) {
|
|
|
1894
1894
|
const generator = async function* () {
|
|
1895
1895
|
const { scope, release } = await acquireRuntimeScope(runtime);
|
|
1896
1896
|
try {
|
|
1897
|
-
const parentRowsRaw = await
|
|
1897
|
+
const parentRowsRaw = await queryPlanRows(scope, compileSelectWithIncludes(contract, context.aggregateDescriptors, namespaceId, tableName, state, modelName)).toArray();
|
|
1898
1898
|
if (parentRowsRaw.length === 0) return;
|
|
1899
1899
|
const polyInfo = resolvePolymorphismInfo(contract, namespaceId, modelName);
|
|
1900
1900
|
const parentRows = parentRowsRaw.map((row) => {
|
|
@@ -2211,13 +2211,13 @@ function dispatchMutationRows(options) {
|
|
|
2211
2211
|
const { context, runtime, compiled, tableName, modelName, namespaceId, variantName, includes, selectedFields, hiddenColumns, mapRow } = options;
|
|
2212
2212
|
const { contract } = context;
|
|
2213
2213
|
const mapStorageRow = createMutationRowMapper(contract, namespaceId, modelName, variantName);
|
|
2214
|
-
if (includes.length === 0) return mapResultRows(
|
|
2214
|
+
if (includes.length === 0) return mapResultRows(queryPlanRows(runtime, compiled), (rawRow) => {
|
|
2215
2215
|
const mapped = mapStorageRow(rawRow);
|
|
2216
2216
|
if (hiddenColumns.length > 0) stripHiddenMappedFields(contract, namespaceId, modelName, mapped, hiddenColumns);
|
|
2217
2217
|
return mapRow(mapped);
|
|
2218
2218
|
});
|
|
2219
2219
|
const generator = async function* () {
|
|
2220
|
-
const identityRows = await
|
|
2220
|
+
const identityRows = await queryPlanRows(runtime, compiled).toArray();
|
|
2221
2221
|
yield* reloadMutationRowsByIdentities({
|
|
2222
2222
|
context,
|
|
2223
2223
|
runtime,
|
|
@@ -2238,7 +2238,7 @@ function dispatchSplitMutationRows(options) {
|
|
|
2238
2238
|
const generator = async function* () {
|
|
2239
2239
|
if (includes.length > 0) {
|
|
2240
2240
|
const identityRows = [];
|
|
2241
|
-
for (const plan of plans) identityRows.push(...await
|
|
2241
|
+
for (const plan of plans) identityRows.push(...await queryPlanRows(runtime, plan).toArray());
|
|
2242
2242
|
yield* reloadMutationRowsByIdentities({
|
|
2243
2243
|
context,
|
|
2244
2244
|
runtime,
|
|
@@ -2251,7 +2251,7 @@ function dispatchSplitMutationRows(options) {
|
|
|
2251
2251
|
});
|
|
2252
2252
|
return;
|
|
2253
2253
|
}
|
|
2254
|
-
for (const plan of plans) for await (const rawRow of
|
|
2254
|
+
for (const plan of plans) for await (const rawRow of queryPlanRows(runtime, plan)) {
|
|
2255
2255
|
const mapped = mapStorageRow(rawRow);
|
|
2256
2256
|
if (hiddenColumns.length > 0) stripHiddenMappedFields(contract, namespaceId, modelName, mapped, hiddenColumns);
|
|
2257
2257
|
yield mapRow(mapped);
|
|
@@ -2264,13 +2264,13 @@ async function executeMutationReturningSingleRow(options) {
|
|
|
2264
2264
|
const { contract } = context;
|
|
2265
2265
|
const mapStorageRow = createMutationRowMapper(contract, namespaceId, modelName, variantName);
|
|
2266
2266
|
if (includes.length === 0) {
|
|
2267
|
-
const first = (await
|
|
2267
|
+
const first = (await queryPlanRows(runtime, compiled).toArray())[0];
|
|
2268
2268
|
if (!first) return null;
|
|
2269
2269
|
const mapped = mapStorageRow(first);
|
|
2270
2270
|
if (hiddenColumns.length > 0) stripHiddenMappedFields(contract, namespaceId, modelName, mapped, hiddenColumns);
|
|
2271
2271
|
return mapRow(mapped);
|
|
2272
2272
|
}
|
|
2273
|
-
const identityRows = await
|
|
2273
|
+
const identityRows = await queryPlanRows(runtime, compiled).toArray();
|
|
2274
2274
|
if (identityRows.length === 0) return null;
|
|
2275
2275
|
for await (const row of reloadMutationRowsByIdentities({
|
|
2276
2276
|
context,
|
|
@@ -2386,7 +2386,7 @@ var GroupedCollection = class GroupedCollection {
|
|
|
2386
2386
|
if (meta.annotations.size > 0) annotationsMap = meta.annotations;
|
|
2387
2387
|
}
|
|
2388
2388
|
const compiled = mergeAnnotations(compileGroupedAggregate(this.contract, this.ctx.context.aggregateDescriptors, this.namespaceId, this.tableName, this.baseFilters, this.groupByColumns, aggregateSpec, combineWhereExprs(this.havingFilters)), annotationsMap);
|
|
2389
|
-
return (await
|
|
2389
|
+
return (await queryPlanRows(this.ctx.runtime, compiled).toArray()).map((row) => {
|
|
2390
2390
|
const mapped = mapStorageRowToModelFields(this.contract, this.namespaceId, this.modelName, row);
|
|
2391
2391
|
for (const [alias] of aggregateEntries) mapped[alias] = row[alias];
|
|
2392
2392
|
return mapped;
|
|
@@ -2916,7 +2916,7 @@ async function updateFirstGraph(scope, context, namespaceId, modelName, filters,
|
|
|
2916
2916
|
for (const def of appliedUpdateDefaults) mappedUpdateData[def.column] = def.value;
|
|
2917
2917
|
const pkWhere = shorthandToWhereExpr(context, namespaceId, modelName, castAs(buildPrimaryKeyFilterFromRow(contract, namespaceId, modelName, existingRow)));
|
|
2918
2918
|
if (!pkWhere) throw new InternalError(`Failed to build primary key filter for model "${modelName}"`);
|
|
2919
|
-
const updatedRaw = (await
|
|
2919
|
+
const updatedRaw = (await queryPlanRows(scope, compileUpdateReturning(contract, namespaceId, tableName, mappedUpdateData, [pkWhere], void 0)).toArray())[0];
|
|
2920
2920
|
if (updatedRaw) parentRow = mapStorageRowToModelFields(contract, namespaceId, modelName, updatedRaw);
|
|
2921
2921
|
}
|
|
2922
2922
|
for (const relationMutation of childOwned) await applyChildOwnedMutation(scope, context, namespaceId, modelName, parentRow, relationMutation.relation, relationMutation.mutation);
|
|
@@ -3184,7 +3184,7 @@ async function insertJunctionLink(scope, context, relation, parentPkValues, targ
|
|
|
3184
3184
|
for (const def of applied) junctionRow[def.column] = def.value;
|
|
3185
3185
|
const compiled = compileInsertCount(context.contract, through.namespaceId, through.table, [junctionRow]);
|
|
3186
3186
|
try {
|
|
3187
|
-
await
|
|
3187
|
+
await scope.execute(compiled);
|
|
3188
3188
|
} catch (error) {
|
|
3189
3189
|
if (mutationKind === "connect" && isUniqueConstraintViolation(error)) throw ormError("ORM.RELATION_LINK_DUPLICATE", `connect() nested mutation for relation "${relation.relationName}" violated a unique constraint on junction "${through.table}"; the junction link may already be present`, {
|
|
3190
3190
|
meta: {
|
|
@@ -3205,7 +3205,8 @@ async function deleteJunctionLink(scope, context, relation, parentPkValues, targ
|
|
|
3205
3205
|
for (const [column, value] of Object.entries(junctionRow)) exprs.push(BinaryExpr.eq(ColumnRef.of(through.table, column), LiteralExpr.of(value)));
|
|
3206
3206
|
const first = exprs[0];
|
|
3207
3207
|
const where = exprs.length === 1 && first !== void 0 ? first : and(...exprs);
|
|
3208
|
-
|
|
3208
|
+
const compiled = compileDeleteCount(context.contract, through.namespaceId, through.table, [where]);
|
|
3209
|
+
await scope.execute(compiled);
|
|
3209
3210
|
}
|
|
3210
3211
|
function readParentColumnValues(contract, parentNamespaceId, parentModelName, relation, parentRow) {
|
|
3211
3212
|
const values = /* @__PURE__ */ new Map();
|
|
@@ -3238,7 +3239,7 @@ async function insertSingleRow(scope, context, namespaceId, modelName, data) {
|
|
|
3238
3239
|
values: mappedData
|
|
3239
3240
|
});
|
|
3240
3241
|
for (const def of applied) mappedData[def.column] = def.value;
|
|
3241
|
-
const firstRow = (await
|
|
3242
|
+
const firstRow = (await queryPlanRows(scope, compileInsertReturning(contract, namespaceId, tableName, [mappedData], void 0)).toArray())[0];
|
|
3242
3243
|
if (!firstRow) throw ormError("ORM.MUTATION_ROW_MISSING", `Nested create for model "${modelName}" did not return a row`, { meta: {
|
|
3243
3244
|
operation: "create",
|
|
3244
3245
|
model: modelName,
|
|
@@ -3254,7 +3255,7 @@ async function findRowByCriterion(scope, context, namespaceId, modelName, criter
|
|
|
3254
3255
|
model: modelName,
|
|
3255
3256
|
problem: "empty-criterion"
|
|
3256
3257
|
} });
|
|
3257
|
-
const firstRow = (await
|
|
3258
|
+
const firstRow = (await queryPlanRows(scope, compileSelect(contract, namespaceId, resolveModelTableName(contract, namespaceId, modelName), {
|
|
3258
3259
|
...emptyState(),
|
|
3259
3260
|
filters: [whereExpr],
|
|
3260
3261
|
limit: 1
|
|
@@ -3263,7 +3264,7 @@ async function findRowByCriterion(scope, context, namespaceId, modelName, criter
|
|
|
3263
3264
|
return mapStorageRowToModelFields(contract, namespaceId, modelName, firstRow);
|
|
3264
3265
|
}
|
|
3265
3266
|
async function findFirstByFilters(scope, contract, namespaceId, modelName, filters) {
|
|
3266
|
-
const firstRow = (await
|
|
3267
|
+
const firstRow = (await queryPlanRows(scope, compileSelect(contract, namespaceId, resolveModelTableName(contract, namespaceId, modelName), {
|
|
3267
3268
|
...emptyState(),
|
|
3268
3269
|
filters,
|
|
3269
3270
|
limit: 1
|
|
@@ -3272,7 +3273,8 @@ async function findFirstByFilters(scope, contract, namespaceId, modelName, filte
|
|
|
3272
3273
|
return mapStorageRowToModelFields(contract, namespaceId, modelName, firstRow);
|
|
3273
3274
|
}
|
|
3274
3275
|
async function executeUpdateCount(scope, contract, namespaceId, tableName, setValues, filters) {
|
|
3275
|
-
|
|
3276
|
+
const compiled = compileUpdateCount(contract, namespaceId, tableName, setValues, filters);
|
|
3277
|
+
await scope.execute(compiled);
|
|
3276
3278
|
}
|
|
3277
3279
|
const relationDefsCache = /* @__PURE__ */ new WeakMap();
|
|
3278
3280
|
function getRelationDefinitions(contract, namespaceId, modelName) {
|
|
@@ -3808,7 +3810,7 @@ var CollectionImpl = class CollectionImpl {
|
|
|
3808
3810
|
} });
|
|
3809
3811
|
const annotationsMap = this.#collectAnnotationsFromMeta(configure, "read", "aggregate");
|
|
3810
3812
|
const compiled = mergeAnnotations(compileAggregate(this.contract, this.ctx.context.aggregateDescriptors, this.namespaceId, this.tableName, this.state.filters, aggregateSpec), annotationsMap);
|
|
3811
|
-
const row = (await
|
|
3813
|
+
const row = (await queryPlanRows(this.ctx.runtime, compiled).toArray())[0] ?? {};
|
|
3812
3814
|
const result = {};
|
|
3813
3815
|
for (const [alias, selector] of entries) result[alias] = row[alias] ?? this.#emptyAggregateValue(selector);
|
|
3814
3816
|
return blindCast(result);
|
|
@@ -3966,7 +3968,7 @@ var CollectionImpl = class CollectionImpl {
|
|
|
3966
3968
|
}
|
|
3967
3969
|
yield blindCast(await withMutationScope(runtime, async (scope) => {
|
|
3968
3970
|
applyCreateDefaults(collectionCtx, namespaceId, tableName, [baseRow]);
|
|
3969
|
-
const baseCreated = (await
|
|
3971
|
+
const baseCreated = (await queryPlanRows(scope, compileInsertReturning(contract, namespaceId, tableName, [baseRow], void 0)).toArray())[0];
|
|
3970
3972
|
if (!baseCreated) throw ormError("ORM.MUTATION_ROW_MISSING", `MTI base INSERT for model "${modelName}" did not return a row`, { meta: {
|
|
3971
3973
|
operation: "create",
|
|
3972
3974
|
model: modelName,
|
|
@@ -3976,7 +3978,7 @@ var CollectionImpl = class CollectionImpl {
|
|
|
3976
3978
|
const pkValue = baseCreated[pkColumn];
|
|
3977
3979
|
variantRow[pkColumn] = pkValue;
|
|
3978
3980
|
applyCreateDefaults(collectionCtx, namespaceId, variant.table, [variantRow]);
|
|
3979
|
-
const variantCreated = (await
|
|
3981
|
+
const variantCreated = (await queryPlanRows(scope, compileInsertReturning(contract, namespaceId, variant.table, [variantRow], void 0)).toArray())[0];
|
|
3980
3982
|
if (!variantCreated) throw ormError("ORM.MUTATION_ROW_MISSING", `MTI variant INSERT for model "${modelName}" into "${variant.table}" did not return a row`, { meta: {
|
|
3981
3983
|
operation: "create",
|
|
3982
3984
|
model: modelName,
|
|
@@ -4048,11 +4050,11 @@ var CollectionImpl = class CollectionImpl {
|
|
|
4048
4050
|
applyCreateDefaults(this.ctx, this.namespaceId, this.tableName, mappedRows);
|
|
4049
4051
|
if (this.contract.capabilities?.["sql"]?.["defaultInInsert"] !== true) {
|
|
4050
4052
|
const plans = compileInsertCountSplit(this.contract, this.namespaceId, this.tableName, mappedRows).map((plan) => mergeAnnotations(plan, annotationsMap));
|
|
4051
|
-
for (const plan of plans) await
|
|
4053
|
+
for (const plan of plans) await this.ctx.runtime.execute(plan);
|
|
4052
4054
|
return data.length;
|
|
4053
4055
|
}
|
|
4054
4056
|
const compiled = mergeAnnotations(compileInsertCount(this.contract, this.namespaceId, this.tableName, mappedRows), annotationsMap);
|
|
4055
|
-
await
|
|
4057
|
+
await this.ctx.runtime.execute(compiled);
|
|
4056
4058
|
return data.length;
|
|
4057
4059
|
}
|
|
4058
4060
|
/**
|
|
@@ -4260,18 +4262,8 @@ var CollectionImpl = class CollectionImpl {
|
|
|
4260
4262
|
if (Object.keys(mappedData).length === 0) return 0;
|
|
4261
4263
|
applyUpdateDefaults(this.ctx, this.namespaceId, this.tableName, mappedData);
|
|
4262
4264
|
const annotationsMap = this.#collectAnnotationsFromMeta(configure, "write", "updateAndCount");
|
|
4263
|
-
const primaryKeyColumn = resolvePrimaryKeyColumn(this.contract, this.namespaceId, this.tableName);
|
|
4264
|
-
const countState = {
|
|
4265
|
-
...emptyState(),
|
|
4266
|
-
filters: this.state.filters,
|
|
4267
|
-
selectedFields: [primaryKeyColumn],
|
|
4268
|
-
variantName: this.state.variantName
|
|
4269
|
-
};
|
|
4270
|
-
const countCompiled = compileSelect(this.contract, this.namespaceId, this.tableName, countState, this.modelName);
|
|
4271
|
-
const matchingRows = await executeQueryPlan(this.ctx.runtime, countCompiled).toArray();
|
|
4272
4265
|
const compiled = mergeAnnotations(compileUpdateCount(this.contract, this.namespaceId, this.tableName, mappedData, this.state.filters, this.state.variantName, this.modelName), annotationsMap);
|
|
4273
|
-
await
|
|
4274
|
-
return matchingRows.length;
|
|
4266
|
+
return (await this.ctx.runtime.execute(compiled)).affectedRows;
|
|
4275
4267
|
}
|
|
4276
4268
|
/**
|
|
4277
4269
|
* Write terminal: delete a single matching row — the first one the
|
|
@@ -4370,7 +4362,8 @@ var CollectionImpl = class CollectionImpl {
|
|
|
4370
4362
|
modelName: collection.modelName,
|
|
4371
4363
|
namespaceId: collection.namespaceId
|
|
4372
4364
|
}).toArray();
|
|
4373
|
-
|
|
4365
|
+
const deletePlan = mergeAnnotations(compileDeleteCount(collection.contract, collection.namespaceId, collection.tableName, collection.state.filters, collection.state.variantName, collection.modelName), annotationsMap);
|
|
4366
|
+
await scope.execute(deletePlan);
|
|
4374
4367
|
return rows;
|
|
4375
4368
|
});
|
|
4376
4369
|
for (const row of snapshot) yield row;
|
|
@@ -4391,18 +4384,8 @@ var CollectionImpl = class CollectionImpl {
|
|
|
4391
4384
|
*/
|
|
4392
4385
|
async deleteAndCount(configure) {
|
|
4393
4386
|
const annotationsMap = this.#collectAnnotationsFromMeta(configure, "write", "deleteAndCount");
|
|
4394
|
-
const primaryKeyColumn = resolvePrimaryKeyColumn(this.contract, this.namespaceId, this.tableName);
|
|
4395
|
-
const countState = {
|
|
4396
|
-
...emptyState(),
|
|
4397
|
-
filters: this.state.filters,
|
|
4398
|
-
selectedFields: [primaryKeyColumn],
|
|
4399
|
-
variantName: this.state.variantName
|
|
4400
|
-
};
|
|
4401
|
-
const countCompiled = compileSelect(this.contract, this.namespaceId, this.tableName, countState, this.modelName);
|
|
4402
|
-
const matchingRows = await executeQueryPlan(this.ctx.runtime, countCompiled).toArray();
|
|
4403
4387
|
const compiled = mergeAnnotations(compileDeleteCount(this.contract, this.namespaceId, this.tableName, this.state.filters, this.state.variantName, this.modelName), annotationsMap);
|
|
4404
|
-
await
|
|
4405
|
-
return matchingRows.length;
|
|
4388
|
+
return (await this.ctx.runtime.execute(compiled)).affectedRows;
|
|
4406
4389
|
}
|
|
4407
4390
|
#buildUpsertConflictCriterion(createValues, conflictColumns) {
|
|
4408
4391
|
const columnToField = getColumnToFieldMap(this.contract, this.namespaceId, this.modelName);
|