@prisma-next/adapter-postgres 0.13.0-dev.2 → 0.13.0-dev.21
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-CAlWA4ug.mjs → adapter-CoRrSTXZ.mjs} +3 -3
- package/dist/adapter-CoRrSTXZ.mjs.map +1 -0
- package/dist/adapter.d.mts +1 -1
- package/dist/adapter.d.mts.map +1 -1
- package/dist/adapter.mjs +1 -1
- package/dist/{control-adapter-ZWrjGBq7.mjs → control-adapter-BeSqyOGl.mjs} +209 -116
- package/dist/control-adapter-BeSqyOGl.mjs.map +1 -0
- package/dist/control.d.mts +23 -12
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +3 -3
- package/dist/control.mjs.map +1 -1
- package/dist/{descriptor-meta-NBwpqHS7.mjs → descriptor-meta-DOgMfoqm.mjs} +10 -3
- package/dist/descriptor-meta-DOgMfoqm.mjs.map +1 -0
- package/dist/runtime.d.mts +1 -1
- package/dist/runtime.mjs +2 -2
- package/dist/{types-Dv7M8jx8.d.mts → types-KXRwRZU8.d.mts} +3 -3
- package/dist/types-KXRwRZU8.d.mts.map +1 -0
- package/dist/types.d.mts +1 -1
- package/package.json +22 -22
- package/src/core/adapter.ts +5 -4
- package/src/core/codec-lookup.ts +5 -5
- package/src/core/control-adapter.ts +241 -37
- package/src/core/control-codecs.ts +25 -0
- package/src/core/descriptor-meta.ts +3 -0
- package/src/core/marker-ledger.ts +2 -18
- package/src/core/sql-renderer.ts +122 -1
- package/src/core/types.ts +2 -2
- package/src/exports/control.ts +1 -0
- package/dist/adapter-CAlWA4ug.mjs.map +0 -1
- package/dist/control-adapter-ZWrjGBq7.mjs.map +0 -1
- package/dist/descriptor-meta-NBwpqHS7.mjs.map +0 -1
- package/dist/types-Dv7M8jx8.d.mts.map +0 -1
- package/src/core/ddl-renderer.ts +0 -155
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor-meta-DOgMfoqm.mjs","names":[],"sources":["../src/core/descriptor-meta.ts"],"sourcesContent":["import type { CodecControlHooks, ExpandNativeTypeInput } from '@prisma-next/family-sql/control';\nimport {\n buildOperation,\n type CodecExpression,\n type Expression,\n type TraitExpression,\n toExpr,\n} from '@prisma-next/sql-relational-core/expression';\nimport {\n PG_BIT_CODEC_ID,\n PG_BOOL_CODEC_ID,\n PG_BYTEA_CODEC_ID,\n PG_CHAR_CODEC_ID,\n PG_FLOAT_CODEC_ID,\n PG_FLOAT4_CODEC_ID,\n PG_FLOAT8_CODEC_ID,\n PG_INT_CODEC_ID,\n PG_INT2_CODEC_ID,\n PG_INT4_CODEC_ID,\n PG_INT8_CODEC_ID,\n PG_INTERVAL_CODEC_ID,\n PG_JSON_CODEC_ID,\n PG_JSONB_CODEC_ID,\n PG_NUMERIC_CODEC_ID,\n PG_TEXT_CODEC_ID,\n PG_TIME_CODEC_ID,\n PG_TIMESTAMP_CODEC_ID,\n PG_TIMESTAMPTZ_CODEC_ID,\n PG_TIMETZ_CODEC_ID,\n PG_UUID_CODEC_ID,\n PG_VARBIT_CODEC_ID,\n PG_VARCHAR_CODEC_ID,\n SQL_CHAR_CODEC_ID,\n SQL_FLOAT_CODEC_ID,\n SQL_INT_CODEC_ID,\n SQL_TEXT_CODEC_ID,\n SQL_TIMESTAMP_CODEC_ID,\n SQL_VARCHAR_CODEC_ID,\n} from '@prisma-next/target-postgres/codec-ids';\nimport { postgresCodecRegistry } from '@prisma-next/target-postgres/codecs';\nimport type { QueryOperationTypes } from '../types/operation-types';\n\n// ============================================================================ Helper functions for reducing boilerplate ============================================================================\n\n/** Creates a type import spec for codec types */\nconst codecTypeImport = (named: string) =>\n ({\n package: '@prisma-next/target-postgres/codec-types',\n named,\n alias: named,\n }) as const;\n\nfunction isPositiveInteger(value: unknown): value is number {\n return (\n typeof value === 'number' && Number.isFinite(value) && Number.isInteger(value) && value > 0\n );\n}\n\nfunction isNonNegativeInteger(value: unknown): value is number {\n return (\n typeof value === 'number' && Number.isFinite(value) && Number.isInteger(value) && value >= 0\n );\n}\n\nfunction expandLength({ nativeType, typeParams }: ExpandNativeTypeInput): string {\n if (!typeParams || !('length' in typeParams)) {\n return nativeType;\n }\n const length = typeParams['length'];\n if (!isPositiveInteger(length)) {\n throw new Error(\n `Invalid \"length\" type parameter for \"${nativeType}\": expected a positive integer, got ${JSON.stringify(length)}`,\n );\n }\n return `${nativeType}(${length})`;\n}\n\nfunction expandPrecision({ nativeType, typeParams }: ExpandNativeTypeInput): string {\n if (!typeParams || !('precision' in typeParams)) {\n return nativeType;\n }\n const precision = typeParams['precision'];\n if (!isPositiveInteger(precision)) {\n throw new Error(\n `Invalid \"precision\" type parameter for \"${nativeType}\": expected a positive integer, got ${JSON.stringify(precision)}`,\n );\n }\n return `${nativeType}(${precision})`;\n}\n\nfunction expandNumeric({ nativeType, typeParams }: ExpandNativeTypeInput): string {\n const hasPrecision = typeParams && 'precision' in typeParams;\n const hasScale = typeParams && 'scale' in typeParams;\n\n if (!hasPrecision && !hasScale) {\n return nativeType;\n }\n\n if (!hasPrecision && hasScale) {\n throw new Error(\n `Invalid type parameters for \"${nativeType}\": \"scale\" requires \"precision\" to be specified`,\n );\n }\n\n if (hasPrecision) {\n const precision = typeParams['precision'];\n if (!isPositiveInteger(precision)) {\n throw new Error(\n `Invalid \"precision\" type parameter for \"${nativeType}\": expected a positive integer, got ${JSON.stringify(precision)}`,\n );\n }\n if (hasScale) {\n const scale = typeParams['scale'];\n if (!isNonNegativeInteger(scale)) {\n throw new Error(\n `Invalid \"scale\" type parameter for \"${nativeType}\": expected a non-negative integer, got ${JSON.stringify(scale)}`,\n );\n }\n return `${nativeType}(${precision},${scale})`;\n }\n return `${nativeType}(${precision})`;\n }\n\n return nativeType;\n}\n\nconst lengthHooks: CodecControlHooks = { expandNativeType: expandLength };\nconst precisionHooks: CodecControlHooks = { expandNativeType: expandPrecision };\nconst numericHooks: CodecControlHooks = { expandNativeType: expandNumeric };\nconst identityHooks: CodecControlHooks = { expandNativeType: ({ nativeType }) => nativeType };\n\n// ============================================================================ Descriptor metadata ============================================================================\n\ntype CodecTypesBase = Record<string, { readonly input: unknown; readonly output: unknown }>;\n\nexport function postgresQueryOperations<CT extends CodecTypesBase>(): QueryOperationTypes<CT> {\n return {\n ilike: {\n self: { traits: ['textual'] },\n impl: (\n self: TraitExpression<readonly ['textual'], false, CT>,\n pattern: CodecExpression<'pg/text@1', false, CT>,\n ): Expression<{ codecId: 'pg/bool@1'; nullable: false }> => {\n return buildOperation({\n method: 'ilike',\n args: [toExpr(self), toExpr(pattern, { codecId: PG_TEXT_CODEC_ID })],\n returns: { codecId: PG_BOOL_CODEC_ID, nullable: false },\n lowering: { targetFamily: 'sql', strategy: 'infix', template: '{{self}} ILIKE {{arg0}}' },\n });\n },\n },\n };\n}\n\nexport const postgresAdapterDescriptorMeta = {\n kind: 'adapter',\n familyId: 'sql',\n targetId: 'postgres',\n id: 'postgres',\n version: '0.0.1',\n capabilities: {\n postgres: {\n orderBy: true,\n limit: true,\n lateral: true,\n jsonAgg: true,\n returning: true,\n distinctOn: true,\n },\n sql: {\n enums: true,\n returning: true,\n defaultInInsert: true,\n lateral: true,\n },\n },\n types: {\n codecTypes: {\n codecDescriptors: Array.from(postgresCodecRegistry.values()),\n import: {\n package: '@prisma-next/target-postgres/codec-types',\n named: 'CodecTypes',\n alias: 'PgTypes',\n },\n typeImports: [\n {\n package: '@prisma-next/target-postgres/codec-types',\n named: 'JsonValue',\n alias: 'JsonValue',\n },\n codecTypeImport('Char'),\n codecTypeImport('Varchar'),\n codecTypeImport('Numeric'),\n codecTypeImport('Bit'),\n codecTypeImport('VarBit'),\n codecTypeImport('Timestamp'),\n codecTypeImport('Timestamptz'),\n codecTypeImport('Time'),\n codecTypeImport('Timetz'),\n codecTypeImport('Interval'),\n ],\n controlPlaneHooks: {\n [SQL_CHAR_CODEC_ID]: lengthHooks,\n [SQL_VARCHAR_CODEC_ID]: lengthHooks,\n [SQL_TIMESTAMP_CODEC_ID]: precisionHooks,\n [PG_CHAR_CODEC_ID]: lengthHooks,\n [PG_VARCHAR_CODEC_ID]: lengthHooks,\n [PG_NUMERIC_CODEC_ID]: numericHooks,\n [PG_BIT_CODEC_ID]: lengthHooks,\n [PG_VARBIT_CODEC_ID]: lengthHooks,\n [PG_TIMESTAMP_CODEC_ID]: precisionHooks,\n [PG_TIMESTAMPTZ_CODEC_ID]: precisionHooks,\n [PG_TIME_CODEC_ID]: precisionHooks,\n [PG_TIMETZ_CODEC_ID]: precisionHooks,\n [PG_INTERVAL_CODEC_ID]: precisionHooks,\n [PG_JSON_CODEC_ID]: identityHooks,\n [PG_JSONB_CODEC_ID]: identityHooks,\n [PG_BYTEA_CODEC_ID]: identityHooks,\n [PG_UUID_CODEC_ID]: identityHooks,\n },\n },\n storage: [\n { typeId: PG_TEXT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'text' },\n { typeId: SQL_TEXT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'text' },\n { typeId: SQL_CHAR_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'character' },\n {\n typeId: SQL_VARCHAR_CODEC_ID,\n familyId: 'sql',\n targetId: 'postgres',\n nativeType: 'character varying',\n },\n { typeId: SQL_INT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'int4' },\n { typeId: SQL_FLOAT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'float8' },\n {\n typeId: SQL_TIMESTAMP_CODEC_ID,\n familyId: 'sql',\n targetId: 'postgres',\n nativeType: 'timestamp',\n },\n { typeId: PG_CHAR_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'character' },\n {\n typeId: PG_VARCHAR_CODEC_ID,\n familyId: 'sql',\n targetId: 'postgres',\n nativeType: 'character varying',\n },\n { typeId: PG_INT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'int4' },\n { typeId: PG_FLOAT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'float8' },\n { typeId: PG_INT4_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'int4' },\n { typeId: PG_INT2_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'int2' },\n { typeId: PG_INT8_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'int8' },\n { typeId: PG_FLOAT4_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'float4' },\n { typeId: PG_FLOAT8_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'float8' },\n { typeId: PG_NUMERIC_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'numeric' },\n {\n typeId: PG_TIMESTAMP_CODEC_ID,\n familyId: 'sql',\n targetId: 'postgres',\n nativeType: 'timestamp',\n },\n {\n typeId: PG_TIMESTAMPTZ_CODEC_ID,\n familyId: 'sql',\n targetId: 'postgres',\n nativeType: 'timestamptz',\n },\n { typeId: PG_TIME_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'time' },\n { typeId: PG_TIMETZ_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'timetz' },\n { typeId: PG_BOOL_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'bool' },\n { typeId: PG_BIT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'bit' },\n {\n typeId: PG_VARBIT_CODEC_ID,\n familyId: 'sql',\n targetId: 'postgres',\n nativeType: 'bit varying',\n },\n {\n typeId: PG_INTERVAL_CODEC_ID,\n familyId: 'sql',\n targetId: 'postgres',\n nativeType: 'interval',\n },\n { typeId: PG_JSON_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'json' },\n { typeId: PG_JSONB_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'jsonb' },\n { typeId: PG_BYTEA_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'bytea' },\n { typeId: PG_UUID_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'uuid' },\n ],\n queryOperationTypes: {\n import: {\n package: '@prisma-next/adapter-postgres/operation-types',\n named: 'QueryOperationTypes',\n alias: 'PgAdapterQueryOps',\n },\n },\n },\n} as const;\n"],"mappings":";;;;;AA6CA,MAAM,mBAAmB,WACtB;CACC,SAAS;CACT;CACA,OAAO;AACT;AAEF,SAAS,kBAAkB,OAAiC;CAC1D,OACE,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,KAAK,OAAO,UAAU,KAAK,KAAK,QAAQ;AAE9F;AAEA,SAAS,qBAAqB,OAAiC;CAC7D,OACE,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,KAAK,OAAO,UAAU,KAAK,KAAK,SAAS;AAE/F;AAEA,SAAS,aAAa,EAAE,YAAY,cAA6C;CAC/E,IAAI,CAAC,cAAc,EAAE,YAAY,aAC/B,OAAO;CAET,MAAM,SAAS,WAAW;CAC1B,IAAI,CAAC,kBAAkB,MAAM,GAC3B,MAAM,IAAI,MACR,wCAAwC,WAAW,sCAAsC,KAAK,UAAU,MAAM,GAChH;CAEF,OAAO,GAAG,WAAW,GAAG,OAAO;AACjC;AAEA,SAAS,gBAAgB,EAAE,YAAY,cAA6C;CAClF,IAAI,CAAC,cAAc,EAAE,eAAe,aAClC,OAAO;CAET,MAAM,YAAY,WAAW;CAC7B,IAAI,CAAC,kBAAkB,SAAS,GAC9B,MAAM,IAAI,MACR,2CAA2C,WAAW,sCAAsC,KAAK,UAAU,SAAS,GACtH;CAEF,OAAO,GAAG,WAAW,GAAG,UAAU;AACpC;AAEA,SAAS,cAAc,EAAE,YAAY,cAA6C;CAChF,MAAM,eAAe,cAAc,eAAe;CAClD,MAAM,WAAW,cAAc,WAAW;CAE1C,IAAI,CAAC,gBAAgB,CAAC,UACpB,OAAO;CAGT,IAAI,CAAC,gBAAgB,UACnB,MAAM,IAAI,MACR,gCAAgC,WAAW,gDAC7C;CAGF,IAAI,cAAc;EAChB,MAAM,YAAY,WAAW;EAC7B,IAA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
|
|
|
1
|
-
import { c as PostgresContract, l as PostgresLoweredStatement } from "./types-
|
|
1
|
+
import { c as PostgresContract, l as PostgresLoweredStatement } from "./types-KXRwRZU8.mjs";
|
|
2
2
|
import { Adapter, AnyQueryAst } from "@prisma-next/sql-relational-core/ast";
|
|
3
3
|
import { SqlRuntimeAdapterDescriptor } from "@prisma-next/sql-runtime";
|
|
4
4
|
import { RuntimeAdapterInstance } from "@prisma-next/framework-components/execution";
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as postgresRawCodecInferer, t as createPostgresAdapter } from "./adapter-
|
|
2
|
-
import { n as postgresQueryOperations, t as postgresAdapterDescriptorMeta } from "./descriptor-meta-
|
|
1
|
+
import { n as postgresRawCodecInferer, t as createPostgresAdapter } from "./adapter-CoRrSTXZ.mjs";
|
|
2
|
+
import { n as postgresQueryOperations, t as postgresAdapterDescriptorMeta } from "./descriptor-meta-DOgMfoqm.mjs";
|
|
3
3
|
import { extractCodecLookup } from "@prisma-next/framework-components/control";
|
|
4
4
|
import { postgresCodecRegistry } from "@prisma-next/target-postgres/codecs";
|
|
5
5
|
import { builtinGeneratorIds } from "@prisma-next/ids";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BinaryExpr, ColumnRef, DefaultValueExpr, Direction, LoweredStatement, ParamRef, SelectAst } from "@prisma-next/sql-relational-core/ast";
|
|
2
2
|
import { Contract } from "@prisma-next/contract/types";
|
|
3
|
-
import {
|
|
3
|
+
import { CodecRegistry } from "@prisma-next/framework-components/codec";
|
|
4
4
|
import { SqlStorage, StorageColumn, StorageTable } from "@prisma-next/sql-contract/types";
|
|
5
5
|
|
|
6
6
|
//#region src/core/types.d.ts
|
|
@@ -15,7 +15,7 @@ interface PostgresAdapterOptions {
|
|
|
15
15
|
* `SqlControlAdapterDescriptor.create(stack)`) supply the assembled stack
|
|
16
16
|
* lookup so extension codecs are visible to the renderer.
|
|
17
17
|
*/
|
|
18
|
-
readonly codecLookup?:
|
|
18
|
+
readonly codecLookup?: CodecRegistry;
|
|
19
19
|
}
|
|
20
20
|
type PostgresContract = Contract<SqlStorage> & {
|
|
21
21
|
readonly target: 'postgres';
|
|
@@ -28,4 +28,4 @@ interface OrderClause {
|
|
|
28
28
|
type PostgresLoweredStatement = LoweredStatement;
|
|
29
29
|
//#endregion
|
|
30
30
|
export { OrderClause as a, PostgresContract as c, StorageColumn as d, StorageTable as f, Expr as i, PostgresLoweredStatement as l, ColumnRef as n, ParamRef as o, Direction as r, PostgresAdapterOptions as s, BinaryExpr as t, SelectAst as u };
|
|
31
|
-
//# sourceMappingURL=types-
|
|
31
|
+
//# sourceMappingURL=types-KXRwRZU8.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-KXRwRZU8.d.mts","names":[],"sources":["../src/core/types.ts"],"mappings":";;;;;;UAoBiB,sBAAA;EAAA,SACN,SAAA;EADM;;;;;;;;AAWqB;EAXrB,SAWN,WAAA,GAAc,aAAa;AAAA;AAAA,KAG1B,gBAAA,GAAmB,QAAQ,CAAC,UAAA;EAAA,SAAyB,MAAA;AAAA;AAAA,KAErD,IAAA,GAAO,SAAA,GAAY,QAAA,GAAW,gBAAA;AAAA,UAEzB,WAAA;EAAA,SACN,IAAA,EAAM,SAAA;EAAA,SACN,GAAA,EAAK,SAAS;AAAA;AAAA,KAGb,wBAAA,GAA2B,gBAAgB"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as OrderClause, c as PostgresContract, d as StorageColumn, f as StorageTable, i as Expr, l as PostgresLoweredStatement, n as ColumnRef, o as ParamRef, r as Direction, s as PostgresAdapterOptions, t as BinaryExpr, u as SelectAst } from "./types-
|
|
1
|
+
import { a as OrderClause, c as PostgresContract, d as StorageColumn, f as StorageTable, i as Expr, l as PostgresLoweredStatement, n as ColumnRef, o as ParamRef, r as Direction, s as PostgresAdapterOptions, t as BinaryExpr, u as SelectAst } from "./types-KXRwRZU8.mjs";
|
|
2
2
|
export type { BinaryExpr, ColumnRef, Direction, Expr, OrderClause, ParamRef, PostgresAdapterOptions, PostgresContract, PostgresLoweredStatement, SelectAst, StorageColumn, StorageTable };
|
package/package.json
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/adapter-postgres",
|
|
3
|
-
"version": "0.13.0-dev.
|
|
3
|
+
"version": "0.13.0-dev.21",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@prisma-next/contract": "0.13.0-dev.
|
|
9
|
-
"@prisma-next/contract-authoring": "0.13.0-dev.
|
|
10
|
-
"@prisma-next/errors": "0.13.0-dev.
|
|
11
|
-
"@prisma-next/family-sql": "0.13.0-dev.
|
|
12
|
-
"@prisma-next/framework-components": "0.13.0-dev.
|
|
13
|
-
"@prisma-next/ids": "0.13.0-dev.
|
|
14
|
-
"@prisma-next/sql-contract": "0.13.0-dev.
|
|
15
|
-
"@prisma-next/sql-contract-psl": "0.13.0-dev.
|
|
16
|
-
"@prisma-next/sql-contract-ts": "0.13.0-dev.
|
|
17
|
-
"@prisma-next/sql-operations": "0.13.0-dev.
|
|
18
|
-
"@prisma-next/sql-relational-core": "0.13.0-dev.
|
|
19
|
-
"@prisma-next/sql-runtime": "0.13.0-dev.
|
|
20
|
-
"@prisma-next/sql-schema-ir": "0.13.0-dev.
|
|
21
|
-
"@prisma-next/target-postgres": "0.13.0-dev.
|
|
22
|
-
"@prisma-next/utils": "0.13.0-dev.
|
|
8
|
+
"@prisma-next/contract": "0.13.0-dev.21",
|
|
9
|
+
"@prisma-next/contract-authoring": "0.13.0-dev.21",
|
|
10
|
+
"@prisma-next/errors": "0.13.0-dev.21",
|
|
11
|
+
"@prisma-next/family-sql": "0.13.0-dev.21",
|
|
12
|
+
"@prisma-next/framework-components": "0.13.0-dev.21",
|
|
13
|
+
"@prisma-next/ids": "0.13.0-dev.21",
|
|
14
|
+
"@prisma-next/sql-contract": "0.13.0-dev.21",
|
|
15
|
+
"@prisma-next/sql-contract-psl": "0.13.0-dev.21",
|
|
16
|
+
"@prisma-next/sql-contract-ts": "0.13.0-dev.21",
|
|
17
|
+
"@prisma-next/sql-operations": "0.13.0-dev.21",
|
|
18
|
+
"@prisma-next/sql-relational-core": "0.13.0-dev.21",
|
|
19
|
+
"@prisma-next/sql-runtime": "0.13.0-dev.21",
|
|
20
|
+
"@prisma-next/sql-schema-ir": "0.13.0-dev.21",
|
|
21
|
+
"@prisma-next/target-postgres": "0.13.0-dev.21",
|
|
22
|
+
"@prisma-next/utils": "0.13.0-dev.21",
|
|
23
23
|
"arktype": "^2.2.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@prisma-next/cli": "0.13.0-dev.
|
|
27
|
-
"@prisma-next/driver-postgres": "0.13.0-dev.
|
|
28
|
-
"@prisma-next/migration-tools": "0.13.0-dev.
|
|
29
|
-
"@prisma-next/test-utils": "0.13.0-dev.
|
|
30
|
-
"@prisma-next/tsconfig": "0.13.0-dev.
|
|
31
|
-
"@prisma-next/tsdown": "0.13.0-dev.
|
|
26
|
+
"@prisma-next/cli": "0.13.0-dev.21",
|
|
27
|
+
"@prisma-next/driver-postgres": "0.13.0-dev.21",
|
|
28
|
+
"@prisma-next/migration-tools": "0.13.0-dev.21",
|
|
29
|
+
"@prisma-next/test-utils": "0.13.0-dev.21",
|
|
30
|
+
"@prisma-next/tsconfig": "0.13.0-dev.21",
|
|
31
|
+
"@prisma-next/tsdown": "0.13.0-dev.21",
|
|
32
32
|
"pathe": "^2.0.3",
|
|
33
33
|
"tsdown": "0.22.1",
|
|
34
34
|
"typescript": "5.9.3",
|
package/src/core/adapter.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CodecRegistry } from '@prisma-next/framework-components/codec';
|
|
2
2
|
import { APP_SPACE_ID } from '@prisma-next/framework-components/control';
|
|
3
3
|
import type {
|
|
4
4
|
Adapter,
|
|
@@ -13,7 +13,6 @@ import type { RawCodecInferer } from '@prisma-next/sql-relational-core/expressio
|
|
|
13
13
|
import type { PostgresDdlNode } from '@prisma-next/target-postgres/ddl';
|
|
14
14
|
import { createPostgresBuiltinCodecLookup } from './codec-lookup';
|
|
15
15
|
import { PostgresControlAdapter } from './control-adapter';
|
|
16
|
-
import { renderLoweredDdl } from './ddl-renderer';
|
|
17
16
|
import { renderLoweredSql } from './sql-renderer';
|
|
18
17
|
import type { PostgresAdapterOptions, PostgresContract, PostgresLoweredStatement } from './types';
|
|
19
18
|
|
|
@@ -42,7 +41,7 @@ class PostgresAdapterImpl
|
|
|
42
41
|
readonly targetId = 'postgres' as const;
|
|
43
42
|
|
|
44
43
|
readonly profile: AdapterProfile<'postgres'>;
|
|
45
|
-
private readonly codecLookup:
|
|
44
|
+
private readonly codecLookup: CodecRegistry;
|
|
46
45
|
|
|
47
46
|
constructor(options?: PostgresAdapterOptions) {
|
|
48
47
|
this.codecLookup = options?.codecLookup ?? createPostgresBuiltinCodecLookup();
|
|
@@ -75,7 +74,9 @@ class PostgresAdapterImpl
|
|
|
75
74
|
context: LowererContext<PostgresContract>,
|
|
76
75
|
): PostgresLoweredStatement {
|
|
77
76
|
if (isDdlNode(ast)) {
|
|
78
|
-
|
|
77
|
+
throw new Error(
|
|
78
|
+
'lower() does not lower DDL on the runtime adapter — DDL lowering is a control-plane concern handled by the control adapter.',
|
|
79
|
+
);
|
|
79
80
|
}
|
|
80
81
|
return renderLoweredSql(ast, context.contract, this.codecLookup);
|
|
81
82
|
}
|
package/src/core/codec-lookup.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CodecRegistry } from '@prisma-next/framework-components/codec';
|
|
2
2
|
import { extractCodecLookup } from '@prisma-next/framework-components/control';
|
|
3
3
|
import { postgresCodecRegistry } from '@prisma-next/target-postgres/codecs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Build a {@link
|
|
6
|
+
* Build a {@link CodecRegistry} populated with the Postgres-builtin codec definitions only.
|
|
7
7
|
*
|
|
8
|
-
* This is the default
|
|
8
|
+
* This is the default registry used by `createPostgresAdapter()` and `new PostgresControlAdapter()` when called without a stack-derived registry (e.g. from tests, or one-off scripts that don't compose a full stack).
|
|
9
9
|
*
|
|
10
|
-
* Extension codecs (e.g. `pg/vector@1` from `@prisma-next/extension-pgvector`) are intentionally NOT included here: a bare adapter cannot see extensions. Stack-composed paths (`SqlControlAdapterDescriptor.create(stack)` / `SqlRuntimeAdapterDescriptor.create(stack)`) supply the broader, extension-inclusive
|
|
10
|
+
* Extension codecs (e.g. `pg/vector@1` from `@prisma-next/extension-pgvector`) are intentionally NOT included here: a bare adapter cannot see extensions. Stack-composed paths (`SqlControlAdapterDescriptor.create(stack)` / `SqlRuntimeAdapterDescriptor.create(stack)`) supply the broader, extension-inclusive registry at construction time.
|
|
11
11
|
*/
|
|
12
|
-
export function createPostgresBuiltinCodecLookup():
|
|
12
|
+
export function createPostgresBuiltinCodecLookup(): CodecRegistry {
|
|
13
13
|
return extractCodecLookup([
|
|
14
14
|
{
|
|
15
15
|
id: 'postgres-builtin-codecs',
|
|
@@ -10,10 +10,11 @@ import {
|
|
|
10
10
|
} from '@prisma-next/errors/execution';
|
|
11
11
|
import type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';
|
|
12
12
|
import { parseContractMarkerRow } from '@prisma-next/family-sql/verify';
|
|
13
|
-
import type { CodecLookup } from '@prisma-next/framework-components/codec';
|
|
13
|
+
import type { CodecLookup, CodecRegistry } from '@prisma-next/framework-components/codec';
|
|
14
14
|
import { APP_SPACE_ID } from '@prisma-next/framework-components/control';
|
|
15
15
|
import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
|
|
16
16
|
import { ledgerOriginFromStored } from '@prisma-next/migration-tools/ledger-origin';
|
|
17
|
+
import { REFERENTIAL_ACTION_SQL } from '@prisma-next/sql-contract/referential-action-sql';
|
|
17
18
|
import type {
|
|
18
19
|
PostgresEnumStorageEntry,
|
|
19
20
|
SqlControlDriverInstance,
|
|
@@ -21,10 +22,17 @@ import type {
|
|
|
21
22
|
} from '@prisma-next/sql-contract/types';
|
|
22
23
|
import type {
|
|
23
24
|
AnyQueryAst,
|
|
25
|
+
CodecRef,
|
|
26
|
+
ContractCodecRegistry,
|
|
27
|
+
DdlColumn,
|
|
24
28
|
DdlNode,
|
|
29
|
+
DdlTableConstraint,
|
|
30
|
+
FunctionColumnDefault,
|
|
31
|
+
LiteralColumnDefault,
|
|
25
32
|
LoweredStatement,
|
|
26
33
|
LowererContext,
|
|
27
34
|
MarkerReadResult,
|
|
35
|
+
SqlExecuteRequest,
|
|
28
36
|
} from '@prisma-next/sql-relational-core/ast';
|
|
29
37
|
import { isDdlNode } from '@prisma-next/sql-relational-core/ast';
|
|
30
38
|
import type {
|
|
@@ -42,19 +50,22 @@ import {
|
|
|
42
50
|
buildControlTableBootstrapQueries,
|
|
43
51
|
buildSignMarkerBootstrapQueries,
|
|
44
52
|
} from '@prisma-next/target-postgres/contract-free';
|
|
45
|
-
import type {
|
|
53
|
+
import type {
|
|
54
|
+
PostgresCreateSchema,
|
|
55
|
+
PostgresCreateTable,
|
|
56
|
+
PostgresDdlNode,
|
|
57
|
+
} from '@prisma-next/target-postgres/ddl';
|
|
46
58
|
import { parsePostgresDefault } from '@prisma-next/target-postgres/default-normalizer';
|
|
47
59
|
import {
|
|
48
60
|
createResolveExistingEnumValues,
|
|
49
|
-
enumStorageCompoundKey,
|
|
50
61
|
readExistingEnumValues,
|
|
51
62
|
readPostgresSchemaIrAnnotations,
|
|
52
63
|
} from '@prisma-next/target-postgres/enum-planning';
|
|
53
64
|
import { normalizeSchemaNativeType } from '@prisma-next/target-postgres/native-type-normalizer';
|
|
65
|
+
import { escapeLiteral, quoteIdentifier } from '@prisma-next/target-postgres/sql-utils';
|
|
54
66
|
import { blindCast } from '@prisma-next/utils/casts';
|
|
55
67
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
56
|
-
import {
|
|
57
|
-
import { renderLoweredDdl } from './ddl-renderer';
|
|
68
|
+
import { encodeControlQueryParams } from './control-codecs';
|
|
58
69
|
import {
|
|
59
70
|
introspectPostgresEnumTypes,
|
|
60
71
|
type PostgresEnumStorageTypeAnnotation,
|
|
@@ -92,17 +103,10 @@ export class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
92
103
|
readonly familyId = 'sql' as const;
|
|
93
104
|
readonly targetId = 'postgres' as const;
|
|
94
105
|
|
|
95
|
-
private readonly
|
|
106
|
+
private readonly codecRegistry: CodecRegistry;
|
|
96
107
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
* per-codec metadata at lower-time. Defaults to a Postgres-builtins-only
|
|
100
|
-
* lookup when omitted. Stack-aware callers
|
|
101
|
-
* (`SqlControlAdapterDescriptor.create(stack)`) supply
|
|
102
|
-
* `stack.codecLookup` so extension codecs are visible to the renderer.
|
|
103
|
-
*/
|
|
104
|
-
constructor(codecLookup?: CodecLookup) {
|
|
105
|
-
this.codecLookup = codecLookup ?? createPostgresBuiltinCodecLookup();
|
|
108
|
+
constructor(codecRegistry: CodecRegistry) {
|
|
109
|
+
this.codecRegistry = codecRegistry;
|
|
106
110
|
}
|
|
107
111
|
|
|
108
112
|
/**
|
|
@@ -157,9 +161,46 @@ export class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
157
161
|
*/
|
|
158
162
|
lower(ast: AnyQueryAst | PostgresDdlNode, context: LowererContext<unknown>): LoweredStatement {
|
|
159
163
|
if (isDdlNode(ast)) {
|
|
160
|
-
|
|
164
|
+
throw new Error(
|
|
165
|
+
'lower() cannot lower DDL: DDL default literals require inline codec encoding, which is async. Use lowerToExecuteRequest().',
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
return renderLoweredSql(
|
|
169
|
+
ast,
|
|
170
|
+
blindCast<PostgresContract, 'caller must supply a matching PostgresContract'>(
|
|
171
|
+
context.contract,
|
|
172
|
+
),
|
|
173
|
+
this.codecRegistry,
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Lower an AST all the way to a driver-ready statement. For DDL nodes,
|
|
179
|
+
* literal column defaults are formatted as inline SQL with proper quoting and
|
|
180
|
+
* `::nativeType` cast suffixes. For query ASTs, params are kept as `$N`
|
|
181
|
+
* placeholders; wire values go in `params`. Does NOT call `this.lower()` —
|
|
182
|
+
* independent implementation.
|
|
183
|
+
*/
|
|
184
|
+
async lowerToExecuteRequest(
|
|
185
|
+
ast: AnyQueryAst | PostgresDdlNode,
|
|
186
|
+
context?: LowererContext<unknown>,
|
|
187
|
+
): Promise<SqlExecuteRequest> {
|
|
188
|
+
if (isDdlNode(ast)) {
|
|
189
|
+
return pgRenderDdlExecuteRequest(
|
|
190
|
+
blindCast<PostgresDdlNode, 'isDdlNode guard'>(ast),
|
|
191
|
+
this.codecRegistry,
|
|
192
|
+
);
|
|
161
193
|
}
|
|
162
|
-
|
|
194
|
+
const contract = blindCast<PostgresContract, 'Caller must supply matching contract'>(
|
|
195
|
+
context?.contract,
|
|
196
|
+
);
|
|
197
|
+
const lowered = renderLoweredSql(ast, contract, this.codecRegistry);
|
|
198
|
+
const codecRegistry = blindCast<
|
|
199
|
+
ContractCodecRegistry,
|
|
200
|
+
'framework CodecRegistry: its descriptors materialise SQL codecs; the framework Codec type erases to BaseCodec at this boundary'
|
|
201
|
+
>(this.codecRegistry);
|
|
202
|
+
const params = await encodeControlQueryParams(lowered, ast, codecRegistry);
|
|
203
|
+
return { sql: lowered.sql, params };
|
|
163
204
|
}
|
|
164
205
|
|
|
165
206
|
/**
|
|
@@ -625,16 +666,18 @@ export class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
625
666
|
}
|
|
626
667
|
}
|
|
627
668
|
|
|
628
|
-
const
|
|
629
|
-
for (
|
|
630
|
-
const
|
|
631
|
-
|
|
632
|
-
|
|
669
|
+
const mergedEnumTypes: Record<string, Record<string, PostgresEnumStorageTypeAnnotation>> = {};
|
|
670
|
+
for (const ir of perSchema) {
|
|
671
|
+
const enumTypes = blindCast<
|
|
672
|
+
| { enumTypes?: Record<string, Record<string, PostgresEnumStorageTypeAnnotation>> }
|
|
673
|
+
| undefined,
|
|
633
674
|
'pg annotation envelope index slot'
|
|
634
|
-
>(ir?.annotations?.['pg'])?.
|
|
635
|
-
if (!
|
|
636
|
-
for (const [
|
|
637
|
-
|
|
675
|
+
>(ir?.annotations?.['pg'])?.enumTypes;
|
|
676
|
+
if (!enumTypes) continue;
|
|
677
|
+
for (const [schemaName, byType] of Object.entries(enumTypes)) {
|
|
678
|
+
const merged = mergedEnumTypes[schemaName] ?? {};
|
|
679
|
+
Object.assign(merged, byType);
|
|
680
|
+
mergedEnumTypes[schemaName] = merged;
|
|
638
681
|
}
|
|
639
682
|
}
|
|
640
683
|
|
|
@@ -650,8 +693,8 @@ export class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
650
693
|
pg: {
|
|
651
694
|
...firstPg,
|
|
652
695
|
...ifDefined(
|
|
653
|
-
'
|
|
654
|
-
Object.keys(
|
|
696
|
+
'enumTypes',
|
|
697
|
+
Object.keys(mergedEnumTypes).length > 0 ? mergedEnumTypes : undefined,
|
|
655
698
|
),
|
|
656
699
|
},
|
|
657
700
|
}),
|
|
@@ -1093,20 +1136,17 @@ export class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
1093
1136
|
};
|
|
1094
1137
|
}
|
|
1095
1138
|
|
|
1096
|
-
const
|
|
1097
|
-
const
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
}
|
|
1139
|
+
const rawEnumTypes = await introspectPostgresEnumTypes({ driver, schemaName: schema });
|
|
1140
|
+
const enumTypes: Record<
|
|
1141
|
+
string,
|
|
1142
|
+
Record<string, PostgresEnumStorageTypeAnnotation>
|
|
1143
|
+
> = Object.keys(rawEnumTypes).length > 0 ? { [schema]: rawEnumTypes } : {};
|
|
1101
1144
|
|
|
1102
1145
|
const annotations = {
|
|
1103
1146
|
pg: {
|
|
1104
1147
|
schema,
|
|
1105
1148
|
version: await this.getPostgresVersion(driver),
|
|
1106
|
-
...ifDefined(
|
|
1107
|
-
'storageTypes',
|
|
1108
|
-
Object.keys(storageTypes).length > 0 ? storageTypes : undefined,
|
|
1109
|
-
),
|
|
1149
|
+
...ifDefined('enumTypes', Object.keys(enumTypes).length > 0 ? enumTypes : undefined),
|
|
1110
1150
|
},
|
|
1111
1151
|
};
|
|
1112
1152
|
|
|
@@ -1368,3 +1408,167 @@ function extractQuotedLiterals(listBody: string): readonly string[] | undefined
|
|
|
1368
1408
|
const values = [...listBody.matchAll(pattern)].map((m) => (m[1] ?? '').replace(/''/g, "'"));
|
|
1369
1409
|
return values.length > 0 ? values : undefined;
|
|
1370
1410
|
}
|
|
1411
|
+
|
|
1412
|
+
// ---------------------------------------------------------------------------
|
|
1413
|
+
// pgRenderDdlExecuteRequest — independent DDL walker for lowerToExecuteRequest
|
|
1414
|
+
// ---------------------------------------------------------------------------
|
|
1415
|
+
|
|
1416
|
+
function pgIsTextLikeNativeType(nativeType: string): boolean {
|
|
1417
|
+
return (
|
|
1418
|
+
nativeType === 'text' ||
|
|
1419
|
+
nativeType === 'varchar' ||
|
|
1420
|
+
nativeType.startsWith('varchar(') ||
|
|
1421
|
+
nativeType === 'character varying' ||
|
|
1422
|
+
nativeType.startsWith('character varying(') ||
|
|
1423
|
+
nativeType === 'char' ||
|
|
1424
|
+
nativeType.startsWith('char(') ||
|
|
1425
|
+
nativeType === 'character' ||
|
|
1426
|
+
nativeType.startsWith('character(')
|
|
1427
|
+
);
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
function pgInlineLiteral(wire: unknown, nativeType: string): string {
|
|
1431
|
+
if (wire === null) return 'NULL';
|
|
1432
|
+
if (typeof wire === 'boolean') return wire ? 'true' : 'false';
|
|
1433
|
+
if (typeof wire === 'number') {
|
|
1434
|
+
if (!Number.isFinite(wire)) {
|
|
1435
|
+
throw new Error(
|
|
1436
|
+
`pgRenderDdlExecuteRequest: non-finite number wire value ${String(wire)} cannot be emitted as a DEFAULT literal for native type "${nativeType}"`,
|
|
1437
|
+
);
|
|
1438
|
+
}
|
|
1439
|
+
return String(wire);
|
|
1440
|
+
}
|
|
1441
|
+
if (typeof wire === 'bigint') return String(wire);
|
|
1442
|
+
if (wire instanceof Date) {
|
|
1443
|
+
if (Number.isNaN(wire.getTime())) {
|
|
1444
|
+
throw new Error(
|
|
1445
|
+
`pgRenderDdlExecuteRequest: invalid Date value cannot be emitted as a DEFAULT literal for native type "${nativeType}"`,
|
|
1446
|
+
);
|
|
1447
|
+
}
|
|
1448
|
+
const quoted = `'${escapeLiteral(wire.toISOString())}'`;
|
|
1449
|
+
return pgIsTextLikeNativeType(nativeType) ? quoted : `${quoted}::${nativeType}`;
|
|
1450
|
+
}
|
|
1451
|
+
if (typeof wire === 'string') {
|
|
1452
|
+
const quoted = `'${escapeLiteral(wire)}'`;
|
|
1453
|
+
return pgIsTextLikeNativeType(nativeType) ? quoted : `${quoted}::${nativeType}`;
|
|
1454
|
+
}
|
|
1455
|
+
if (wire instanceof Uint8Array) {
|
|
1456
|
+
const hex = Array.from(wire)
|
|
1457
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
1458
|
+
.join('');
|
|
1459
|
+
return `'\\x${hex}'::${nativeType}`;
|
|
1460
|
+
}
|
|
1461
|
+
if (typeof wire === 'object') {
|
|
1462
|
+
const quoted = `'${escapeLiteral(JSON.stringify(wire))}'`;
|
|
1463
|
+
return `${quoted}::${nativeType}`;
|
|
1464
|
+
}
|
|
1465
|
+
throw new Error(
|
|
1466
|
+
`pgRenderDdlExecuteRequest: unexpected wire type "${typeof wire}" for native type "${nativeType}"`,
|
|
1467
|
+
);
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
async function pgRenderDdlColumnDefault(
|
|
1471
|
+
def: LiteralColumnDefault | FunctionColumnDefault,
|
|
1472
|
+
nativeType: string,
|
|
1473
|
+
codecLookup: CodecLookup,
|
|
1474
|
+
codecRef: CodecRef | undefined,
|
|
1475
|
+
): Promise<string> {
|
|
1476
|
+
if (def.kind === 'function') {
|
|
1477
|
+
if (def.expression === 'autoincrement()') return '';
|
|
1478
|
+
return `DEFAULT (${def.expression})`;
|
|
1479
|
+
}
|
|
1480
|
+
if (codecRef !== undefined) {
|
|
1481
|
+
const codec = codecLookup.get(codecRef.codecId);
|
|
1482
|
+
if (codec !== undefined) {
|
|
1483
|
+
const wire = await codec.encode(def.value, {});
|
|
1484
|
+
return `DEFAULT ${pgInlineLiteral(wire, nativeType)}`;
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
// Fallback: codec-less literal defaults follow RawSqlLiteral wire-scalar semantics.
|
|
1488
|
+
return `DEFAULT ${pgInlineLiteral(def.value, nativeType)}`;
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
async function pgRenderDdlColumn(column: DdlColumn, codecLookup: CodecLookup): Promise<string> {
|
|
1492
|
+
const parts = [quoteIdentifier(column.name), column.type];
|
|
1493
|
+
if (column.notNull) parts.push('NOT NULL');
|
|
1494
|
+
if (column.primaryKey) parts.push('PRIMARY KEY');
|
|
1495
|
+
if (column.default) {
|
|
1496
|
+
const clause = await pgRenderDdlColumnDefault(
|
|
1497
|
+
column.default,
|
|
1498
|
+
column.type,
|
|
1499
|
+
codecLookup,
|
|
1500
|
+
column.codecRef,
|
|
1501
|
+
);
|
|
1502
|
+
if (clause.length > 0) parts.push(clause);
|
|
1503
|
+
}
|
|
1504
|
+
return parts.join(' ');
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
function pgRenderDdlConstraint(constraint: DdlTableConstraint): string {
|
|
1508
|
+
if (constraint.kind === 'primary-key') {
|
|
1509
|
+
const cols = constraint.columns.map(quoteIdentifier).join(', ');
|
|
1510
|
+
if (constraint.name !== undefined) {
|
|
1511
|
+
return `CONSTRAINT ${quoteIdentifier(constraint.name)} PRIMARY KEY (${cols})`;
|
|
1512
|
+
}
|
|
1513
|
+
return `PRIMARY KEY (${cols})`;
|
|
1514
|
+
}
|
|
1515
|
+
if (constraint.kind === 'foreign-key') {
|
|
1516
|
+
const cols = constraint.columns.map(quoteIdentifier).join(', ');
|
|
1517
|
+
const refTable = constraint.refTable.split('.').map(quoteIdentifier).join('.');
|
|
1518
|
+
const refCols = constraint.refColumns.map(quoteIdentifier).join(', ');
|
|
1519
|
+
let sql = `FOREIGN KEY (${cols}) REFERENCES ${refTable} (${refCols})`;
|
|
1520
|
+
if (constraint.onDelete !== undefined) {
|
|
1521
|
+
sql += ` ON DELETE ${REFERENTIAL_ACTION_SQL[constraint.onDelete]}`;
|
|
1522
|
+
}
|
|
1523
|
+
if (constraint.onUpdate !== undefined) {
|
|
1524
|
+
sql += ` ON UPDATE ${REFERENTIAL_ACTION_SQL[constraint.onUpdate]}`;
|
|
1525
|
+
}
|
|
1526
|
+
if (constraint.name !== undefined) {
|
|
1527
|
+
sql = `CONSTRAINT ${quoteIdentifier(constraint.name)} ${sql}`;
|
|
1528
|
+
}
|
|
1529
|
+
return sql;
|
|
1530
|
+
}
|
|
1531
|
+
const cols = constraint.columns.map(quoteIdentifier).join(', ');
|
|
1532
|
+
if (constraint.name !== undefined) {
|
|
1533
|
+
return `CONSTRAINT ${quoteIdentifier(constraint.name)} UNIQUE (${cols})`;
|
|
1534
|
+
}
|
|
1535
|
+
return `UNIQUE (${cols})`;
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
async function pgRenderCreateTable(
|
|
1539
|
+
node: PostgresCreateTable,
|
|
1540
|
+
codecLookup: CodecLookup,
|
|
1541
|
+
): Promise<SqlExecuteRequest> {
|
|
1542
|
+
const ifNotExists = node.ifNotExists ? 'IF NOT EXISTS ' : '';
|
|
1543
|
+
const tableRef = node.schema
|
|
1544
|
+
? `${quoteIdentifier(node.schema)}.${quoteIdentifier(node.table)}`
|
|
1545
|
+
: quoteIdentifier(node.table);
|
|
1546
|
+
const columnDefs = await Promise.all(
|
|
1547
|
+
node.columns.map((col) => pgRenderDdlColumn(col, codecLookup)),
|
|
1548
|
+
);
|
|
1549
|
+
const constraintDefs =
|
|
1550
|
+
node.constraints !== undefined ? node.constraints.map(pgRenderDdlConstraint) : [];
|
|
1551
|
+
const allDefs = [...columnDefs, ...constraintDefs].join(',\n ');
|
|
1552
|
+
return {
|
|
1553
|
+
sql: `CREATE TABLE ${ifNotExists}${tableRef} (\n ${allDefs}\n)`,
|
|
1554
|
+
params: [],
|
|
1555
|
+
};
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
function pgRenderCreateSchema(node: PostgresCreateSchema): SqlExecuteRequest {
|
|
1559
|
+
const ifNotExists = node.ifNotExists ? 'IF NOT EXISTS ' : '';
|
|
1560
|
+
return {
|
|
1561
|
+
sql: `CREATE SCHEMA ${ifNotExists}${quoteIdentifier(node.schema)}`,
|
|
1562
|
+
params: [],
|
|
1563
|
+
};
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
async function pgRenderDdlExecuteRequest(
|
|
1567
|
+
ast: PostgresDdlNode,
|
|
1568
|
+
codecLookup: CodecLookup,
|
|
1569
|
+
): Promise<SqlExecuteRequest> {
|
|
1570
|
+
if (ast.kind === 'create-table') {
|
|
1571
|
+
return pgRenderCreateTable(blindCast<PostgresCreateTable, 'kind guard'>(ast), codecLookup);
|
|
1572
|
+
}
|
|
1573
|
+
return pgRenderCreateSchema(blindCast<PostgresCreateSchema, 'kind guard'>(ast));
|
|
1574
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnyQueryAst,
|
|
3
|
+
ContractCodecRegistry,
|
|
4
|
+
LoweredStatement,
|
|
5
|
+
} from '@prisma-next/sql-relational-core/ast';
|
|
6
|
+
import {
|
|
7
|
+
createAstCodecRegistry,
|
|
8
|
+
deriveParamMetadata,
|
|
9
|
+
encodeParamsWithMetadata,
|
|
10
|
+
} from '@prisma-next/sql-runtime';
|
|
11
|
+
import { postgresCodecRegistry } from '@prisma-next/target-postgres/codecs';
|
|
12
|
+
|
|
13
|
+
export const CONTROL_CODECS = createAstCodecRegistry(postgresCodecRegistry);
|
|
14
|
+
|
|
15
|
+
export async function encodeControlQueryParams(
|
|
16
|
+
lowered: LoweredStatement,
|
|
17
|
+
ast: AnyQueryAst,
|
|
18
|
+
codecs: ContractCodecRegistry = CONTROL_CODECS,
|
|
19
|
+
): Promise<readonly unknown[]> {
|
|
20
|
+
const values = lowered.params.map((slot) => {
|
|
21
|
+
if (slot.kind === 'literal') return slot.value;
|
|
22
|
+
throw new Error(`control query lowered to a bind slot '${slot.name}', which is unsupported`);
|
|
23
|
+
});
|
|
24
|
+
return encodeParamsWithMetadata(values, deriveParamMetadata(ast), {}, codecs);
|
|
25
|
+
}
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
PG_TIMESTAMP_CODEC_ID,
|
|
28
28
|
PG_TIMESTAMPTZ_CODEC_ID,
|
|
29
29
|
PG_TIMETZ_CODEC_ID,
|
|
30
|
+
PG_UUID_CODEC_ID,
|
|
30
31
|
PG_VARBIT_CODEC_ID,
|
|
31
32
|
PG_VARCHAR_CODEC_ID,
|
|
32
33
|
SQL_CHAR_CODEC_ID,
|
|
@@ -215,6 +216,7 @@ export const postgresAdapterDescriptorMeta = {
|
|
|
215
216
|
[PG_JSON_CODEC_ID]: identityHooks,
|
|
216
217
|
[PG_JSONB_CODEC_ID]: identityHooks,
|
|
217
218
|
[PG_BYTEA_CODEC_ID]: identityHooks,
|
|
219
|
+
[PG_UUID_CODEC_ID]: identityHooks,
|
|
218
220
|
},
|
|
219
221
|
},
|
|
220
222
|
storage: [
|
|
@@ -281,6 +283,7 @@ export const postgresAdapterDescriptorMeta = {
|
|
|
281
283
|
{ typeId: PG_JSON_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'json' },
|
|
282
284
|
{ typeId: PG_JSONB_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'jsonb' },
|
|
283
285
|
{ typeId: PG_BYTEA_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'bytea' },
|
|
286
|
+
{ typeId: PG_UUID_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'uuid' },
|
|
284
287
|
],
|
|
285
288
|
queryOperationTypes: {
|
|
286
289
|
import: {
|
|
@@ -4,13 +4,7 @@ import {
|
|
|
4
4
|
type LoweredStatement,
|
|
5
5
|
RawExpr,
|
|
6
6
|
} from '@prisma-next/sql-relational-core/ast';
|
|
7
|
-
import {
|
|
8
|
-
createAstCodecRegistry,
|
|
9
|
-
deriveParamMetadata,
|
|
10
|
-
encodeParamsWithMetadata,
|
|
11
|
-
} from '@prisma-next/sql-runtime';
|
|
12
7
|
import { PG_TIMESTAMPTZ_CODEC_ID } from '@prisma-next/target-postgres/codec-ids';
|
|
13
|
-
import { postgresCodecRegistry } from '@prisma-next/target-postgres/codecs';
|
|
14
8
|
import {
|
|
15
9
|
int4,
|
|
16
10
|
int8,
|
|
@@ -20,8 +14,7 @@ import {
|
|
|
20
14
|
textArray,
|
|
21
15
|
timestamptz,
|
|
22
16
|
} from '@prisma-next/target-postgres/contract-free';
|
|
23
|
-
|
|
24
|
-
const CONTROL_CODECS = createAstCodecRegistry(postgresCodecRegistry);
|
|
17
|
+
import { encodeControlQueryParams } from './control-codecs';
|
|
25
18
|
|
|
26
19
|
export const marker = pgTable(
|
|
27
20
|
{ name: 'marker', schema: 'prisma_contract' },
|
|
@@ -105,16 +98,7 @@ export async function execute(
|
|
|
105
98
|
query: AnyQueryAst,
|
|
106
99
|
): Promise<readonly Record<string, unknown>[]> {
|
|
107
100
|
const lowered = lower(query);
|
|
108
|
-
const
|
|
109
|
-
if (slot.kind === 'literal') return slot.value;
|
|
110
|
-
throw new Error('Postgres control DML lowered to a bind parameter, which is unsupported');
|
|
111
|
-
});
|
|
112
|
-
const encoded = await encodeParamsWithMetadata(
|
|
113
|
-
values,
|
|
114
|
-
deriveParamMetadata(query),
|
|
115
|
-
{},
|
|
116
|
-
CONTROL_CODECS,
|
|
117
|
-
);
|
|
101
|
+
const encoded = await encodeControlQueryParams(lowered, query);
|
|
118
102
|
const result = await driver.query(lowered.sql, encoded);
|
|
119
103
|
return result.rows;
|
|
120
104
|
}
|