@prisma-next/adapter-postgres 0.5.0-dev.9 → 0.5.1
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 +14 -16
- package/dist/adapter-CBaRvhQF.mjs +52 -0
- package/dist/adapter-CBaRvhQF.mjs.map +1 -0
- package/dist/adapter.d.mts +3 -4
- package/dist/adapter.d.mts.map +1 -1
- package/dist/adapter.mjs +2 -3
- package/dist/column-types.d.mts +19 -24
- package/dist/column-types.d.mts.map +1 -1
- package/dist/column-types.mjs +20 -60
- package/dist/column-types.mjs.map +1 -1
- package/dist/control.d.mts +83 -3
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +117 -29
- package/dist/control.mjs.map +1 -1
- package/dist/{descriptor-meta-RTDzyrae.mjs → descriptor-meta-CyjnYUWG.mjs} +35 -27
- package/dist/descriptor-meta-CyjnYUWG.mjs.map +1 -0
- package/dist/operation-types.d.mts +11 -10
- package/dist/operation-types.d.mts.map +1 -1
- package/dist/operation-types.mjs +1 -1
- package/dist/runtime.d.mts +3 -11
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +19 -81
- package/dist/runtime.mjs.map +1 -1
- package/dist/{sql-renderer-pEaSP82_.mjs → sql-renderer-wTVSEy5H.mjs} +109 -48
- package/dist/sql-renderer-wTVSEy5H.mjs.map +1 -0
- package/dist/{types-CfRPdAk8.d.mts → types-B1eiuBHQ.d.mts} +12 -1
- package/dist/types-B1eiuBHQ.d.mts.map +1 -0
- package/dist/types.d.mts +1 -1
- package/dist/types.mjs +1 -1
- package/package.json +23 -23
- package/src/core/adapter.ts +36 -43
- package/src/core/codec-lookup.ts +19 -0
- package/src/core/control-adapter.ts +252 -98
- package/src/core/control-mutation-defaults.ts +24 -18
- package/src/core/descriptor-meta.ts +27 -20
- package/src/core/sql-renderer.ts +129 -66
- package/src/core/types.ts +11 -0
- package/src/exports/column-types.ts +21 -61
- package/src/exports/control.ts +3 -2
- package/src/exports/runtime.ts +27 -66
- package/src/types/operation-types.ts +19 -9
- package/dist/adapter-hNElNHo4.mjs +0 -60
- package/dist/adapter-hNElNHo4.mjs.map +0 -1
- package/dist/descriptor-meta-RTDzyrae.mjs.map +0 -1
- package/dist/sql-renderer-pEaSP82_.mjs.map +0 -1
- package/dist/types-CfRPdAk8.d.mts.map +0 -1
- package/src/core/json-schema-validator.ts +0 -54
- package/src/core/standard-schema.ts +0 -71
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor-meta-CyjnYUWG.mjs","names":[],"sources":["../src/core/enum-control-hooks.ts","../src/core/descriptor-meta.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type { CodecControlHooks, SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport { arraysEqual } from '@prisma-next/family-sql/schema-verify';\nimport type { SqlStorage, StorageTypeInstance } from '@prisma-next/sql-contract/types';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\nimport { PG_ENUM_CODEC_ID } from '@prisma-next/target-postgres/codec-ids';\nimport {\n escapeLiteral,\n qualifyName,\n quoteIdentifier,\n validateEnumValueLength,\n} from '@prisma-next/target-postgres/sql-utils';\n\n/**\n * Postgres enum control hooks.\n *\n * - Plans enum type operations for migrations\n * - Verifies enum types in schema IR\n * - Introspects enum types from the database\n */\ntype EnumRow = {\n schema_name: string;\n type_name: string;\n values: string[];\n};\n\ntype EnumDiff =\n | { kind: 'unchanged' }\n | { kind: 'add_values'; values: readonly string[] }\n | { kind: 'rebuild'; removedValues: readonly string[] };\n\n// ============================================================================\n// Introspection SQL\n// ============================================================================\n\nconst ENUM_INTROSPECT_QUERY = `\n SELECT\n n.nspname AS schema_name,\n t.typname AS type_name,\n array_agg(e.enumlabel ORDER BY e.enumsortorder) AS values\n FROM pg_type t\n JOIN pg_namespace n ON t.typnamespace = n.oid\n JOIN pg_enum e ON t.oid = e.enumtypid\n WHERE n.nspname = $1\n GROUP BY n.nspname, t.typname\n ORDER BY n.nspname, t.typname\n`;\n\n// ============================================================================\n// Schema Helpers (Simplified)\n// ============================================================================\n\n/**\n * Type guard for string arrays. Used for runtime validation of introspected data.\n */\nfunction isStringArray(value: unknown): value is string[] {\n return Array.isArray(value) && value.every((entry) => typeof entry === 'string');\n}\n\n/**\n * Parses a PostgreSQL array value into a JavaScript string array.\n *\n * PostgreSQL's `pg` library may return `array_agg` results either as:\n * - A JavaScript array (when type parsers are configured)\n * - A string in PostgreSQL array literal format: `{value1,value2,...}`\n *\n * Handles PostgreSQL's quoting rules for array elements:\n * - Elements containing commas, double quotes, backslashes, or whitespace are double-quoted\n * - Inside quoted elements, `\\\"` represents `\"` and `\\\\` represents `\\`\n *\n * @param value - The value to parse (array or PostgreSQL array string)\n * @returns A string array, or null if the value cannot be parsed\n */\nexport function parsePostgresArray(value: unknown): string[] | null {\n if (isStringArray(value)) {\n return value;\n }\n if (typeof value === 'string' && value.startsWith('{') && value.endsWith('}')) {\n const inner = value.slice(1, -1);\n if (inner === '') {\n return [];\n }\n return parseArrayElements(inner);\n }\n return null;\n}\n\nfunction parseArrayElements(input: string): string[] {\n const result: string[] = [];\n let i = 0;\n while (i < input.length) {\n if (input[i] === ',') {\n i++;\n continue;\n }\n if (input[i] === '\"') {\n i++;\n let element = '';\n while (i < input.length && input[i] !== '\"') {\n if (input[i] === '\\\\' && i + 1 < input.length) {\n i++;\n element += input[i];\n } else {\n element += input[i];\n }\n i++;\n }\n i++;\n result.push(element);\n } else {\n const nextComma = input.indexOf(',', i);\n if (nextComma === -1) {\n result.push(input.slice(i).trim());\n i = input.length;\n } else {\n result.push(input.slice(i, nextComma).trim());\n i = nextComma;\n }\n }\n }\n return result;\n}\n\n/**\n * Extracts enum values from a StorageTypeInstance.\n * Returns null if values are missing or invalid.\n */\nfunction getEnumValues(typeInstance: StorageTypeInstance): readonly string[] | null {\n const values = typeInstance.typeParams?.['values'];\n return isStringArray(values) ? values : null;\n}\n\n/**\n * Reads existing enum values from the schema IR for a given native type.\n * Uses optional chaining to simplify navigation through the annotations structure.\n */\nfunction readExistingEnumValues(schema: SqlSchemaIR, nativeType: string): readonly string[] | null {\n const storageTypes = (schema.annotations?.['pg'] as Record<string, unknown> | undefined)?.[\n 'storageTypes'\n ] as Record<string, StorageTypeInstance> | undefined;\n\n const existing = storageTypes?.[nativeType];\n if (!existing || existing.codecId !== PG_ENUM_CODEC_ID) {\n return null;\n }\n return getEnumValues(existing);\n}\n\n/**\n * Determines what changes are needed to transform existing enum values to desired values.\n *\n * Returns one of:\n * - `unchanged`: No changes needed, values match exactly\n * - `add_values`: New values can be safely appended (PostgreSQL supports this)\n * - `rebuild`: Full enum rebuild required (value removal, reordering, or both)\n *\n * Note: PostgreSQL enums can only have values added (not removed or reordered) without\n * a full type rebuild involving temp type creation and column migration.\n *\n * @param existing - Current enum values in the database\n * @param desired - Target enum values from the contract\n * @returns The type of change required\n */\nfunction determineEnumDiff(existing: readonly string[], desired: readonly string[]): EnumDiff {\n if (arraysEqual(existing, desired)) {\n return { kind: 'unchanged' };\n }\n\n // Use Sets for O(1) lookups instead of O(n) array.includes()\n const existingSet = new Set(existing);\n const desiredSet = new Set(desired);\n\n const missingValues = desired.filter((value) => !existingSet.has(value));\n const removedValues = existing.filter((value) => !desiredSet.has(value));\n const orderMismatch =\n missingValues.length === 0 && removedValues.length === 0 && !arraysEqual(existing, desired);\n\n if (removedValues.length > 0 || orderMismatch) {\n return { kind: 'rebuild', removedValues };\n }\n\n return { kind: 'add_values', values: missingValues };\n}\n\n// ============================================================================\n// SQL Helpers\n// ============================================================================\n\nfunction enumTypeExistsCheck(schemaName: string, typeName: string, exists = true): string {\n const existsClause = exists ? 'EXISTS' : 'NOT EXISTS';\n return `SELECT ${existsClause} (\n SELECT 1\n FROM pg_type t\n JOIN pg_namespace n ON t.typnamespace = n.oid\n WHERE n.nspname = '${escapeLiteral(schemaName)}'\n AND t.typname = '${escapeLiteral(typeName)}'\n)`;\n}\n\n// ============================================================================\n// Operation Builders\n// ============================================================================\n\nfunction buildCreateEnumOperation(\n typeName: string,\n nativeType: string,\n schemaName: string,\n values: readonly string[],\n): SqlMigrationPlanOperation<unknown> {\n // Validate all enum values don't exceed PostgreSQL's label length limit\n for (const value of values) {\n validateEnumValueLength(value, typeName);\n }\n const literalValues = values.map((value) => `'${escapeLiteral(value)}'`).join(', ');\n const qualifiedType = qualifyName(schemaName, nativeType);\n return {\n id: `type.${typeName}`,\n label: `Create type ${typeName}`,\n summary: `Creates enum type ${typeName}`,\n operationClass: 'additive',\n target: { id: 'postgres' },\n precheck: [\n {\n description: `ensure type \"${nativeType}\" does not exist`,\n sql: enumTypeExistsCheck(schemaName, nativeType, false),\n },\n ],\n execute: [\n {\n description: `create type \"${nativeType}\"`,\n sql: `CREATE TYPE ${qualifiedType} AS ENUM (${literalValues})`,\n },\n ],\n postcheck: [\n {\n description: `verify type \"${nativeType}\" exists`,\n sql: enumTypeExistsCheck(schemaName, nativeType),\n },\n ],\n };\n}\n\n/**\n * Computes the optimal position for inserting a new enum value to maintain\n * the desired order relative to existing values.\n *\n * PostgreSQL's `ALTER TYPE ADD VALUE` supports BEFORE/AFTER positioning.\n * This function finds the best reference value by:\n * 1. Looking for the nearest preceding value that already exists\n * 2. Falling back to the nearest following value if no preceding exists\n * 3. Defaulting to end-of-list if no reference is found\n *\n * @param options.desired - The target ordered list of all enum values\n * @param options.desiredIndex - Index of the value being inserted in the desired list\n * @param options.current - Current list of enum values (being built up incrementally)\n * @returns SQL clause (e.g., \" AFTER 'x'\") and insert position for tracking\n */\nfunction computeInsertPosition(options: {\n desired: readonly string[];\n desiredIndex: number;\n current: readonly string[];\n}): { clause: string; insertAt: number } {\n const { desired, desiredIndex, current } = options;\n const currentSet = new Set(current);\n const previous = desired\n .slice(0, desiredIndex)\n .reverse()\n .find((candidate) => currentSet.has(candidate));\n const next = desired.slice(desiredIndex + 1).find((candidate) => currentSet.has(candidate));\n const clause = previous\n ? ` AFTER '${escapeLiteral(previous)}'`\n : next\n ? ` BEFORE '${escapeLiteral(next)}'`\n : '';\n const insertAt = previous\n ? current.indexOf(previous) + 1\n : next\n ? current.indexOf(next)\n : current.length;\n\n return { clause, insertAt };\n}\n\n/**\n * Builds operations to add new enum values to an existing PostgreSQL enum type.\n *\n * Each new value is added with `ALTER TYPE ... ADD VALUE IF NOT EXISTS` for idempotency.\n * Values are inserted in the correct order using BEFORE/AFTER positioning to match\n * the desired final order.\n *\n * This is a safe, non-destructive operation - existing data is not affected.\n *\n * @param options.typeName - Contract-level type name (e.g., 'Role')\n * @param options.nativeType - PostgreSQL type name (e.g., 'role')\n * @param options.schemaName - PostgreSQL schema (e.g., 'public')\n * @param options.desired - Target ordered list of all enum values\n * @param options.existing - Current enum values in the database\n * @returns Array of migration operations to add each missing value\n */\nfunction buildAddValueOperations(options: {\n typeName: string;\n nativeType: string;\n schemaName: string;\n desired: readonly string[];\n existing: readonly string[];\n}): SqlMigrationPlanOperation<unknown>[] {\n const { typeName, nativeType, schemaName } = options;\n const current = [...options.existing];\n const currentSet = new Set(current);\n const operations: SqlMigrationPlanOperation<unknown>[] = [];\n for (let index = 0; index < options.desired.length; index += 1) {\n const value = options.desired[index];\n if (value === undefined) {\n continue;\n }\n if (currentSet.has(value)) {\n continue;\n }\n // Validate the new value doesn't exceed PostgreSQL's label length limit\n validateEnumValueLength(value, typeName);\n const { clause, insertAt } = computeInsertPosition({\n desired: options.desired,\n desiredIndex: index,\n current,\n });\n // Use IF NOT EXISTS for idempotency - safe to re-run after partial failures.\n // Supported in PostgreSQL 9.3+, and we require PostgreSQL 12+.\n operations.push({\n id: `type.${typeName}.value.${value}`,\n label: `Add value ${value} to ${typeName}`,\n summary: `Adds enum value ${value} to ${typeName}`,\n operationClass: 'widening',\n target: { id: 'postgres' },\n precheck: [],\n execute: [\n {\n description: `add value \"${value}\" if not exists`,\n sql: `ALTER TYPE ${qualifyName(schemaName, nativeType)} ADD VALUE IF NOT EXISTS '${escapeLiteral(\n value,\n )}'${clause}`,\n },\n ],\n postcheck: [],\n });\n current.splice(insertAt, 0, value);\n currentSet.add(value);\n }\n return operations;\n}\n\n/**\n * Collects columns using the enum type from the contract (desired state).\n * Used for type-safe reference tracking.\n */\nfunction collectEnumColumnsFromContract(\n contract: Contract<SqlStorage>,\n typeName: string,\n nativeType: string,\n): ReadonlyArray<{ table: string; column: string }> {\n const columns: Array<{ table: string; column: string }> = [];\n for (const [tableName, table] of Object.entries(contract.storage.tables)) {\n for (const [columnName, column] of Object.entries(table.columns)) {\n if (\n column.typeRef === typeName ||\n (column.nativeType === nativeType && column.codecId === PG_ENUM_CODEC_ID)\n ) {\n columns.push({ table: tableName, column: columnName });\n }\n }\n }\n return columns;\n}\n\n/**\n * Collects columns using the enum type from the schema IR (live database state).\n * This ensures we find ALL dependent columns, including those added outside the contract\n * (e.g., manual DDL), which is critical for safe enum rebuild operations.\n */\nfunction collectEnumColumnsFromSchema(\n schema: SqlSchemaIR,\n nativeType: string,\n): ReadonlyArray<{ table: string; column: string }> {\n const columns: Array<{ table: string; column: string }> = [];\n for (const [tableName, table] of Object.entries(schema.tables)) {\n for (const [columnName, column] of Object.entries(table.columns)) {\n // Match by nativeType since schema IR doesn't have codecId/typeRef\n if (column.nativeType === nativeType) {\n columns.push({ table: tableName, column: columnName });\n }\n }\n }\n return columns;\n}\n\n/**\n * Collects all columns using the enum type from both contract AND live database.\n * Merges and deduplicates to ensure we migrate ALL dependent columns during rebuild.\n *\n * This is critical for data integrity: if a column exists in the database using\n * this enum but is not in the contract (e.g., added via manual DDL), we must\n * still migrate it to avoid DROP TYPE failures.\n */\nfunction collectAllEnumColumns(\n contract: Contract<SqlStorage>,\n schema: SqlSchemaIR,\n typeName: string,\n nativeType: string,\n): ReadonlyArray<{ table: string; column: string }> {\n const contractColumns = collectEnumColumnsFromContract(contract, typeName, nativeType);\n const schemaColumns = collectEnumColumnsFromSchema(schema, nativeType);\n\n // Merge and deduplicate using a Set of \"table.column\" keys\n const seen = new Set<string>();\n const result: Array<{ table: string; column: string }> = [];\n\n for (const col of [...contractColumns, ...schemaColumns]) {\n const key = `${col.table}.${col.column}`;\n if (!seen.has(key)) {\n seen.add(key);\n result.push(col);\n }\n }\n\n // Sort for deterministic operation order\n return result.sort((a, b) => {\n const tableCompare = a.table.localeCompare(b.table);\n return tableCompare !== 0 ? tableCompare : a.column.localeCompare(b.column);\n });\n}\n\n/**\n * Builds a SQL check to verify a column's type matches an expected type.\n */\nfunction columnTypeCheck(options: {\n schemaName: string;\n tableName: string;\n columnName: string;\n expectedType: string;\n}): string {\n return `SELECT EXISTS (\n SELECT 1\n FROM information_schema.columns\n WHERE table_schema = '${escapeLiteral(options.schemaName)}'\n AND table_name = '${escapeLiteral(options.tableName)}'\n AND column_name = '${escapeLiteral(options.columnName)}'\n AND udt_name = '${escapeLiteral(options.expectedType)}'\n)`;\n}\n\n/** PostgreSQL maximum identifier length (NAMEDATALEN - 1) */\nconst MAX_IDENTIFIER_LENGTH = 63;\n\n/** Suffix added to enum type names during rebuild operations */\nconst REBUILD_SUFFIX = '__pn_rebuild';\n\n/**\n * Builds an SQL check to verify no rows contain any of the removed enum values.\n * This prevents data loss during enum rebuild operations.\n *\n * @param schemaName - PostgreSQL schema name\n * @param tableName - Table containing the enum column\n * @param columnName - Column using the enum type\n * @param removedValues - Array of enum values being removed\n * @returns SQL query that returns true if no rows contain removed values\n */\nfunction noRemovedValuesExistCheck(\n schemaName: string,\n tableName: string,\n columnName: string,\n removedValues: readonly string[],\n): string {\n if (removedValues.length === 0) {\n // No values being removed, always passes\n return 'SELECT true';\n }\n const valuesList = removedValues.map((v) => `'${escapeLiteral(v)}'`).join(', ');\n return `SELECT NOT EXISTS (\n SELECT 1 FROM ${qualifyName(schemaName, tableName)}\n WHERE ${quoteIdentifier(columnName)}::text IN (${valuesList})\n LIMIT 1\n)`;\n}\n\n/**\n * Builds a migration operation to recreate a PostgreSQL enum type with updated values.\n *\n * This is required when:\n * - Enum values are removed (PostgreSQL doesn't support direct removal)\n * - Enum values are reordered (PostgreSQL doesn't support reordering)\n *\n * The operation:\n * 1. Creates a new enum type with the desired values (temp name)\n * 2. Migrates all columns to use the new type via text cast\n * 3. Drops the original type\n * 4. Renames the temp type to the original name\n *\n * IMPORTANT: If values are being removed and data exists using those values,\n * the operation will fail at the precheck stage with a clear error message.\n * This prevents silent data loss.\n *\n * @param options.typeName - Contract-level type name\n * @param options.nativeType - PostgreSQL type name\n * @param options.schemaName - PostgreSQL schema\n * @param options.values - Desired final enum values\n * @param options.removedValues - Values being removed (for data loss checks)\n * @param options.contract - Full contract for column discovery\n * @param options.schema - Current schema IR for column discovery\n * @returns Migration operation for full enum rebuild\n */\nfunction buildRecreateEnumOperation(options: {\n typeName: string;\n nativeType: string;\n schemaName: string;\n values: readonly string[];\n removedValues: readonly string[];\n contract: Contract<SqlStorage>;\n schema: SqlSchemaIR;\n}): SqlMigrationPlanOperation<unknown> {\n const tempTypeName = `${options.nativeType}${REBUILD_SUFFIX}`;\n\n // Validate temp type name length won't exceed PostgreSQL's 63-character limit.\n // If it would, PostgreSQL silently truncates which could cause conflicts.\n if (tempTypeName.length > MAX_IDENTIFIER_LENGTH) {\n const maxBaseLength = MAX_IDENTIFIER_LENGTH - REBUILD_SUFFIX.length;\n throw new Error(\n `Enum type name \"${options.nativeType}\" is too long for rebuild operation. ` +\n `Maximum length is ${maxBaseLength} characters (type name + \"${REBUILD_SUFFIX}\" suffix ` +\n `must fit within PostgreSQL's ${MAX_IDENTIFIER_LENGTH}-character identifier limit).`,\n );\n }\n\n const qualifiedOriginal = qualifyName(options.schemaName, options.nativeType);\n const qualifiedTemp = qualifyName(options.schemaName, tempTypeName);\n const literalValues = options.values.map((value) => `'${escapeLiteral(value)}'`).join(', ');\n\n // CRITICAL: Collect columns from BOTH contract AND live database.\n // This ensures we migrate ALL dependent columns, including those added\n // outside of Prisma Next (e.g., manual DDL). Without this, DROP TYPE\n // would fail if the database has columns not tracked in the contract.\n const columnRefs = collectAllEnumColumns(\n options.contract,\n options.schema,\n options.typeName,\n options.nativeType,\n );\n\n const alterColumns = columnRefs.map((ref) => ({\n description: `alter ${ref.table}.${ref.column} to ${tempTypeName}`,\n sql: `ALTER TABLE ${qualifyName(options.schemaName, ref.table)}\nALTER COLUMN ${quoteIdentifier(ref.column)}\nTYPE ${qualifiedTemp}\nUSING ${quoteIdentifier(ref.column)}::text::${qualifiedTemp}`,\n }));\n\n // Build postchecks to verify:\n // 1. The final type exists with the correct name\n // 2. The temp type was cleaned up (renamed away)\n // 3. All migrated columns now reference the final type\n const postchecks = [\n {\n description: `verify type \"${options.nativeType}\" exists`,\n sql: enumTypeExistsCheck(options.schemaName, options.nativeType),\n },\n {\n description: `verify temp type \"${tempTypeName}\" was removed`,\n sql: enumTypeExistsCheck(options.schemaName, tempTypeName, false),\n },\n // Verify each column was successfully migrated to the final type\n ...columnRefs.map((ref) => ({\n description: `verify ${ref.table}.${ref.column} uses type \"${options.nativeType}\"`,\n sql: columnTypeCheck({\n schemaName: options.schemaName,\n tableName: ref.table,\n columnName: ref.column,\n expectedType: options.nativeType,\n }),\n })),\n ];\n\n return {\n id: `type.${options.typeName}.rebuild`,\n label: `Rebuild type ${options.typeName}`,\n summary: `Recreates enum type ${options.typeName} with updated values`,\n operationClass: 'destructive',\n target: { id: 'postgres' },\n precheck: [\n {\n description: `ensure type \"${options.nativeType}\" exists`,\n sql: enumTypeExistsCheck(options.schemaName, options.nativeType),\n },\n // Note: We don't precheck that temp type doesn't exist because we handle\n // orphaned temp types in the execute step below.\n\n // CRITICAL: If values are being removed, verify no data exists using those values.\n // This prevents silent data loss during the rebuild - the USING cast would fail\n // at runtime if rows contain values that don't exist in the new enum.\n ...(options.removedValues.length > 0\n ? columnRefs.map((ref) => ({\n description: `ensure no rows in ${ref.table}.${ref.column} contain removed values (${options.removedValues.join(', ')})`,\n sql: noRemovedValuesExistCheck(\n options.schemaName,\n ref.table,\n ref.column,\n options.removedValues,\n ),\n }))\n : []),\n ],\n execute: [\n // Clean up any orphaned temp type from a previous failed migration.\n // This makes the operation recoverable without manual intervention.\n // DROP TYPE IF EXISTS is safe - it's a no-op if the type doesn't exist.\n {\n description: `drop orphaned temp type \"${tempTypeName}\" if exists`,\n sql: `DROP TYPE IF EXISTS ${qualifiedTemp}`,\n },\n {\n description: `create temp type \"${tempTypeName}\"`,\n sql: `CREATE TYPE ${qualifiedTemp} AS ENUM (${literalValues})`,\n },\n ...alterColumns,\n {\n description: `drop type \"${options.nativeType}\"`,\n sql: `DROP TYPE ${qualifiedOriginal}`,\n },\n {\n description: `rename type \"${tempTypeName}\" to \"${options.nativeType}\"`,\n sql: `ALTER TYPE ${qualifiedTemp} RENAME TO ${quoteIdentifier(options.nativeType)}`,\n },\n ],\n postcheck: postchecks,\n };\n}\n\n// ============================================================================\n// Codec Control Hooks\n// ============================================================================\n\n/**\n * Postgres enum hooks for planning, verifying, and introspecting `storage.types`.\n */\nexport const pgEnumControlHooks: CodecControlHooks = {\n planTypeOperations: ({ typeName, typeInstance, contract, schema, schemaName }) => {\n const desired = getEnumValues(typeInstance);\n if (!desired || desired.length === 0) {\n return { operations: [] };\n }\n\n const schemaNamespace = schemaName ?? 'public';\n const existing = readExistingEnumValues(schema, typeInstance.nativeType);\n if (!existing) {\n return {\n operations: [\n buildCreateEnumOperation(typeName, typeInstance.nativeType, schemaNamespace, desired),\n ],\n };\n }\n\n const diff = determineEnumDiff(existing, desired);\n if (diff.kind === 'unchanged') {\n return { operations: [] };\n }\n\n if (diff.kind === 'rebuild') {\n return {\n operations: [\n buildRecreateEnumOperation({\n typeName,\n nativeType: typeInstance.nativeType,\n schemaName: schemaNamespace,\n values: desired,\n removedValues: diff.removedValues,\n contract,\n schema,\n }),\n ],\n };\n }\n\n return {\n operations: buildAddValueOperations({\n typeName,\n nativeType: typeInstance.nativeType,\n schemaName: schemaNamespace,\n desired,\n existing,\n }),\n };\n },\n verifyType: ({ typeName, typeInstance, schema }) => {\n const desired = getEnumValues(typeInstance);\n if (!desired) {\n return [];\n }\n const existing = readExistingEnumValues(schema, typeInstance.nativeType);\n if (!existing) {\n return [\n {\n kind: 'type_missing',\n typeName,\n message: `Type \"${typeName}\" is missing from database`,\n },\n ];\n }\n const diff = determineEnumDiff(existing, desired);\n if (diff.kind === 'unchanged') return [];\n const existingSet = new Set(existing);\n const desiredSet = new Set(desired);\n const addedValues = desired.filter((v) => !existingSet.has(v));\n const removedValues = existing.filter((v) => !desiredSet.has(v));\n return [\n {\n kind: 'enum_values_changed' as const,\n typeName,\n addedValues,\n removedValues,\n message:\n diff.kind === 'add_values'\n ? `Enum type \"${typeName}\" needs new values: ${addedValues.join(', ')}`\n : `Enum type \"${typeName}\" values changed (requires rebuild): +[${addedValues.join(', ')}] -[${removedValues.join(', ')}]`,\n },\n ];\n },\n introspectTypes: async ({ driver, schemaName }) => {\n const namespace = schemaName ?? 'public';\n const result = await driver.query<EnumRow>(ENUM_INTROSPECT_QUERY, [namespace]);\n const types: Record<string, StorageTypeInstance> = {};\n for (const row of result.rows) {\n const values = parsePostgresArray(row.values);\n if (!values) {\n throw new Error(\n `Failed to parse enum values for type \"${row.type_name}\": ` +\n `unexpected format: ${JSON.stringify(row.values)}`,\n );\n }\n types[row.type_name] = {\n codecId: PG_ENUM_CODEC_ID,\n nativeType: row.type_name,\n typeParams: { values },\n };\n }\n return types;\n },\n};\n","import type { CodecControlHooks, ExpandNativeTypeInput } from '@prisma-next/family-sql/control';\nimport { buildOperation, refsOf, toExpr } 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_ENUM_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_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';\nimport { pgEnumControlHooks } from './enum-control-hooks';\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: (self, pattern) => {\n const selfRefs = refsOf(self);\n return buildOperation({\n method: 'ilike',\n args: [toExpr(self), toExpr(pattern, PG_TEXT_CODEC_ID, selfRefs)],\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 },\n sql: {\n enums: true,\n returning: true,\n defaultInInsert: 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_ENUM_CODEC_ID]: pgEnumControlHooks,\n [PG_JSON_CODEC_ID]: identityHooks,\n [PG_JSONB_CODEC_ID]: identityHooks,\n [PG_BYTEA_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 ],\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":";;;;;;AAmCA,MAAM,wBAAwB;;;;;;;;;;;;;;;AAoB9B,SAAS,cAAc,OAAmC;CACxD,OAAO,MAAM,QAAQ,MAAM,IAAI,MAAM,OAAO,UAAU,OAAO,UAAU,SAAS;;;;;;;;;;;;;;;;AAiBlF,SAAgB,mBAAmB,OAAiC;CAClE,IAAI,cAAc,MAAM,EACtB,OAAO;CAET,IAAI,OAAO,UAAU,YAAY,MAAM,WAAW,IAAI,IAAI,MAAM,SAAS,IAAI,EAAE;EAC7E,MAAM,QAAQ,MAAM,MAAM,GAAG,GAAG;EAChC,IAAI,UAAU,IACZ,OAAO,EAAE;EAEX,OAAO,mBAAmB,MAAM;;CAElC,OAAO;;AAGT,SAAS,mBAAmB,OAAyB;CACnD,MAAM,SAAmB,E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;IAAO,UAAU;IAAY,YAAY;IAAS;GAC1F;EACD,qBAAqB,EACnB,QAAQ;GACN,SAAS;GACT,OAAO;GACP,OAAO;GACR,EACF;EACF;CACF"}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
import { CodecExpression, Expression, TraitExpression } from "@prisma-next/sql-relational-core/expression";
|
|
1
2
|
import { SqlQueryOperationTypes } from "@prisma-next/sql-contract/types";
|
|
2
3
|
|
|
3
4
|
//#region src/types/operation-types.d.ts
|
|
4
|
-
type
|
|
5
|
+
type CodecTypesBase = Record<string, {
|
|
6
|
+
readonly input: unknown;
|
|
7
|
+
readonly output: unknown;
|
|
8
|
+
}>;
|
|
9
|
+
type QueryOperationTypes<CT extends CodecTypesBase> = SqlQueryOperationTypes<CT, {
|
|
5
10
|
readonly ilike: {
|
|
6
|
-
readonly
|
|
11
|
+
readonly self: {
|
|
7
12
|
readonly traits: readonly ['textual'];
|
|
8
|
-
readonly nullable: false;
|
|
9
|
-
}, {
|
|
10
|
-
readonly codecId: 'pg/text@1';
|
|
11
|
-
readonly nullable: false;
|
|
12
|
-
}];
|
|
13
|
-
readonly returns: {
|
|
14
|
-
readonly codecId: 'pg/bool@1';
|
|
15
|
-
readonly nullable: false;
|
|
16
13
|
};
|
|
14
|
+
readonly impl: (self: TraitExpression<readonly ['textual'], false, CT>, pattern: CodecExpression<'pg/text@1', false, CT>) => Expression<{
|
|
15
|
+
codecId: 'pg/bool@1';
|
|
16
|
+
nullable: false;
|
|
17
|
+
}>;
|
|
17
18
|
};
|
|
18
19
|
}>;
|
|
19
20
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation-types.d.mts","names":[],"sources":["../src/types/operation-types.ts"],"
|
|
1
|
+
{"version":3,"file":"operation-types.d.mts","names":[],"sources":["../src/types/operation-types.ts"],"mappings":";;;;KAOK,cAAA,GAAiB,MAAA;EAAA,SAA0B,KAAA;EAAA,SAAyB,MAAA;AAAA;AAAA,KAE7D,mBAAA,YAA+B,cAAA,IAAkB,sBAAA,CAC3D,EAAA;EAAA,SAEW,KAAA;IAAA,SACE,IAAA;MAAA,SAAiB,MAAA;IAAA;IAAA,SACjB,IAAA,GACP,IAAA,EAAM,eAAA,8BAA6C,EAAA,GACnD,OAAA,EAAS,eAAA,qBAAoC,EAAA,MAC1C,UAAA;MAAa,OAAA;MAAsB,QAAA;IAAA;EAAA;AAAA"}
|
package/dist/operation-types.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
import { c as PostgresContract, l as PostgresLoweredStatement } from "./types-
|
|
1
|
+
import { c as PostgresContract, l as PostgresLoweredStatement } from "./types-B1eiuBHQ.mjs";
|
|
2
|
+
import { SqlRuntimeAdapterDescriptor } from "@prisma-next/sql-runtime";
|
|
2
3
|
import { Adapter, AnyQueryAst } from "@prisma-next/sql-relational-core/ast";
|
|
3
4
|
import { RuntimeAdapterInstance } from "@prisma-next/framework-components/execution";
|
|
4
|
-
import { SqlRuntimeAdapterDescriptor } from "@prisma-next/sql-runtime";
|
|
5
|
-
import { JsonSchemaValidateFn } from "@prisma-next/sql-relational-core/query-lane-context";
|
|
6
5
|
|
|
7
6
|
//#region src/exports/runtime.d.ts
|
|
8
7
|
interface SqlRuntimeAdapter extends RuntimeAdapterInstance<'sql', 'postgres'>, Adapter<AnyQueryAst, PostgresContract, PostgresLoweredStatement> {}
|
|
9
|
-
/**
|
|
10
|
-
* Helper returned by the JSON/JSONB `init` hook.
|
|
11
|
-
* Contains a compiled JSON Schema validate function for runtime conformance checks.
|
|
12
|
-
*/
|
|
13
|
-
type JsonCodecHelper = {
|
|
14
|
-
readonly validate: JsonSchemaValidateFn;
|
|
15
|
-
};
|
|
16
8
|
declare const postgresRuntimeAdapterDescriptor: SqlRuntimeAdapterDescriptor<'postgres', SqlRuntimeAdapter>;
|
|
17
9
|
//#endregion
|
|
18
|
-
export {
|
|
10
|
+
export { SqlRuntimeAdapter, postgresRuntimeAdapterDescriptor as default };
|
|
19
11
|
//# sourceMappingURL=runtime.d.mts.map
|
package/dist/runtime.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/exports/runtime.ts"],"
|
|
1
|
+
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/exports/runtime.ts"],"mappings":";;;;;;UAaiB,iBAAA,SACP,sBAAA,qBACN,OAAA,CAAQ,WAAA,EAAa,gBAAA,EAAkB,wBAAA;AAAA,cAgBrC,gCAAA,EAAkC,2BAAA,aAAwC,iBAAA"}
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,99 +1,37 @@
|
|
|
1
|
-
import { t as createPostgresAdapter } from "./adapter-
|
|
2
|
-
import { n as postgresQueryOperations, t as postgresAdapterDescriptorMeta } from "./descriptor-meta-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { PG_JSONB_CODEC_ID, PG_JSON_CODEC_ID } from "@prisma-next/target-postgres/codec-ids";
|
|
1
|
+
import { t as createPostgresAdapter } from "./adapter-CBaRvhQF.mjs";
|
|
2
|
+
import { n as postgresQueryOperations, t as postgresAdapterDescriptorMeta } from "./descriptor-meta-CyjnYUWG.mjs";
|
|
3
|
+
import { extractCodecLookup } from "@prisma-next/framework-components/control";
|
|
4
|
+
import { postgresCodecRegistry } from "@prisma-next/target-postgres/codecs";
|
|
6
5
|
import { builtinGeneratorIds } from "@prisma-next/ids";
|
|
6
|
+
import { timestampNowRuntimeGenerator } from "@prisma-next/family-sql/runtime";
|
|
7
7
|
import { generateId } from "@prisma-next/ids/runtime";
|
|
8
|
-
import { type } from "arktype";
|
|
9
|
-
import Ajv from "ajv";
|
|
10
|
-
|
|
11
|
-
//#region src/core/json-schema-validator.ts
|
|
12
|
-
/**
|
|
13
|
-
* Shared Ajv instance for all JSON Schema validators.
|
|
14
|
-
* Reusing a single instance avoids ~50-100KB memory overhead per compiled schema.
|
|
15
|
-
*/
|
|
16
|
-
let sharedAjv;
|
|
17
|
-
function getSharedAjv() {
|
|
18
|
-
if (!sharedAjv) sharedAjv = new Ajv({
|
|
19
|
-
allErrors: false,
|
|
20
|
-
strict: false
|
|
21
|
-
});
|
|
22
|
-
return sharedAjv;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Compiles a JSON Schema object into a reusable validate function using Ajv.
|
|
26
|
-
*
|
|
27
|
-
* The returned function validates a value against the schema and returns
|
|
28
|
-
* a structured result with error details on failure.
|
|
29
|
-
*
|
|
30
|
-
* Uses a shared Ajv instance and fail-fast mode (`allErrors: false`)
|
|
31
|
-
* to minimize memory and CPU overhead.
|
|
32
|
-
*
|
|
33
|
-
* @param schema - A JSON Schema object (draft-07 compatible)
|
|
34
|
-
* @returns A validate function
|
|
35
|
-
*/
|
|
36
|
-
function compileJsonSchemaValidator(schema) {
|
|
37
|
-
const validate = getSharedAjv().compile(schema);
|
|
38
|
-
return (value) => {
|
|
39
|
-
if (validate(value)) return { valid: true };
|
|
40
|
-
return {
|
|
41
|
-
valid: false,
|
|
42
|
-
errors: validate.errors.map((err) => ({
|
|
43
|
-
path: err.instancePath || "/",
|
|
44
|
-
message: err.message ?? "unknown validation error",
|
|
45
|
-
keyword: err.keyword
|
|
46
|
-
}))
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
//#endregion
|
|
52
8
|
//#region src/exports/runtime.ts
|
|
53
|
-
function createPostgresCodecRegistry() {
|
|
54
|
-
const registry = createCodecRegistry();
|
|
55
|
-
for (const definition of Object.values(codecDefinitions)) registry.register(definition.codec);
|
|
56
|
-
return registry;
|
|
57
|
-
}
|
|
58
|
-
const jsonTypeParamsSchema = type({
|
|
59
|
-
schemaJson: "object",
|
|
60
|
-
"type?": "string"
|
|
61
|
-
});
|
|
62
9
|
function createPostgresMutationDefaultGenerators() {
|
|
63
|
-
return builtinGeneratorIds.map((id) => ({
|
|
10
|
+
return [...builtinGeneratorIds.map((id) => ({
|
|
64
11
|
id,
|
|
65
12
|
generate: (params) => {
|
|
66
13
|
return generateId(params ? {
|
|
67
14
|
id,
|
|
68
15
|
params
|
|
69
16
|
} : { id });
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
function initJsonCodecHelper(params) {
|
|
74
|
-
return { validate: compileJsonSchemaValidator(params.schemaJson) };
|
|
17
|
+
},
|
|
18
|
+
stability: "field"
|
|
19
|
+
})), timestampNowRuntimeGenerator()];
|
|
75
20
|
}
|
|
76
|
-
const parameterizedCodecDescriptors = [{
|
|
77
|
-
codecId: PG_JSON_CODEC_ID,
|
|
78
|
-
paramsSchema: jsonTypeParamsSchema,
|
|
79
|
-
init: initJsonCodecHelper
|
|
80
|
-
}, {
|
|
81
|
-
codecId: PG_JSONB_CODEC_ID,
|
|
82
|
-
paramsSchema: jsonTypeParamsSchema,
|
|
83
|
-
init: initJsonCodecHelper
|
|
84
|
-
}];
|
|
85
21
|
const postgresRuntimeAdapterDescriptor = {
|
|
86
22
|
...postgresAdapterDescriptorMeta,
|
|
87
|
-
codecs:
|
|
88
|
-
|
|
89
|
-
queryOperations: () => postgresQueryOperations,
|
|
23
|
+
codecs: () => Array.from(postgresCodecRegistry.values()),
|
|
24
|
+
queryOperations: () => postgresQueryOperations(),
|
|
90
25
|
mutationDefaultGenerators: createPostgresMutationDefaultGenerators,
|
|
91
|
-
create(
|
|
92
|
-
return createPostgresAdapter(
|
|
26
|
+
create(stack) {
|
|
27
|
+
return createPostgresAdapter({ codecLookup: extractCodecLookup([
|
|
28
|
+
stack.target,
|
|
29
|
+
stack.adapter,
|
|
30
|
+
...stack.extensionPacks
|
|
31
|
+
]) });
|
|
93
32
|
}
|
|
94
33
|
};
|
|
95
|
-
var runtime_default = postgresRuntimeAdapterDescriptor;
|
|
96
|
-
|
|
97
34
|
//#endregion
|
|
98
|
-
export {
|
|
35
|
+
export { postgresRuntimeAdapterDescriptor as default };
|
|
36
|
+
|
|
99
37
|
//# sourceMappingURL=runtime.mjs.map
|
package/dist/runtime.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.mjs","names":[
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":[],"sources":["../src/exports/runtime.ts"],"sourcesContent":["import type { GeneratedValueSpec } from '@prisma-next/contract/types';\nimport { timestampNowRuntimeGenerator } from '@prisma-next/family-sql/runtime';\nimport { extractCodecLookup } from '@prisma-next/framework-components/control';\nimport type { RuntimeAdapterInstance } from '@prisma-next/framework-components/execution';\nimport { builtinGeneratorIds } from '@prisma-next/ids';\nimport { generateId } from '@prisma-next/ids/runtime';\nimport type { Adapter, AnyQueryAst } from '@prisma-next/sql-relational-core/ast';\nimport type { SqlRuntimeAdapterDescriptor } from '@prisma-next/sql-runtime';\nimport { postgresCodecRegistry } from '@prisma-next/target-postgres/codecs';\nimport { createPostgresAdapter } from '../core/adapter';\nimport { postgresAdapterDescriptorMeta, postgresQueryOperations } from '../core/descriptor-meta';\nimport type { PostgresContract, PostgresLoweredStatement } from '../core/types';\n\nexport interface SqlRuntimeAdapter\n extends RuntimeAdapterInstance<'sql', 'postgres'>,\n Adapter<AnyQueryAst, PostgresContract, PostgresLoweredStatement> {}\n\nfunction createPostgresMutationDefaultGenerators() {\n return [\n ...builtinGeneratorIds.map((id) => ({\n id,\n generate: (params?: Record<string, unknown>) => {\n const spec: GeneratedValueSpec = params ? { id, params } : { id };\n return generateId(spec);\n },\n stability: 'field' as const,\n })),\n timestampNowRuntimeGenerator(),\n ];\n}\n\nconst postgresRuntimeAdapterDescriptor: SqlRuntimeAdapterDescriptor<'postgres', SqlRuntimeAdapter> =\n {\n ...postgresAdapterDescriptorMeta,\n codecs: () => Array.from(postgresCodecRegistry.values()),\n queryOperations: () => postgresQueryOperations(),\n mutationDefaultGenerators: createPostgresMutationDefaultGenerators,\n create(stack): SqlRuntimeAdapter {\n // The runtime `ExecutionStack` does not (yet) carry a pre-assembled `codecLookup` field the way the control `ControlStack` does, so we derive an equivalent lookup here from the stack's component metadata (target + adapter + extension packs) using the same assembly helper that `createControlStack` uses. This keeps the renderer fed with the same codec set on both planes — including extension-contributed codecs like\n // `pg/vector@1` from `@prisma-next/extension-pgvector`.\n const codecLookup = extractCodecLookup([\n stack.target,\n stack.adapter,\n ...stack.extensionPacks,\n ]);\n return createPostgresAdapter({ codecLookup });\n },\n };\n\nexport default postgresRuntimeAdapterDescriptor;\n"],"mappings":";;;;;;;;AAiBA,SAAS,0CAA0C;CACjD,OAAO,CACL,GAAG,oBAAoB,KAAK,QAAQ;EAClC;EACA,WAAW,WAAqC;GAE9C,OAAO,WAD0B,SAAS;IAAE;IAAI;IAAQ,GAAG,EAAE,IAAI,CAC1C;;EAEzB,WAAW;EACZ,EAAE,EACH,8BAA8B,CAC/B;;AAGH,MAAM,mCACJ;CACE,GAAG;CACH,cAAc,MAAM,KAAK,sBAAsB,QAAQ,CAAC;CACxD,uBAAuB,yBAAyB;CAChD,2BAA2B;CAC3B,OAAO,OAA0B;EAQ/B,OAAO,sBAAsB,EAAE,aALX,mBAAmB;GACrC,MAAM;GACN,MAAM;GACN,GAAG,MAAM;GACV,CACyC,EAAE,CAAC;;CAEhD"}
|
|
@@ -1,57 +1,98 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { extractCodecLookup } from "@prisma-next/framework-components/control";
|
|
2
|
+
import { postgresCodecRegistry } from "@prisma-next/target-postgres/codecs";
|
|
3
|
+
import { LiteralExpr, collectOrderedParamRefs } from "@prisma-next/sql-relational-core/ast";
|
|
3
4
|
import { escapeLiteral, quoteIdentifier } from "@prisma-next/target-postgres/sql-utils";
|
|
4
|
-
|
|
5
|
+
//#region src/core/codec-lookup.ts
|
|
6
|
+
/**
|
|
7
|
+
* Build a {@link CodecLookup} populated with the Postgres-builtin codec definitions only.
|
|
8
|
+
*
|
|
9
|
+
* This is the default lookup used by `createPostgresAdapter()` and `new PostgresControlAdapter()` when called without a stack-derived lookup (e.g. from tests, or one-off scripts that don't compose a full stack).
|
|
10
|
+
*
|
|
11
|
+
* 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 lookup at construction time.
|
|
12
|
+
*/
|
|
13
|
+
function createPostgresBuiltinCodecLookup() {
|
|
14
|
+
return extractCodecLookup([{
|
|
15
|
+
id: "postgres-builtin-codecs",
|
|
16
|
+
types: { codecTypes: { codecDescriptors: Array.from(postgresCodecRegistry.values()) } }
|
|
17
|
+
}]);
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
5
20
|
//#region src/core/sql-renderer.ts
|
|
6
|
-
const VECTOR_CODEC_ID = "pg/vector@1";
|
|
7
21
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
22
|
+
* Postgres native types whose unknown-OID parameter inference is reliable in arbitrary expression positions. Parameters bound to a codec whose `meta.db.sql.postgres.nativeType` falls in this set are emitted as plain `$N`; everything else (including `json`, `jsonb`, extension types like `vector`, and unknown user types) is emitted as `$N::<nativeType>` so the planner picks an unambiguous overload.
|
|
23
|
+
*
|
|
24
|
+
* `json` / `jsonb` are intentionally excluded despite being Postgres builtins: their operator overloads make context inference unreliable in expression positions (e.g. `$1 -> 'key'` is ambiguous between the two).
|
|
10
25
|
*
|
|
11
|
-
*
|
|
12
|
-
* TML-2310 ("Move SQL param-cast metadata onto codec descriptors").
|
|
13
|
-
* Until that lands the cast lives on the renderer rather than the codec.
|
|
26
|
+
* Spellings match the on-disk `meta.db.sql.postgres.nativeType` values in `@prisma-next/target-postgres`'s codec definitions, not the `udt_name` abbreviations that ADR 205 used as illustrative shorthand. The lookup-based cast policy compares against these strings directly.
|
|
14
27
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
28
|
+
const POSTGRES_INFERRABLE_NATIVE_TYPES = new Set([
|
|
29
|
+
"integer",
|
|
30
|
+
"smallint",
|
|
31
|
+
"bigint",
|
|
32
|
+
"real",
|
|
33
|
+
"double precision",
|
|
34
|
+
"numeric",
|
|
35
|
+
"boolean",
|
|
36
|
+
"text",
|
|
37
|
+
"character",
|
|
38
|
+
"character varying",
|
|
39
|
+
"timestamp",
|
|
40
|
+
"timestamp without time zone",
|
|
41
|
+
"timestamp with time zone",
|
|
42
|
+
"time",
|
|
43
|
+
"timetz",
|
|
44
|
+
"interval",
|
|
45
|
+
"bit",
|
|
46
|
+
"bit varying"
|
|
47
|
+
]);
|
|
48
|
+
function renderTypedParam(index, codecId, codecLookup) {
|
|
49
|
+
if (codecId === void 0) return `$${index}`;
|
|
50
|
+
if (codecLookup.get(codecId) === void 0) throw new Error(`Postgres lowering: ParamRef carries codecId "${codecId}" but the assembled codec lookup has no entry for it. This usually indicates a missing extension pack in the runtime stack — register the pack that contributes this codec (e.g. \`extensionPacks: [pgvectorRuntime]\`), or use the codec directly from \`@prisma-next/target-postgres/codecs\` if it's a builtin.`);
|
|
51
|
+
const dbRecord = codecLookup.metaFor(codecId)?.db;
|
|
52
|
+
const sqlBlock = isRecord(dbRecord) ? dbRecord["sql"] : void 0;
|
|
53
|
+
const dialectBlock = isRecord(sqlBlock) ? sqlBlock["postgres"] : void 0;
|
|
54
|
+
const nativeType = isRecord(dialectBlock) ? dialectBlock["nativeType"] : void 0;
|
|
55
|
+
if (typeof nativeType === "string" && !POSTGRES_INFERRABLE_NATIVE_TYPES.has(nativeType)) return `$${index}::${nativeType}`;
|
|
56
|
+
return `$${index}`;
|
|
19
57
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
return cast ? `$${index}::${cast}` : `$${index}`;
|
|
58
|
+
function isRecord(value) {
|
|
59
|
+
return typeof value === "object" && value !== null;
|
|
23
60
|
}
|
|
24
61
|
/**
|
|
25
62
|
* Render a SQL query AST to a Postgres-flavored `{ sql, params }` payload.
|
|
26
63
|
*
|
|
27
|
-
* Shared between the runtime (`PostgresAdapterImpl.lower`) and control
|
|
28
|
-
* (`PostgresControlAdapter.lower`) entrypoints so emit-time and run-time
|
|
29
|
-
* paths produce byte-identical output for the same AST.
|
|
64
|
+
* Shared between the runtime (`PostgresAdapterImpl.lower`) and control (`PostgresControlAdapter.lower`) entrypoints so emit-time and run-time paths produce byte-identical output for the same AST.
|
|
30
65
|
*/
|
|
31
|
-
function renderLoweredSql(ast, contract) {
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const params =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
66
|
+
function renderLoweredSql(ast, contract, codecLookup) {
|
|
67
|
+
const orderedRefs = collectOrderedParamRefs(ast);
|
|
68
|
+
const indexMap = /* @__PURE__ */ new Map();
|
|
69
|
+
const params = orderedRefs.map((ref, i) => {
|
|
70
|
+
indexMap.set(ref, i + 1);
|
|
71
|
+
return ref.value;
|
|
72
|
+
});
|
|
73
|
+
const pim = {
|
|
74
|
+
indexMap,
|
|
75
|
+
codecLookup
|
|
76
|
+
};
|
|
40
77
|
const node = ast;
|
|
41
78
|
let sql;
|
|
42
79
|
switch (node.kind) {
|
|
43
80
|
case "select":
|
|
44
|
-
sql = renderSelect(node, contract,
|
|
81
|
+
sql = renderSelect(node, contract, pim);
|
|
45
82
|
break;
|
|
46
83
|
case "insert":
|
|
47
|
-
sql = renderInsert(node, contract,
|
|
84
|
+
sql = renderInsert(node, contract, pim);
|
|
48
85
|
break;
|
|
49
86
|
case "update":
|
|
50
|
-
sql = renderUpdate(node, contract,
|
|
87
|
+
sql = renderUpdate(node, contract, pim);
|
|
51
88
|
break;
|
|
52
89
|
case "delete":
|
|
53
|
-
sql = renderDelete(node, contract,
|
|
90
|
+
sql = renderDelete(node, contract, pim);
|
|
54
91
|
break;
|
|
92
|
+
case "raw-sql":
|
|
93
|
+
sql = renderRawSql(node, contract, pim);
|
|
94
|
+
break;
|
|
95
|
+
// v8 ignore next 4
|
|
55
96
|
default: throw new Error(`Unsupported AST node kind: ${node.kind}`);
|
|
56
97
|
}
|
|
57
98
|
return Object.freeze({
|
|
@@ -81,6 +122,16 @@ function renderProjection(projection, contract, pim) {
|
|
|
81
122
|
return `${renderExpr(item.expr, contract, pim)} AS ${alias}`;
|
|
82
123
|
}).join(", ");
|
|
83
124
|
}
|
|
125
|
+
function renderReturning(items, contract, pim) {
|
|
126
|
+
return items.map((item) => {
|
|
127
|
+
if (item.expr.kind === "column-ref") {
|
|
128
|
+
const rendered = renderColumn(item.expr);
|
|
129
|
+
return item.expr.column === item.alias ? rendered : `${rendered} AS ${quoteIdentifier(item.alias)}`;
|
|
130
|
+
}
|
|
131
|
+
if (item.expr.kind === "literal") return `${renderLiteral(item.expr)} AS ${quoteIdentifier(item.alias)}`;
|
|
132
|
+
return `${renderExpr(item.expr, contract, pim)} AS ${quoteIdentifier(item.alias)}`;
|
|
133
|
+
}).join(", ");
|
|
134
|
+
}
|
|
84
135
|
function renderDistinctPrefix(distinct, distinctOn, contract, pim) {
|
|
85
136
|
if (distinctOn && distinctOn.length > 0) return `DISTINCT ON (${distinctOn.map((expr) => renderExpr(expr, contract, pim)).join(", ")}) `;
|
|
86
137
|
if (distinct) return "DISTINCT ";
|
|
@@ -95,6 +146,7 @@ function renderSource(source, contract, pim) {
|
|
|
95
146
|
return `${table} AS ${quoteIdentifier(node.alias)}`;
|
|
96
147
|
}
|
|
97
148
|
case "derived-table-source": return `(${renderSelect(node.query, contract, pim)}) AS ${quoteIdentifier(node.alias)}`;
|
|
149
|
+
// v8 ignore next 4
|
|
98
150
|
default: throw new Error(`Unsupported source node kind: ${node.kind}`);
|
|
99
151
|
}
|
|
100
152
|
}
|
|
@@ -114,15 +166,9 @@ function renderNullCheck(expr, contract, pim) {
|
|
|
114
166
|
return expr.isNull ? `${renderedExpr} IS NULL` : `${renderedExpr} IS NOT NULL`;
|
|
115
167
|
}
|
|
116
168
|
/**
|
|
117
|
-
* Atomic expression kinds whose rendered SQL is already self-delimited
|
|
118
|
-
* (a column reference, parameter, literal, function call, aggregate, etc.)
|
|
119
|
-
* and therefore does not need surrounding parentheses when used as the
|
|
120
|
-
* left operand of a postfix predicate like `IS NULL` or `IS NOT NULL`,
|
|
121
|
-
* or as either operand of a binary infix operator.
|
|
169
|
+
* Atomic expression kinds whose rendered SQL is already self-delimited (a column reference, parameter, literal, function call, aggregate, etc.) and therefore does not need surrounding parentheses when used as the left operand of a postfix predicate like `IS NULL` or `IS NOT NULL`, or as either operand of a binary infix operator.
|
|
122
170
|
*
|
|
123
|
-
* Anything not in this set is treated as composite (binary, AND/OR/NOT,
|
|
124
|
-
* EXISTS, nested IS NULL, subqueries, operation templates) and gets
|
|
125
|
-
* wrapped to preserve grouping.
|
|
171
|
+
* Anything not in this set is treated as composite (binary, AND/OR/NOT, EXISTS, nested IS NULL, subqueries, operation templates) and gets wrapped to preserve grouping.
|
|
126
172
|
*/
|
|
127
173
|
function isAtomicExpressionKind(kind) {
|
|
128
174
|
switch (kind) {
|
|
@@ -239,13 +285,14 @@ function renderExpr(expr, contract, pim) {
|
|
|
239
285
|
case "param-ref": return renderParamRef(node, pim);
|
|
240
286
|
case "literal": return renderLiteral(node);
|
|
241
287
|
case "list": return renderListLiteral(node, contract, pim);
|
|
288
|
+
// v8 ignore next 4
|
|
242
289
|
default: throw new Error(`Unsupported expression node kind: ${node.kind}`);
|
|
243
290
|
}
|
|
244
291
|
}
|
|
245
292
|
function renderParamRef(ref, pim) {
|
|
246
|
-
const index = pim.get(ref);
|
|
293
|
+
const index = pim.indexMap.get(ref);
|
|
247
294
|
if (index === void 0) throw new Error("ParamRef not found in index map");
|
|
248
|
-
return renderTypedParam(index, ref.codecId);
|
|
295
|
+
return renderTypedParam(index, ref.codecId, pim.codecLookup);
|
|
249
296
|
}
|
|
250
297
|
function renderLiteral(expr) {
|
|
251
298
|
if (typeof expr.value === "string") return `'${escapeLiteral(expr.value)}'`;
|
|
@@ -296,6 +343,7 @@ function renderInsertValue(value, pim) {
|
|
|
296
343
|
switch (value.kind) {
|
|
297
344
|
case "param-ref": return renderParamRef(value, pim);
|
|
298
345
|
case "column-ref": return renderColumn(value);
|
|
346
|
+
// v8 ignore next 4
|
|
299
347
|
default: throw new Error(`Unsupported value node in INSERT: ${value.kind}`);
|
|
300
348
|
}
|
|
301
349
|
}
|
|
@@ -335,9 +383,10 @@ function renderInsert(ast, contract, pim) {
|
|
|
335
383
|
});
|
|
336
384
|
return ` ON CONFLICT (${conflictColumns.join(", ")}) DO UPDATE SET ${updates.join(", ")}`;
|
|
337
385
|
}
|
|
386
|
+
// v8 ignore next 4
|
|
338
387
|
default: throw new Error(`Unsupported onConflict action: ${action.kind}`);
|
|
339
388
|
}
|
|
340
|
-
})() : ""}${ast.returning?.length ? ` RETURNING ${ast.returning
|
|
389
|
+
})() : ""}${ast.returning?.length ? ` RETURNING ${renderReturning(ast.returning, contract, pim)}` : ""}`;
|
|
341
390
|
}
|
|
342
391
|
function renderUpdate(ast, contract, pim) {
|
|
343
392
|
const table = quoteIdentifier(ast.table.name);
|
|
@@ -353,18 +402,30 @@ function renderUpdate(ast, contract, pim) {
|
|
|
353
402
|
case "column-ref":
|
|
354
403
|
value = renderColumn(val);
|
|
355
404
|
break;
|
|
405
|
+
// v8 ignore next 4
|
|
356
406
|
default: throw new Error(`Unsupported value node in UPDATE: ${val.kind}`);
|
|
357
407
|
}
|
|
358
408
|
return `${column} = ${value}`;
|
|
359
409
|
});
|
|
360
410
|
const whereClause = ast.where ? ` WHERE ${renderWhere(ast.where, contract, pim)}` : "";
|
|
361
|
-
const returningClause = ast.returning?.length ? ` RETURNING ${ast.returning
|
|
411
|
+
const returningClause = ast.returning?.length ? ` RETURNING ${renderReturning(ast.returning, contract, pim)}` : "";
|
|
362
412
|
return `UPDATE ${table} SET ${setClauses.join(", ")}${whereClause}${returningClause}`;
|
|
363
413
|
}
|
|
364
414
|
function renderDelete(ast, contract, pim) {
|
|
365
|
-
return `DELETE FROM ${quoteIdentifier(ast.table.name)}${ast.where ? ` WHERE ${renderWhere(ast.where, contract, pim)}` : ""}${ast.returning?.length ? ` RETURNING ${ast.returning
|
|
415
|
+
return `DELETE FROM ${quoteIdentifier(ast.table.name)}${ast.where ? ` WHERE ${renderWhere(ast.where, contract, pim)}` : ""}${ast.returning?.length ? ` RETURNING ${renderReturning(ast.returning, contract, pim)}` : ""}`;
|
|
416
|
+
}
|
|
417
|
+
function renderRawSql(ast, contract, pim) {
|
|
418
|
+
const out = [];
|
|
419
|
+
for (let i = 0; i < ast.fragments.length; i++) {
|
|
420
|
+
out.push(ast.fragments[i] ?? "");
|
|
421
|
+
if (i < ast.args.length) {
|
|
422
|
+
const arg = ast.args[i];
|
|
423
|
+
if (arg !== void 0) out.push(renderExpr(arg, contract, pim));
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return out.join("");
|
|
366
427
|
}
|
|
367
|
-
|
|
368
428
|
//#endregion
|
|
369
|
-
export { renderLoweredSql as t };
|
|
370
|
-
|
|
429
|
+
export { createPostgresBuiltinCodecLookup as n, renderLoweredSql as t };
|
|
430
|
+
|
|
431
|
+
//# sourceMappingURL=sql-renderer-wTVSEy5H.mjs.map
|