@prisma-next/sql-runtime 0.3.0-dev.3 → 0.3.0-dev.31
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/README.md +1 -2
- package/dist/{accelerate-EEKAFGN3-SHR4XFVV.js → accelerate-EEKAFGN3-P6A6XJWJ.js} +28 -28
- package/dist/{accelerate-EEKAFGN3-SHR4XFVV.js.map → accelerate-EEKAFGN3-P6A6XJWJ.js.map} +1 -1
- package/dist/{chunk-C6I3V3DM.js → chunk-APA6GHYY.js} +84 -2
- package/dist/chunk-APA6GHYY.js.map +1 -0
- package/dist/{dist-LCVVJCGI.js → dist-AQ3LWXOX.js} +13 -13
- package/dist/{dist-LCVVJCGI.js.map → dist-AQ3LWXOX.js.map} +1 -1
- package/dist/index.js +1 -1
- package/dist/src/codecs/decoding.d.ts +4 -0
- package/dist/src/codecs/decoding.d.ts.map +1 -0
- package/dist/src/codecs/encoding.d.ts +5 -0
- package/dist/src/codecs/encoding.d.ts.map +1 -0
- package/dist/src/codecs/validation.d.ts +6 -0
- package/dist/src/codecs/validation.d.ts.map +1 -0
- package/dist/src/exports/index.d.ts +11 -0
- package/dist/src/exports/index.d.ts.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/lower-sql-plan.d.ts +15 -0
- package/dist/src/lower-sql-plan.d.ts.map +1 -0
- package/dist/src/sql-context.d.ts +130 -0
- package/dist/src/sql-context.d.ts.map +1 -0
- package/dist/src/sql-family-adapter.d.ts +10 -0
- package/dist/src/sql-family-adapter.d.ts.map +1 -0
- package/dist/src/sql-marker.d.ts +22 -0
- package/dist/src/sql-marker.d.ts.map +1 -0
- package/dist/src/sql-runtime.d.ts +25 -0
- package/dist/src/sql-runtime.d.ts.map +1 -0
- package/dist/test/utils.d.ts +20 -24
- package/dist/test/utils.d.ts.map +1 -0
- package/dist/test/utils.js +26 -26
- package/dist/test/utils.js.map +1 -1
- package/package.json +25 -22
- package/src/codecs/decoding.ts +140 -0
- package/src/codecs/encoding.ts +76 -0
- package/src/codecs/validation.ts +67 -0
- package/src/exports/index.ts +40 -0
- package/src/index.ts +1 -0
- package/src/lower-sql-plan.ts +32 -0
- package/src/sql-context.ts +402 -0
- package/src/sql-family-adapter.ts +43 -0
- package/src/sql-marker.ts +105 -0
- package/src/sql-runtime.ts +166 -0
- package/test/async-iterable-result.test.ts +136 -0
- package/test/context.types.test-d.ts +70 -0
- package/test/parameterized-types.test.ts +553 -0
- package/test/sql-context.test.ts +217 -0
- package/test/sql-family-adapter.test.ts +86 -0
- package/test/sql-runtime.test.ts +155 -0
- package/test/utils.ts +266 -0
- package/dist/chunk-C6I3V3DM.js.map +0 -1
- package/dist/index.d.ts +0 -29
- package/dist/sql-runtime-DgEbg2OP.d.ts +0 -109
package/package.json
CHANGED
|
@@ -1,33 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-runtime",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.31",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "SQL runtime implementation for Prisma Next",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"
|
|
9
|
-
"@prisma-next/
|
|
10
|
-
"@prisma-next/
|
|
11
|
-
"@prisma-next/
|
|
12
|
-
"@prisma-next/
|
|
13
|
-
"@prisma-next/sql-
|
|
14
|
-
"@prisma-next/sql-
|
|
8
|
+
"arktype": "^2.1.26",
|
|
9
|
+
"@prisma-next/contract": "0.3.0-dev.31",
|
|
10
|
+
"@prisma-next/core-execution-plane": "0.3.0-dev.31",
|
|
11
|
+
"@prisma-next/operations": "0.3.0-dev.31",
|
|
12
|
+
"@prisma-next/runtime-executor": "0.3.0-dev.31",
|
|
13
|
+
"@prisma-next/sql-contract": "0.3.0-dev.31",
|
|
14
|
+
"@prisma-next/sql-operations": "0.3.0-dev.31",
|
|
15
|
+
"@prisma-next/sql-relational-core": "0.3.0-dev.31"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|
|
17
|
-
"@types/pg": "
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"@prisma-next/
|
|
18
|
+
"@types/pg": "8.16.0",
|
|
19
|
+
"pg": "8.16.3",
|
|
20
|
+
"tsup": "8.5.1",
|
|
21
|
+
"typescript": "5.9.3",
|
|
22
|
+
"vitest": "4.0.16",
|
|
23
|
+
"@prisma-next/test-utils": "0.0.1",
|
|
24
|
+
"@prisma-next/tsconfig": "0.0.0"
|
|
24
25
|
},
|
|
25
26
|
"files": [
|
|
26
|
-
"dist"
|
|
27
|
+
"dist",
|
|
28
|
+
"src",
|
|
29
|
+
"test"
|
|
27
30
|
],
|
|
28
31
|
"exports": {
|
|
29
32
|
".": {
|
|
30
|
-
"types": "./dist/index.d.ts",
|
|
33
|
+
"types": "./dist/src/index.d.ts",
|
|
31
34
|
"import": "./dist/index.js"
|
|
32
35
|
},
|
|
33
36
|
"./test/utils": {
|
|
@@ -36,13 +39,13 @@
|
|
|
36
39
|
}
|
|
37
40
|
},
|
|
38
41
|
"scripts": {
|
|
39
|
-
"build": "tsup --config tsup.config.ts",
|
|
42
|
+
"build": "tsup --config tsup.config.ts && tsc --project tsconfig.build.json",
|
|
40
43
|
"test": "vitest run --passWithNoTests",
|
|
41
44
|
"test:coverage": "vitest run --coverage --passWithNoTests",
|
|
42
45
|
"typecheck": "tsc --project tsconfig.json --noEmit",
|
|
43
|
-
"lint": "biome check . --
|
|
44
|
-
"lint:fix": "biome check --write .
|
|
45
|
-
"lint:fix:unsafe": "biome check --write --unsafe .
|
|
46
|
-
"clean": "
|
|
46
|
+
"lint": "biome check . --error-on-warnings",
|
|
47
|
+
"lint:fix": "biome check --write .",
|
|
48
|
+
"lint:fix:unsafe": "biome check --write --unsafe .",
|
|
49
|
+
"clean": "rm -rf dist dist-tsc dist-tsc-prod coverage .tmp-output"
|
|
47
50
|
}
|
|
48
51
|
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { ExecutionPlan } from '@prisma-next/contract/types';
|
|
2
|
+
import type { Codec, CodecRegistry } from '@prisma-next/sql-relational-core/ast';
|
|
3
|
+
|
|
4
|
+
function resolveRowCodec(
|
|
5
|
+
alias: string,
|
|
6
|
+
plan: ExecutionPlan,
|
|
7
|
+
registry: CodecRegistry,
|
|
8
|
+
): Codec | null {
|
|
9
|
+
const planCodecId = plan.meta.annotations?.codecs?.[alias] as string | undefined;
|
|
10
|
+
if (planCodecId) {
|
|
11
|
+
const codec = registry.get(planCodecId);
|
|
12
|
+
if (codec) {
|
|
13
|
+
return codec;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (plan.meta.projectionTypes) {
|
|
18
|
+
const typeId = plan.meta.projectionTypes[alias];
|
|
19
|
+
if (typeId) {
|
|
20
|
+
const codec = registry.get(typeId);
|
|
21
|
+
if (codec) {
|
|
22
|
+
return codec;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function decodeRow(
|
|
31
|
+
row: Record<string, unknown>,
|
|
32
|
+
plan: ExecutionPlan,
|
|
33
|
+
registry: CodecRegistry,
|
|
34
|
+
): Record<string, unknown> {
|
|
35
|
+
const decoded: Record<string, unknown> = {};
|
|
36
|
+
|
|
37
|
+
let aliases: readonly string[];
|
|
38
|
+
const projection = plan.meta.projection;
|
|
39
|
+
if (projection && !Array.isArray(projection)) {
|
|
40
|
+
aliases = Object.keys(projection);
|
|
41
|
+
} else if (projection && Array.isArray(projection)) {
|
|
42
|
+
aliases = projection;
|
|
43
|
+
} else {
|
|
44
|
+
aliases = Object.keys(row);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
for (const alias of aliases) {
|
|
48
|
+
const wireValue = row[alias];
|
|
49
|
+
|
|
50
|
+
const projection = plan.meta.projection;
|
|
51
|
+
const projectionValue =
|
|
52
|
+
projection && typeof projection === 'object' && !Array.isArray(projection)
|
|
53
|
+
? (projection as Record<string, string>)[alias]
|
|
54
|
+
: undefined;
|
|
55
|
+
|
|
56
|
+
if (typeof projectionValue === 'string' && projectionValue.startsWith('include:')) {
|
|
57
|
+
if (wireValue === null || wireValue === undefined) {
|
|
58
|
+
decoded[alias] = [];
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
let parsed: unknown;
|
|
64
|
+
if (typeof wireValue === 'string') {
|
|
65
|
+
parsed = JSON.parse(wireValue);
|
|
66
|
+
} else if (Array.isArray(wireValue)) {
|
|
67
|
+
parsed = wireValue;
|
|
68
|
+
} else {
|
|
69
|
+
parsed = JSON.parse(String(wireValue));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!Array.isArray(parsed)) {
|
|
73
|
+
throw new Error(`Expected array for include alias '${alias}', got ${typeof parsed}`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
decoded[alias] = parsed;
|
|
77
|
+
} catch (error) {
|
|
78
|
+
const decodeError = new Error(
|
|
79
|
+
`Failed to parse JSON array for include alias '${alias}': ${error instanceof Error ? error.message : String(error)}`,
|
|
80
|
+
) as Error & {
|
|
81
|
+
code: string;
|
|
82
|
+
category: string;
|
|
83
|
+
severity: string;
|
|
84
|
+
details?: Record<string, unknown>;
|
|
85
|
+
};
|
|
86
|
+
decodeError.code = 'RUNTIME.DECODE_FAILED';
|
|
87
|
+
decodeError.category = 'RUNTIME';
|
|
88
|
+
decodeError.severity = 'error';
|
|
89
|
+
decodeError.details = {
|
|
90
|
+
alias,
|
|
91
|
+
wirePreview:
|
|
92
|
+
typeof wireValue === 'string' && wireValue.length > 100
|
|
93
|
+
? `${wireValue.substring(0, 100)}...`
|
|
94
|
+
: String(wireValue).substring(0, 100),
|
|
95
|
+
};
|
|
96
|
+
throw decodeError;
|
|
97
|
+
}
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (wireValue === null || wireValue === undefined) {
|
|
102
|
+
decoded[alias] = wireValue;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const codec = resolveRowCodec(alias, plan, registry);
|
|
107
|
+
|
|
108
|
+
if (!codec) {
|
|
109
|
+
decoded[alias] = wireValue;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
decoded[alias] = codec.decode(wireValue);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
const decodeError = new Error(
|
|
117
|
+
`Failed to decode row alias '${alias}' with codec '${codec.id}': ${error instanceof Error ? error.message : String(error)}`,
|
|
118
|
+
) as Error & {
|
|
119
|
+
code: string;
|
|
120
|
+
category: string;
|
|
121
|
+
severity: string;
|
|
122
|
+
details?: Record<string, unknown>;
|
|
123
|
+
};
|
|
124
|
+
decodeError.code = 'RUNTIME.DECODE_FAILED';
|
|
125
|
+
decodeError.category = 'RUNTIME';
|
|
126
|
+
decodeError.severity = 'error';
|
|
127
|
+
decodeError.details = {
|
|
128
|
+
alias,
|
|
129
|
+
codec: codec.id,
|
|
130
|
+
wirePreview:
|
|
131
|
+
typeof wireValue === 'string' && wireValue.length > 100
|
|
132
|
+
? `${wireValue.substring(0, 100)}...`
|
|
133
|
+
: String(wireValue).substring(0, 100),
|
|
134
|
+
};
|
|
135
|
+
throw decodeError;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return decoded;
|
|
140
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { ExecutionPlan, ParamDescriptor } from '@prisma-next/contract/types';
|
|
2
|
+
import type { Codec, CodecRegistry } from '@prisma-next/sql-relational-core/ast';
|
|
3
|
+
|
|
4
|
+
function resolveParamCodec(
|
|
5
|
+
paramDescriptor: ParamDescriptor,
|
|
6
|
+
plan: ExecutionPlan,
|
|
7
|
+
registry: CodecRegistry,
|
|
8
|
+
): Codec | null {
|
|
9
|
+
const paramName = paramDescriptor.name ?? `param_${paramDescriptor.index ?? 0}`;
|
|
10
|
+
|
|
11
|
+
const planCodecId = plan.meta.annotations?.codecs?.[paramName] as string | undefined;
|
|
12
|
+
if (planCodecId) {
|
|
13
|
+
const codec = registry.get(planCodecId);
|
|
14
|
+
if (codec) {
|
|
15
|
+
return codec;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (paramDescriptor.codecId) {
|
|
20
|
+
const codec = registry.get(paramDescriptor.codecId);
|
|
21
|
+
if (codec) {
|
|
22
|
+
return codec;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function encodeParam(
|
|
30
|
+
value: unknown,
|
|
31
|
+
paramDescriptor: ParamDescriptor,
|
|
32
|
+
plan: ExecutionPlan,
|
|
33
|
+
registry: CodecRegistry,
|
|
34
|
+
): unknown {
|
|
35
|
+
if (value === null || value === undefined) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const codec = resolveParamCodec(paramDescriptor, plan, registry);
|
|
40
|
+
if (!codec) {
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (codec.encode) {
|
|
45
|
+
try {
|
|
46
|
+
return codec.encode(value);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
`Failed to encode parameter ${paramDescriptor.name ?? paramDescriptor.index}: ${error instanceof Error ? error.message : String(error)}`,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function encodeParams(plan: ExecutionPlan, registry: CodecRegistry): readonly unknown[] {
|
|
58
|
+
if (plan.params.length === 0) {
|
|
59
|
+
return plan.params;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const encoded: unknown[] = [];
|
|
63
|
+
|
|
64
|
+
for (let i = 0; i < plan.params.length; i++) {
|
|
65
|
+
const paramValue = plan.params[i];
|
|
66
|
+
const paramDescriptor = plan.meta.paramDescriptors[i];
|
|
67
|
+
|
|
68
|
+
if (paramDescriptor) {
|
|
69
|
+
encoded.push(encodeParam(paramValue, paramDescriptor, plan, registry));
|
|
70
|
+
} else {
|
|
71
|
+
encoded.push(paramValue);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return Object.freeze(encoded);
|
|
76
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { runtimeError } from '@prisma-next/runtime-executor';
|
|
2
|
+
import type { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
|
|
3
|
+
import type { CodecRegistry } from '@prisma-next/sql-relational-core/ast';
|
|
4
|
+
|
|
5
|
+
export function extractCodecIds(contract: SqlContract<SqlStorage>): Set<string> {
|
|
6
|
+
const codecIds = new Set<string>();
|
|
7
|
+
|
|
8
|
+
for (const table of Object.values(contract.storage.tables)) {
|
|
9
|
+
for (const column of Object.values(table.columns)) {
|
|
10
|
+
const codecId = column.codecId;
|
|
11
|
+
codecIds.add(codecId);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return codecIds;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function extractCodecIdsFromColumns(contract: SqlContract<SqlStorage>): Map<string, string> {
|
|
19
|
+
const codecIds = new Map<string, string>();
|
|
20
|
+
|
|
21
|
+
for (const [tableName, table] of Object.entries(contract.storage.tables)) {
|
|
22
|
+
for (const [columnName, column] of Object.entries(table.columns)) {
|
|
23
|
+
const codecId = column.codecId;
|
|
24
|
+
const key = `${tableName}.${columnName}`;
|
|
25
|
+
codecIds.set(key, codecId);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return codecIds;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function validateContractCodecMappings(
|
|
33
|
+
registry: CodecRegistry,
|
|
34
|
+
contract: SqlContract<SqlStorage>,
|
|
35
|
+
): void {
|
|
36
|
+
const codecIds = extractCodecIdsFromColumns(contract);
|
|
37
|
+
const invalidCodecs: Array<{ table: string; column: string; codecId: string }> = [];
|
|
38
|
+
|
|
39
|
+
for (const [key, codecId] of codecIds.entries()) {
|
|
40
|
+
if (!registry.has(codecId)) {
|
|
41
|
+
const parts = key.split('.');
|
|
42
|
+
const table = parts[0] ?? '';
|
|
43
|
+
const column = parts[1] ?? '';
|
|
44
|
+
invalidCodecs.push({ table, column, codecId });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (invalidCodecs.length > 0) {
|
|
49
|
+
const details: Record<string, unknown> = {
|
|
50
|
+
contractTarget: contract.target,
|
|
51
|
+
invalidCodecs,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
throw runtimeError(
|
|
55
|
+
'RUNTIME.CODEC_MISSING',
|
|
56
|
+
`Missing codec implementations for column codecIds: ${invalidCodecs.map((c) => `${c.table}.${c.column} (${c.codecId})`).join(', ')}`,
|
|
57
|
+
details,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function validateCodecRegistryCompleteness(
|
|
63
|
+
registry: CodecRegistry,
|
|
64
|
+
contract: SqlContract<SqlStorage>,
|
|
65
|
+
): void {
|
|
66
|
+
validateContractCodecMappings(registry, contract);
|
|
67
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
AfterExecuteResult,
|
|
3
|
+
BudgetsOptions,
|
|
4
|
+
LintsOptions,
|
|
5
|
+
Log,
|
|
6
|
+
Plugin,
|
|
7
|
+
PluginContext,
|
|
8
|
+
} from '@prisma-next/runtime-executor';
|
|
9
|
+
export { budgets, lints } from '@prisma-next/runtime-executor';
|
|
10
|
+
export {
|
|
11
|
+
extractCodecIds,
|
|
12
|
+
validateCodecRegistryCompleteness,
|
|
13
|
+
validateContractCodecMappings,
|
|
14
|
+
} from '../codecs/validation';
|
|
15
|
+
export { lowerSqlPlan } from '../lower-sql-plan';
|
|
16
|
+
export type {
|
|
17
|
+
CreateRuntimeContextOptions,
|
|
18
|
+
RuntimeContext,
|
|
19
|
+
RuntimeParameterizedCodecDescriptor,
|
|
20
|
+
SqlRuntimeAdapterInstance,
|
|
21
|
+
SqlRuntimeExtensionDescriptor,
|
|
22
|
+
SqlRuntimeExtensionInstance,
|
|
23
|
+
TypeHelperRegistry,
|
|
24
|
+
} from '../sql-context';
|
|
25
|
+
export { createRuntimeContext } from '../sql-context';
|
|
26
|
+
export type { SqlStatement } from '../sql-marker';
|
|
27
|
+
export {
|
|
28
|
+
ensureSchemaStatement,
|
|
29
|
+
ensureTableStatement,
|
|
30
|
+
readContractMarker,
|
|
31
|
+
writeContractMarker,
|
|
32
|
+
} from '../sql-marker';
|
|
33
|
+
export type {
|
|
34
|
+
Runtime,
|
|
35
|
+
RuntimeOptions,
|
|
36
|
+
RuntimeTelemetryEvent,
|
|
37
|
+
RuntimeVerifyOptions,
|
|
38
|
+
TelemetryOutcome,
|
|
39
|
+
} from '../sql-runtime';
|
|
40
|
+
export { createRuntime } from '../sql-runtime';
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './exports';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ExecutionPlan } from '@prisma-next/contract/types';
|
|
2
|
+
import type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';
|
|
3
|
+
import type { RuntimeContext } from './sql-context';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Lowers a SQL query plan to an executable Plan by calling the adapter's lower method.
|
|
7
|
+
*
|
|
8
|
+
* This function is responsible for converting a lane-produced SqlQueryPlan (which contains
|
|
9
|
+
* AST and params but no SQL) into a fully executable Plan (which includes SQL string).
|
|
10
|
+
*
|
|
11
|
+
* @param context - Runtime context containing the adapter
|
|
12
|
+
* @param queryPlan - SQL query plan from a lane (contains AST, params, meta, but no SQL)
|
|
13
|
+
* @returns Fully executable Plan with SQL string
|
|
14
|
+
*/
|
|
15
|
+
export function lowerSqlPlan<Row>(
|
|
16
|
+
context: RuntimeContext,
|
|
17
|
+
queryPlan: SqlQueryPlan<Row>,
|
|
18
|
+
): ExecutionPlan<Row> {
|
|
19
|
+
const lowered = context.adapter.lower(queryPlan.ast, {
|
|
20
|
+
contract: context.contract,
|
|
21
|
+
params: queryPlan.params,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const body = lowered.body;
|
|
25
|
+
|
|
26
|
+
return Object.freeze({
|
|
27
|
+
sql: body.sql,
|
|
28
|
+
params: body.params ?? queryPlan.params,
|
|
29
|
+
ast: queryPlan.ast,
|
|
30
|
+
meta: queryPlan.meta,
|
|
31
|
+
});
|
|
32
|
+
}
|