@prisma-next/adapter-postgres 0.16.0-dev.1 → 0.16.0-dev.11
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-BaZsfXGA.mjs → adapter-BbIiMeqB.mjs} +2 -2
- package/dist/{adapter-BaZsfXGA.mjs.map → adapter-BbIiMeqB.mjs.map} +1 -1
- package/dist/adapter.mjs +1 -1
- package/dist/{control-adapter-B6IM_oTR.mjs → control-adapter-XtIRYsO-.mjs} +37 -12
- package/dist/control-adapter-XtIRYsO-.mjs.map +1 -0
- package/dist/control.mjs +1 -1
- package/dist/runtime.mjs +1 -1
- package/package.json +23 -23
- package/src/core/sql-renderer.ts +79 -21
- package/dist/control-adapter-B6IM_oTR.mjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/adapter-postgres",
|
|
3
|
-
"version": "0.16.0-dev.
|
|
3
|
+
"version": "0.16.0-dev.11",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@prisma-next/contract": "0.16.0-dev.
|
|
9
|
-
"@prisma-next/contract-authoring": "0.16.0-dev.
|
|
10
|
-
"@prisma-next/errors": "0.16.0-dev.
|
|
11
|
-
"@prisma-next/family-sql": "0.16.0-dev.
|
|
12
|
-
"@prisma-next/framework-components": "0.16.0-dev.
|
|
13
|
-
"@prisma-next/ids": "0.16.0-dev.
|
|
14
|
-
"@prisma-next/psl-parser": "0.16.0-dev.
|
|
15
|
-
"@prisma-next/sql-contract": "0.16.0-dev.
|
|
16
|
-
"@prisma-next/sql-contract-psl": "0.16.0-dev.
|
|
17
|
-
"@prisma-next/sql-contract-ts": "0.16.0-dev.
|
|
18
|
-
"@prisma-next/sql-operations": "0.16.0-dev.
|
|
19
|
-
"@prisma-next/sql-relational-core": "0.16.0-dev.
|
|
20
|
-
"@prisma-next/sql-runtime": "0.16.0-dev.
|
|
21
|
-
"@prisma-next/sql-schema-ir": "0.16.0-dev.
|
|
22
|
-
"@prisma-next/target-postgres": "0.16.0-dev.
|
|
23
|
-
"@prisma-next/utils": "0.16.0-dev.
|
|
8
|
+
"@prisma-next/contract": "0.16.0-dev.11",
|
|
9
|
+
"@prisma-next/contract-authoring": "0.16.0-dev.11",
|
|
10
|
+
"@prisma-next/errors": "0.16.0-dev.11",
|
|
11
|
+
"@prisma-next/family-sql": "0.16.0-dev.11",
|
|
12
|
+
"@prisma-next/framework-components": "0.16.0-dev.11",
|
|
13
|
+
"@prisma-next/ids": "0.16.0-dev.11",
|
|
14
|
+
"@prisma-next/psl-parser": "0.16.0-dev.11",
|
|
15
|
+
"@prisma-next/sql-contract": "0.16.0-dev.11",
|
|
16
|
+
"@prisma-next/sql-contract-psl": "0.16.0-dev.11",
|
|
17
|
+
"@prisma-next/sql-contract-ts": "0.16.0-dev.11",
|
|
18
|
+
"@prisma-next/sql-operations": "0.16.0-dev.11",
|
|
19
|
+
"@prisma-next/sql-relational-core": "0.16.0-dev.11",
|
|
20
|
+
"@prisma-next/sql-runtime": "0.16.0-dev.11",
|
|
21
|
+
"@prisma-next/sql-schema-ir": "0.16.0-dev.11",
|
|
22
|
+
"@prisma-next/target-postgres": "0.16.0-dev.11",
|
|
23
|
+
"@prisma-next/utils": "0.16.0-dev.11",
|
|
24
24
|
"arktype": "^2.2.2"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@prisma-next/cli": "0.16.0-dev.
|
|
28
|
-
"@prisma-next/driver-postgres": "0.16.0-dev.
|
|
29
|
-
"@prisma-next/migration-tools": "0.16.0-dev.
|
|
30
|
-
"@prisma-next/test-utils": "0.16.0-dev.
|
|
31
|
-
"@prisma-next/tsconfig": "0.16.0-dev.
|
|
32
|
-
"@prisma-next/tsdown": "0.16.0-dev.
|
|
27
|
+
"@prisma-next/cli": "0.16.0-dev.11",
|
|
28
|
+
"@prisma-next/driver-postgres": "0.16.0-dev.11",
|
|
29
|
+
"@prisma-next/migration-tools": "0.16.0-dev.11",
|
|
30
|
+
"@prisma-next/test-utils": "0.16.0-dev.11",
|
|
31
|
+
"@prisma-next/tsconfig": "0.16.0-dev.11",
|
|
32
|
+
"@prisma-next/tsdown": "0.16.0-dev.11",
|
|
33
33
|
"pathe": "^2.0.3",
|
|
34
34
|
"tsdown": "0.22.8",
|
|
35
35
|
"typescript": "5.9.3",
|
package/src/core/sql-renderer.ts
CHANGED
|
@@ -5,18 +5,23 @@ import {
|
|
|
5
5
|
type AggregateExpr,
|
|
6
6
|
type AnyExpression,
|
|
7
7
|
type AnyFromSource,
|
|
8
|
+
type AnyJsonValueProjection,
|
|
8
9
|
type AnyParamRef,
|
|
9
10
|
type AnyQueryAst,
|
|
10
11
|
type BinaryExpr,
|
|
12
|
+
type CaseExpr,
|
|
13
|
+
type CastExpr,
|
|
11
14
|
type ColumnRef,
|
|
12
15
|
collectOrderedParamRefs,
|
|
13
16
|
type DeleteAst,
|
|
17
|
+
type FunctionCallExpr,
|
|
14
18
|
type InsertAst,
|
|
15
19
|
type InsertValue,
|
|
16
20
|
type JoinAst,
|
|
17
21
|
type JoinOnExpr,
|
|
18
22
|
type JsonArrayAggExpr,
|
|
19
23
|
type JsonObjectExpr,
|
|
24
|
+
type JsonValueProjectionVisitor,
|
|
20
25
|
type ListExpression,
|
|
21
26
|
LiteralExpr,
|
|
22
27
|
type LoweredParam,
|
|
@@ -121,6 +126,19 @@ function isRecord(value: unknown): value is Record<string, unknown> {
|
|
|
121
126
|
return typeof value === 'object' && value !== null;
|
|
122
127
|
}
|
|
123
128
|
|
|
129
|
+
function unreachableKind(value: never): string {
|
|
130
|
+
const candidate: unknown = value;
|
|
131
|
+
if (
|
|
132
|
+
typeof candidate === 'object' &&
|
|
133
|
+
candidate !== null &&
|
|
134
|
+
'kind' in candidate &&
|
|
135
|
+
typeof candidate.kind === 'string'
|
|
136
|
+
) {
|
|
137
|
+
return candidate.kind;
|
|
138
|
+
}
|
|
139
|
+
return 'unknown';
|
|
140
|
+
}
|
|
141
|
+
|
|
124
142
|
/**
|
|
125
143
|
* Per-render carrier threaded through every helper. Bundles the param-index map (for `$N` numbering) and the assembled-stack `codecLookup` (for cast policy at the `renderTypedParam` chokepoint). Carrying both on a single value keeps helper signatures stable.
|
|
126
144
|
*/
|
|
@@ -169,9 +187,7 @@ export function renderLoweredSql(
|
|
|
169
187
|
break;
|
|
170
188
|
// v8 ignore next 4
|
|
171
189
|
default:
|
|
172
|
-
throw new Error(
|
|
173
|
-
`Unsupported AST node kind: ${(node satisfies never as { kind: string }).kind}`,
|
|
174
|
-
);
|
|
190
|
+
throw new Error(`Unsupported AST node kind: ${unreachableKind(node)}`);
|
|
175
191
|
}
|
|
176
192
|
|
|
177
193
|
return Object.freeze({ sql, params: Object.freeze(params) });
|
|
@@ -465,13 +481,17 @@ function renderSource(
|
|
|
465
481
|
case 'function-source': {
|
|
466
482
|
const args = node.args.map((arg) => renderExpr(arg, contract, pim)).join(', ');
|
|
467
483
|
const call = `${node.fn}(${args})`;
|
|
468
|
-
|
|
484
|
+
const ordinality = node.ordinality ? ' WITH ORDINALITY' : '';
|
|
485
|
+
const alias = node.alias === undefined ? '' : ` AS ${quoteIdentifier(node.alias)}`;
|
|
486
|
+
const columnAliases =
|
|
487
|
+
node.columnAliases === undefined
|
|
488
|
+
? ''
|
|
489
|
+
: `(${node.columnAliases.map((column) => quoteIdentifier(column)).join(', ')})`;
|
|
490
|
+
return `${call}${ordinality}${alias}${columnAliases}`;
|
|
469
491
|
}
|
|
470
492
|
// v8 ignore next 4
|
|
471
493
|
default:
|
|
472
|
-
throw new Error(
|
|
473
|
-
`Unsupported source node kind: ${(node satisfies never as { kind: string }).kind}`,
|
|
474
|
-
);
|
|
494
|
+
throw new Error(`Unsupported source node kind: ${unreachableKind(node)}`);
|
|
475
495
|
}
|
|
476
496
|
}
|
|
477
497
|
|
|
@@ -518,6 +538,9 @@ function isAtomicExpressionKind(kind: AnyExpression['kind']): boolean {
|
|
|
518
538
|
case 'literal':
|
|
519
539
|
case 'aggregate':
|
|
520
540
|
case 'window-func':
|
|
541
|
+
case 'function-call':
|
|
542
|
+
case 'cast':
|
|
543
|
+
case 'case':
|
|
521
544
|
case 'json-object':
|
|
522
545
|
case 'json-array-agg':
|
|
523
546
|
case 'list':
|
|
@@ -644,6 +667,44 @@ function renderWindowFuncExpr(
|
|
|
644
667
|
return `${fn}(${args}) OVER (${over})`;
|
|
645
668
|
}
|
|
646
669
|
|
|
670
|
+
function renderFunctionCallExpr(
|
|
671
|
+
expr: FunctionCallExpr,
|
|
672
|
+
contract: PostgresContract,
|
|
673
|
+
pim: ParamIndexMap,
|
|
674
|
+
): string {
|
|
675
|
+
const args = expr.args.map((arg) => renderExpr(arg, contract, pim)).join(', ');
|
|
676
|
+
return `${expr.fn}(${args})`;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
function renderCastExpr(expr: CastExpr, contract: PostgresContract, pim: ParamIndexMap): string {
|
|
680
|
+
return `CAST(${renderExpr(expr.expr, contract, pim)} AS ${expr.targetType})`;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
function renderCaseExpr(expr: CaseExpr, contract: PostgresContract, pim: ParamIndexMap): string {
|
|
684
|
+
const branches = expr.branches
|
|
685
|
+
.map(
|
|
686
|
+
(branch) =>
|
|
687
|
+
`WHEN ${renderExpr(branch.condition, contract, pim)} THEN ${renderExpr(branch.value, contract, pim)}`,
|
|
688
|
+
)
|
|
689
|
+
.join(' ');
|
|
690
|
+
const elseClause =
|
|
691
|
+
expr.elseExpr === undefined ? '' : ` ELSE ${renderExpr(expr.elseExpr, contract, pim)}`;
|
|
692
|
+
return `CASE ${branches}${elseClause} END`;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
function renderJsonValueProjection(
|
|
696
|
+
projection: AnyJsonValueProjection,
|
|
697
|
+
contract: PostgresContract,
|
|
698
|
+
pim: ParamIndexMap,
|
|
699
|
+
): string {
|
|
700
|
+
const visitor: JsonValueProjectionVisitor<string> = {
|
|
701
|
+
codec: ({ value }) => renderExpr(value, contract, pim),
|
|
702
|
+
native: ({ value }) => renderExpr(value, contract, pim),
|
|
703
|
+
document: ({ value }) => renderExpr(value, contract, pim),
|
|
704
|
+
};
|
|
705
|
+
return projection.accept(visitor);
|
|
706
|
+
}
|
|
707
|
+
|
|
647
708
|
function renderJsonObjectExpr(
|
|
648
709
|
expr: JsonObjectExpr,
|
|
649
710
|
contract: PostgresContract,
|
|
@@ -652,10 +713,7 @@ function renderJsonObjectExpr(
|
|
|
652
713
|
const args = expr.entries
|
|
653
714
|
.flatMap((entry): [string, string] => {
|
|
654
715
|
const key = `'${escapeLiteral(entry.key)}'`;
|
|
655
|
-
|
|
656
|
-
return [key, renderLiteral(entry.value)];
|
|
657
|
-
}
|
|
658
|
-
return [key, renderExpr(entry.value, contract, pim)];
|
|
716
|
+
return [key, renderJsonValueProjection(entry.value, contract, pim)];
|
|
659
717
|
})
|
|
660
718
|
.join(', ');
|
|
661
719
|
return `json_build_object(${args})`;
|
|
@@ -680,7 +738,7 @@ function renderJsonArrayAggExpr(
|
|
|
680
738
|
expr.orderBy && expr.orderBy.length > 0
|
|
681
739
|
? ` ORDER BY ${renderOrderByItems(expr.orderBy, contract, pim)}`
|
|
682
740
|
: '';
|
|
683
|
-
const aggregated = `json_agg(${
|
|
741
|
+
const aggregated = `json_agg(${renderJsonValueProjection(expr.expr, contract, pim)}${aggregateOrderBy})`;
|
|
684
742
|
if (expr.onEmpty === 'emptyArray') {
|
|
685
743
|
return `coalesce(${aggregated}, json_build_array())`;
|
|
686
744
|
}
|
|
@@ -702,6 +760,12 @@ function renderExpr(expr: AnyExpression, contract: PostgresContract, pim: ParamI
|
|
|
702
760
|
return renderAggregateExpr(node, contract, pim);
|
|
703
761
|
case 'window-func':
|
|
704
762
|
return renderWindowFuncExpr(node, contract, pim);
|
|
763
|
+
case 'function-call':
|
|
764
|
+
return renderFunctionCallExpr(node, contract, pim);
|
|
765
|
+
case 'cast':
|
|
766
|
+
return renderCastExpr(node, contract, pim);
|
|
767
|
+
case 'case':
|
|
768
|
+
return renderCaseExpr(node, contract, pim);
|
|
705
769
|
case 'json-object':
|
|
706
770
|
return renderJsonObjectExpr(node, contract, pim);
|
|
707
771
|
case 'json-array-agg':
|
|
@@ -738,9 +802,7 @@ function renderExpr(expr: AnyExpression, contract: PostgresContract, pim: ParamI
|
|
|
738
802
|
return renderRawExpr(node, contract, pim);
|
|
739
803
|
// v8 ignore next 4
|
|
740
804
|
default:
|
|
741
|
-
throw new Error(
|
|
742
|
-
`Unsupported expression node kind: ${(node satisfies never as { kind: string }).kind}`,
|
|
743
|
-
);
|
|
805
|
+
throw new Error(`Unsupported expression node kind: ${unreachableKind(node)}`);
|
|
744
806
|
}
|
|
745
807
|
}
|
|
746
808
|
|
|
@@ -912,9 +974,7 @@ function renderInsertValue(
|
|
|
912
974
|
return renderExpr(value, contract, pim);
|
|
913
975
|
// v8 ignore next 4
|
|
914
976
|
default:
|
|
915
|
-
throw new Error(
|
|
916
|
-
`Unsupported value node in INSERT: ${(value satisfies never as { kind: string }).kind}`,
|
|
917
|
-
);
|
|
977
|
+
throw new Error(`Unsupported value node in INSERT: ${unreachableKind(value)}`);
|
|
918
978
|
}
|
|
919
979
|
}
|
|
920
980
|
|
|
@@ -979,9 +1039,7 @@ function renderInsert(ast: InsertAst, contract: PostgresContract, pim: ParamInde
|
|
|
979
1039
|
}
|
|
980
1040
|
// v8 ignore next 4
|
|
981
1041
|
default:
|
|
982
|
-
throw new Error(
|
|
983
|
-
`Unsupported onConflict action: ${(action satisfies never as { kind: string }).kind}`,
|
|
984
|
-
);
|
|
1042
|
+
throw new Error(`Unsupported onConflict action: ${unreachableKind(action)}`);
|
|
985
1043
|
}
|
|
986
1044
|
})()
|
|
987
1045
|
: '';
|