effect-qb 4.0.0-beta.66 → 4.0.0-beta.98

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.
Files changed (129) hide show
  1. package/README.md +5 -2
  2. package/dist/index.js +9376 -0
  3. package/dist/mysql.js +3921 -2573
  4. package/dist/postgres/metadata.js +2491 -1373
  5. package/dist/postgres.js +5453 -5155
  6. package/dist/sqlite.js +6895 -5529
  7. package/dist/standard.js +9330 -0
  8. package/package.json +9 -2
  9. package/src/casing.ts +71 -0
  10. package/src/index.ts +2 -0
  11. package/src/internal/casing.ts +89 -0
  12. package/src/internal/coercion/rules.ts +13 -1
  13. package/src/internal/column-state.ts +21 -15
  14. package/src/internal/column.ts +44 -7
  15. package/src/internal/datatypes/define.ts +7 -1
  16. package/src/internal/datatypes/enrich.ts +23 -0
  17. package/src/internal/datatypes/lookup.ts +81 -25
  18. package/src/internal/datatypes/matrix.ts +903 -0
  19. package/src/internal/datatypes/shape.ts +2 -0
  20. package/src/internal/derived-table.ts +4 -36
  21. package/src/{mysql/internal/sql-expression-renderer.ts → internal/dialect-renderers/mysql.ts} +552 -361
  22. package/src/{postgres/internal/sql-expression-renderer.ts → internal/dialect-renderers/postgres.ts} +657 -400
  23. package/src/{sqlite/internal/sql-expression-renderer.ts → internal/dialect-renderers/sqlite.ts} +505 -347
  24. package/src/internal/dialect.ts +35 -0
  25. package/src/internal/dsl-mutation-runtime.ts +12 -162
  26. package/src/internal/dsl-plan-runtime.ts +10 -138
  27. package/src/internal/dsl-query-runtime.ts +5 -79
  28. package/src/internal/dsl-transaction-ddl-runtime.ts +41 -65
  29. package/src/internal/executor.ts +14 -16
  30. package/src/internal/grouping-key.ts +87 -20
  31. package/src/internal/implication-runtime.ts +1 -1
  32. package/src/internal/json/path-access.ts +351 -0
  33. package/src/internal/predicate/runtime.ts +3 -0
  34. package/src/internal/query.d.ts +38 -11
  35. package/src/internal/query.ts +64 -25
  36. package/src/internal/renderer.ts +26 -14
  37. package/src/internal/runtime/normalize.ts +12 -5
  38. package/src/internal/scalar.ts +7 -1
  39. package/src/internal/schema-derivation.d.ts +7 -7
  40. package/src/internal/schema-derivation.ts +9 -9
  41. package/src/internal/schema-expression.ts +2 -2
  42. package/src/internal/sql-expression-renderer.ts +19 -0
  43. package/src/internal/standard-dsl.ts +6978 -0
  44. package/src/internal/table-options.ts +126 -66
  45. package/src/internal/table.ts +652 -219
  46. package/src/mysql/column-extension.ts +3 -0
  47. package/src/mysql/column.ts +8 -9
  48. package/src/mysql/datatypes/index.ts +4 -2
  49. package/src/mysql/datatypes/spec.ts +6 -176
  50. package/src/mysql/errors/normalize.ts +0 -1
  51. package/src/mysql/executor.ts +7 -7
  52. package/src/mysql/internal/dialect.ts +9 -4
  53. package/src/mysql/internal/dsl.ts +312 -154
  54. package/src/mysql/internal/renderer.ts +6 -2
  55. package/src/mysql/json.ts +7 -2
  56. package/src/mysql/query-extension.ts +16 -0
  57. package/src/mysql/renderer.ts +37 -3
  58. package/src/mysql/type.ts +60 -0
  59. package/src/mysql.ts +7 -13
  60. package/src/postgres/check.ts +1 -0
  61. package/src/postgres/column-extension.ts +28 -0
  62. package/src/postgres/column.ts +2 -8
  63. package/src/postgres/datatypes/index.d.ts +2 -1
  64. package/src/postgres/datatypes/index.ts +4 -2
  65. package/src/postgres/datatypes/spec.ts +6 -260
  66. package/src/postgres/errors/normalize.ts +0 -1
  67. package/src/postgres/executor.ts +7 -7
  68. package/src/postgres/foreign-key.ts +24 -0
  69. package/src/postgres/function/core.ts +1 -3
  70. package/src/postgres/function/index.ts +1 -17
  71. package/src/postgres/index.ts +1 -0
  72. package/src/postgres/internal/dialect.ts +9 -4
  73. package/src/postgres/internal/dsl.ts +306 -163
  74. package/src/postgres/internal/renderer.ts +6 -2
  75. package/src/postgres/internal/schema-ddl.ts +22 -10
  76. package/src/postgres/internal/schema-model.ts +238 -7
  77. package/src/postgres/json-extension.ts +7 -0
  78. package/src/postgres/json.ts +762 -173
  79. package/src/postgres/jsonb.ts +37 -0
  80. package/src/postgres/primary-key.ts +24 -0
  81. package/src/postgres/query-extension.ts +2 -0
  82. package/src/postgres/renderer.ts +37 -3
  83. package/src/postgres/schema-management.ts +12 -11
  84. package/src/postgres/schema.ts +106 -15
  85. package/src/postgres/table.ts +205 -530
  86. package/src/postgres/type.ts +93 -10
  87. package/src/postgres/unique.ts +32 -0
  88. package/src/postgres.ts +20 -16
  89. package/src/sqlite/column-extension.ts +3 -0
  90. package/src/sqlite/column.ts +8 -9
  91. package/src/sqlite/datatypes/index.ts +4 -2
  92. package/src/sqlite/datatypes/spec.ts +6 -94
  93. package/src/sqlite/errors/normalize.ts +0 -1
  94. package/src/sqlite/executor.ts +7 -7
  95. package/src/sqlite/internal/dialect.ts +9 -4
  96. package/src/sqlite/internal/dsl.ts +301 -154
  97. package/src/sqlite/internal/renderer.ts +6 -2
  98. package/src/sqlite/json.ts +8 -2
  99. package/src/sqlite/query-extension.ts +2 -0
  100. package/src/sqlite/renderer.ts +37 -3
  101. package/src/sqlite/type.ts +40 -0
  102. package/src/sqlite.ts +7 -13
  103. package/src/standard/cast.ts +113 -0
  104. package/src/standard/check.ts +17 -0
  105. package/src/standard/column.ts +163 -0
  106. package/src/standard/datatypes/index.ts +83 -0
  107. package/src/standard/datatypes/spec.ts +12 -0
  108. package/src/standard/dialect.ts +40 -0
  109. package/src/standard/foreign-key.ts +37 -0
  110. package/src/standard/function/aggregate.ts +2 -0
  111. package/src/standard/function/core.ts +2 -0
  112. package/src/standard/function/index.ts +18 -0
  113. package/src/standard/function/string.ts +2 -0
  114. package/src/standard/function/temporal.ts +78 -0
  115. package/src/standard/function/window.ts +2 -0
  116. package/src/standard/index.ts +17 -0
  117. package/src/standard/internal/renderer.ts +45 -0
  118. package/src/standard/json.ts +883 -0
  119. package/src/standard/primary-key.ts +17 -0
  120. package/src/standard/query.ts +152 -0
  121. package/src/standard/renderer.ts +49 -0
  122. package/src/standard/table.ts +151 -0
  123. package/src/standard/unique.ts +17 -0
  124. package/src/standard.ts +32 -0
  125. package/src/internal/aggregation-validation.ts +0 -57
  126. package/src/internal/table.d.ts +0 -180
  127. package/src/mysql/table.ts +0 -186
  128. package/src/postgres/cast.ts +0 -45
  129. package/src/sqlite/table.ts +0 -175
@@ -1,9 +1,10 @@
1
1
  import * as Query from "../../internal/query.js"
2
2
  import type * as Expression from "../../internal/scalar.js"
3
+ import type * as Casing from "../../internal/casing.js"
3
4
  import { type RenderState } from "../../internal/dialect.js"
4
5
  import { mysqlDialect } from "./dialect.js"
5
6
  import { type Projection } from "../../internal/projections.js"
6
- import { renderQueryAst } from "./sql-expression-renderer.js"
7
+ import { renderQueryAst } from "../../internal/sql-expression-renderer.js"
7
8
 
8
9
  /**
9
10
  * Internal rendered-query payload produced by the built-in MySQL renderer.
@@ -17,6 +18,7 @@ export interface MysqlRenderResult {
17
18
 
18
19
  export interface MysqlRenderOptions {
19
20
  readonly valueMappings?: Expression.DriverValueMappings
21
+ readonly casing?: Casing.Options
20
22
  }
21
23
 
22
24
  /**
@@ -29,9 +31,11 @@ export const renderMysqlPlan = <PlanValue extends Query.Plan.Any>(
29
31
  const state: RenderState = {
30
32
  params: [],
31
33
  valueMappings: options.valueMappings,
34
+ casing: options.casing,
32
35
  ctes: [],
33
36
  cteNames: new Set<string>(),
34
- cteSources: new Map<string, unknown>()
37
+ cteSources: new Map<string, unknown>(),
38
+ sourceNames: new Map()
35
39
  }
36
40
  const rendered = renderQueryAst(
37
41
  Query.getAst(plan as Query.Plan.Any) as any,
package/src/mysql/json.ts CHANGED
@@ -1,2 +1,7 @@
1
- /** MySQL JSON expression helpers. */
2
- export { json } from "./internal/dsl.js"
1
+ /** MySQL-specific JSON expression helpers. Portable JSON helpers are exported from `effect-qb`. */
2
+ import { json } from "./internal/dsl.js"
3
+
4
+ export const typeOf = json.typeOf
5
+ export const length = json.length
6
+ export const stripNulls = json.stripNulls
7
+ export const pathMatch = json.pathMatch
@@ -0,0 +1,16 @@
1
+ import { lock } from "./query.js"
2
+
3
+ /** MySQL-only mutation modifier for UPDATE IGNORE. */
4
+ export const ignore = lock("ignore")
5
+
6
+ /** MySQL-only mutation modifier for DELETE QUICK. */
7
+ export const quick = lock("quick")
8
+
9
+ /** MySQL-only mutation modifier for LOW_PRIORITY mutations. */
10
+ export const lowPriority = lock("lowPriority")
11
+
12
+ /** MySQL-only mutation ordering and limiting. */
13
+ export { orderBy, limit } from "./query.js"
14
+
15
+ /** MySQL-only multi-target mutation forms. */
16
+ export { update, delete } from "./query.js"
@@ -1,5 +1,9 @@
1
+ import { pipeArguments, type Pipeable } from "effect/Pipeable"
2
+
1
3
  import * as CoreRenderer from "../internal/renderer.js"
4
+ import * as Casing from "../internal/casing.js"
2
5
  import type * as Expression from "../internal/scalar.js"
6
+ import type { MysqlDatatypeFamily, MysqlDatatypeKind } from "./datatypes/spec.js"
3
7
  import { renderMysqlPlan } from "./internal/renderer.js"
4
8
 
5
9
  /** MySQL-specialized rendered query shape. */
@@ -7,18 +11,48 @@ export type RenderedQuery<Row> = CoreRenderer.RenderedQuery<Row, "mysql">
7
11
  /** Extracts the row type carried by a MySQL rendered query. */
8
12
  export type RowOf<Value extends RenderedQuery<any>> = CoreRenderer.RowOf<Value>
9
13
  /** MySQL-specialized renderer contract. */
10
- export type Renderer = CoreRenderer.Renderer<"mysql">
14
+ export type Renderer = CoreRenderer.Renderer<"mysql"> & Pipeable & {
15
+ readonly [Casing.TypeId]: Casing.State
16
+ readonly withCasing: (options: Casing.Options) => Renderer
17
+ }
18
+
19
+ export type ValueMappings = Expression.DriverValueMappingsFor<MysqlDatatypeKind | "uuid", MysqlDatatypeFamily | "uuid">
11
20
 
12
21
  export interface MakeOptions {
13
- readonly valueMappings?: Expression.DriverValueMappings
22
+ readonly valueMappings?: ValueMappings
23
+ }
24
+
25
+ interface RendererState extends MakeOptions {
26
+ readonly casing?: Casing.Options
14
27
  }
15
28
 
16
29
  export { TypeId } from "../internal/renderer.js"
17
30
  export type { Projection } from "../internal/renderer.js"
18
31
 
32
+ const RendererProto = {
33
+ pipe(this: Pipeable) {
34
+ return pipeArguments(this, arguments)
35
+ }
36
+ }
37
+
38
+ /** Creates the built-in MySQL renderer. */
39
+ const makeWithState = (state: RendererState = {}): Renderer => {
40
+ const renderer = CoreRenderer.makeTrusted("mysql", (plan) => renderMysqlPlan(plan, state))
41
+ return Object.assign(Object.create(RendererProto), renderer, {
42
+ [Casing.TypeId]: {
43
+ casing: state.casing
44
+ },
45
+ withCasing: (override: Casing.Options) =>
46
+ makeWithState({
47
+ ...state,
48
+ casing: Casing.merge(state.casing, override)
49
+ })
50
+ }) as Renderer
51
+ }
52
+
19
53
  /** Creates the built-in MySQL renderer. */
20
54
  export const make = (options: MakeOptions = {}): Renderer =>
21
- CoreRenderer.make("mysql", (plan) => renderMysqlPlan(plan, options))
55
+ makeWithState({ valueMappings: options.valueMappings })
22
56
 
23
57
  /** Shared built-in MySQL renderer instance. */
24
58
  export const mysql = make()
@@ -0,0 +1,60 @@
1
+ import type * as Expression from "../internal/scalar.js"
2
+ import type { NonEmptyStringInput } from "../internal/table-options.js"
3
+ import {
4
+ mysqlSpecificDatatypeKeys,
5
+ pickDatatypeConstructors,
6
+ type MysqlSpecificDatatypeKey
7
+ } from "../internal/datatypes/matrix.js"
8
+ import { mysqlDatatypes } from "./datatypes/index.js"
9
+
10
+ type MysqlSpecificDatatypes = Pick<typeof mysqlDatatypes, MysqlSpecificDatatypeKey>
11
+
12
+ type MysqlTypeNamespace = MysqlSpecificDatatypes & {
13
+ readonly enum: <Kind extends string>(kind: NonEmptyStringInput<Kind>) => Expression.DbType.Enum<"mysql", Kind>
14
+ readonly set: <Kind extends string>(kind: NonEmptyStringInput<Kind>) => Expression.DbType.Set<"mysql", Kind>
15
+ readonly custom: <Kind extends string>(kind: NonEmptyStringInput<Kind>) => Expression.DbType.Base<"mysql", Kind>
16
+ readonly driverValueMapping: <Db extends Expression.DbType.Any>(
17
+ dbType: Db,
18
+ mapping: Expression.DriverValueMapping
19
+ ) => Db
20
+ }
21
+
22
+ const enum_ = <Kind extends string>(
23
+ kind: NonEmptyStringInput<Kind>
24
+ ): Expression.DbType.Enum<"mysql", Kind> => ({
25
+ dialect: "mysql",
26
+ kind: kind as Kind,
27
+ variant: "enum"
28
+ })
29
+
30
+ const set = <Kind extends string>(
31
+ kind: NonEmptyStringInput<Kind>
32
+ ): Expression.DbType.Set<"mysql", Kind> => ({
33
+ dialect: "mysql",
34
+ kind: kind as Kind,
35
+ variant: "set"
36
+ })
37
+
38
+ const custom = <Kind extends string>(
39
+ kind: NonEmptyStringInput<Kind>
40
+ ): Expression.DbType.Base<"mysql", Kind> => ({
41
+ dialect: "mysql",
42
+ kind: kind as Kind
43
+ })
44
+
45
+ const driverValueMapping = <Db extends Expression.DbType.Any>(
46
+ dbType: Db,
47
+ mapping: Expression.DriverValueMapping
48
+ ): Db => ({
49
+ ...dbType,
50
+ driverValueMapping: mapping
51
+ })
52
+
53
+ /** MySQL-only database-type constructors for casts and typed column references. */
54
+ export const type: MysqlTypeNamespace = {
55
+ ...pickDatatypeConstructors(mysqlDatatypes, mysqlSpecificDatatypeKeys),
56
+ enum: enum_,
57
+ set,
58
+ custom,
59
+ driverValueMapping
60
+ }
package/src/mysql.ts CHANGED
@@ -1,22 +1,16 @@
1
- /** MySQL-specialized column-definition DSL. */
2
- export * as Column from "./mysql/column.js"
1
+ /** MySQL-specific column extensions. Portable columns are exported from `effect-qb`. */
2
+ export * as Column from "./mysql/column-extension.js"
3
3
  /** MySQL datatype witnesses and coercion families. */
4
4
  export * as Datatypes from "./mysql/datatypes/index.js"
5
5
  /** MySQL error catalog and error normalization helpers. */
6
6
  export * as Errors from "./mysql/errors/index.js"
7
- /** Shared scalar SQL interfaces and DB-type descriptors. */
8
- export * as Scalar from "./internal/scalar.js"
9
- /** MySQL-specialized SQL function expressions. */
10
- export * as Function from "./mysql/function/index.js"
11
- /** MySQL-specialized JSON expression helpers. */
7
+ /** MySQL-specific JSON expression helpers. Portable JSON helpers are exported from the root package. */
12
8
  export * as Json from "./mysql/json.js"
13
9
  /** MySQL-specialized typed query execution contracts. */
14
10
  export * as Executor from "./mysql/executor.js"
15
- /** Shared logical row-set interfaces. */
16
- export * as RowSet from "./internal/row-set.js"
17
- /** MySQL-specialized query-construction DSL. */
18
- export * as Query from "./mysql/query.js"
19
- /** MySQL-specialized table-definition DSL. */
20
- export * as Table from "./mysql/table.js"
11
+ /** MySQL-specific query helpers. Portable queries are exported from the root package. */
12
+ export * as Query from "./mysql/query-extension.js"
13
+ /** MySQL-only database-type constructors for casts and typed references. */
14
+ export { type as Type } from "./mysql/type.js"
21
15
  /** MySQL-specialized built-in renderer entrypoint. */
22
16
  export * as Renderer from "./mysql/renderer.js"
@@ -0,0 +1 @@
1
+ export { noInherit } from "./table.js"
@@ -0,0 +1,28 @@
1
+ export {
2
+ array,
3
+ bit,
4
+ bytea,
5
+ custom,
6
+ ddlType,
7
+ float4,
8
+ float8,
9
+ foreignKey,
10
+ identityAlways,
11
+ identityByDefault,
12
+ index,
13
+ int2,
14
+ int8,
15
+ interval,
16
+ jsonb,
17
+ name,
18
+ oid,
19
+ pg_lsn,
20
+ regclass,
21
+ timetz,
22
+ timestamptz,
23
+ unique,
24
+ varbit,
25
+ xml
26
+ } from "./column.js"
27
+
28
+ export type { Any, AnyBound } from "./column.js"
@@ -3,6 +3,7 @@ import * as Schema from "effect/Schema"
3
3
  import * as BaseColumn from "../internal/column.js"
4
4
  import { makeColumnDefinition, type ColumnDefinition } from "../internal/column-state.js"
5
5
  import type * as Expression from "../internal/scalar.js"
6
+ import { enrichDbType } from "../internal/datatypes/enrich.js"
6
7
  import {
7
8
  BigIntStringSchema,
8
9
  DecimalStringSchema,
@@ -21,13 +22,6 @@ import {
21
22
  } from "../internal/runtime/value.js"
22
23
  import { postgresDatatypes } from "./datatypes/index.js"
23
24
 
24
- const enrichDbType = <Db extends Expression.DbType.Any>(dbType: Db): Db => {
25
- const candidate = (postgresDatatypes as unknown as Record<string, (() => Expression.DbType.Any) | undefined>)[dbType.kind]
26
- return typeof candidate === "function"
27
- ? { ...candidate(), ...dbType } as Db
28
- : dbType
29
- }
30
-
31
25
  const primitive = <Type, Db extends Expression.DbType.Any>(
32
26
  schema: Schema.Schema<Type>,
33
27
  dbType: Db
@@ -66,7 +60,7 @@ export const custom = <SchemaType extends Schema.Top, Db extends Expression.DbTy
66
60
  dbType: Db
67
61
  ) =>
68
62
  makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>>, {
69
- dbType: enrichDbType(dbType),
63
+ dbType: enrichDbType(postgresDatatypes, dbType),
70
64
  nullable: false,
71
65
  hasDefault: false,
72
66
  generated: false,
@@ -1,7 +1,8 @@
1
1
  import type * as Expression from "../../internal/scalar.js";
2
+ import type { NonEmptyStringInput } from "../../internal/table-options.js";
2
3
  import { postgresDatatypeFamilies, postgresDatatypeKinds } from "./spec.js";
3
4
  export declare const postgresDatatypes: {
4
- custom: <Kind extends string>(kind: Kind) => Expression.DbType.Base<"postgres", Kind>;
5
+ custom: <Kind extends string>(kind: NonEmptyStringInput<Kind>) => Expression.DbType.Base<"postgres", Kind>;
5
6
  text: () => Expression.DbType.Base<"postgres", "text"> & {
6
7
  readonly family: "text";
7
8
  readonly runtime: "string";
@@ -1,5 +1,6 @@
1
1
  import type { DatatypeModule } from "../../internal/datatypes/define.js"
2
2
  import type * as Expression from "../../internal/scalar.js"
3
+ import type { NonEmptyStringInput } from "../../internal/table-options.js"
3
4
  import { postgresDatatypeFamilies, postgresDatatypeKinds } from "./spec.js"
4
5
 
5
6
  const withMetadata = <Kind extends keyof typeof postgresDatatypeKinds & string>(
@@ -14,14 +15,15 @@ const withMetadata = <Kind extends keyof typeof postgresDatatypeKinds & string>(
14
15
  runtime: kindSpec.runtime,
15
16
  compareGroup: familySpec?.compareGroup,
16
17
  castTargets: familySpec?.castTargets,
18
+ implicitTargets: (familySpec as { readonly implicitTargets?: readonly string[] }).implicitTargets,
17
19
  traits: familySpec?.traits
18
20
  }
19
21
  }
20
22
 
21
23
  const postgresDatatypeModule = {
22
- custom: (kind: string) => ({
24
+ custom: <Kind extends string>(kind: NonEmptyStringInput<Kind>) => ({
23
25
  dialect: "postgres",
24
- kind
26
+ kind: kind as Kind
25
27
  }),
26
28
  boolean: () => withMetadata("bool")
27
29
  } as Record<string, (...args: readonly any[]) => Expression.DbType.Base<"postgres", string>>
@@ -1,264 +1,10 @@
1
- import type { DatatypeFamilySpec, DatatypeKindSpec } from "../../internal/datatypes/shape.js"
1
+ import {
2
+ postgresDatatypeFamilies as matrixPostgresDatatypeFamilies,
3
+ postgresDatatypeKinds as matrixPostgresDatatypeKinds
4
+ } from "../../internal/datatypes/matrix.js"
2
5
 
3
- export const postgresDatatypeFamilies = {
4
- text: {
5
- compareGroup: "text",
6
- castTargets: [
7
- "text",
8
- "numeric",
9
- "boolean",
10
- "date",
11
- "time",
12
- "timestamp",
13
- "interval",
14
- "binary",
15
- "uuid",
16
- "json",
17
- "xml",
18
- "bit",
19
- "oid",
20
- "identifier",
21
- "network",
22
- "spatial",
23
- "textsearch",
24
- "range",
25
- "multirange",
26
- "array",
27
- "money",
28
- "null"
29
- ],
30
- traits: {
31
- textual: true,
32
- ordered: true
33
- }
34
- },
35
- numeric: {
36
- compareGroup: "numeric",
37
- castTargets: ["numeric", "text", "boolean", "date", "time", "timestamp", "interval", "uuid", "bit", "oid", "money"],
38
- traits: {
39
- ordered: true
40
- }
41
- },
42
- boolean: {
43
- compareGroup: "boolean",
44
- castTargets: ["boolean", "text", "numeric"],
45
- traits: {}
46
- },
47
- date: {
48
- compareGroup: "date",
49
- castTargets: ["date", "timestamp", "text"],
50
- traits: {
51
- ordered: true
52
- }
53
- },
54
- time: {
55
- compareGroup: "time",
56
- castTargets: ["time", "timestamp", "text"],
57
- traits: {
58
- ordered: true
59
- }
60
- },
61
- timestamp: {
62
- compareGroup: "timestamp",
63
- castTargets: ["timestamp", "date", "text"],
64
- traits: {
65
- ordered: true
66
- }
67
- },
68
- interval: {
69
- compareGroup: "interval",
70
- castTargets: ["interval", "text"],
71
- traits: {
72
- ordered: true
73
- }
74
- },
75
- binary: {
76
- compareGroup: "binary",
77
- castTargets: ["binary", "text"],
78
- traits: {}
79
- },
80
- uuid: {
81
- compareGroup: "uuid",
82
- castTargets: ["uuid", "text"],
83
- traits: {
84
- ordered: true
85
- }
86
- },
87
- json: {
88
- compareGroup: "json",
89
- castTargets: ["json", "text"],
90
- traits: {}
91
- },
92
- xml: {
93
- compareGroup: "xml",
94
- castTargets: ["xml", "text"],
95
- traits: {}
96
- },
97
- bit: {
98
- compareGroup: "bit",
99
- castTargets: ["bit", "text", "numeric"],
100
- traits: {}
101
- },
102
- oid: {
103
- compareGroup: "oid",
104
- castTargets: ["oid", "text", "numeric"],
105
- traits: {
106
- ordered: true
107
- }
108
- },
109
- identifier: {
110
- compareGroup: "identifier",
111
- castTargets: ["identifier", "text"],
112
- traits: {}
113
- },
114
- network: {
115
- compareGroup: "network",
116
- castTargets: ["network", "text"],
117
- traits: {}
118
- },
119
- spatial: {
120
- compareGroup: "spatial",
121
- castTargets: ["spatial", "text"],
122
- traits: {}
123
- },
124
- textsearch: {
125
- compareGroup: "textsearch",
126
- castTargets: ["textsearch", "text"],
127
- traits: {}
128
- },
129
- range: {
130
- compareGroup: "range",
131
- castTargets: ["range", "text"],
132
- traits: {}
133
- },
134
- multirange: {
135
- compareGroup: "multirange",
136
- castTargets: ["multirange", "text"],
137
- traits: {}
138
- },
139
- enum: {
140
- compareGroup: "enum",
141
- castTargets: ["enum", "text"],
142
- traits: {
143
- textual: true,
144
- ordered: true
145
- }
146
- },
147
- record: {
148
- compareGroup: "record",
149
- castTargets: ["record", "text"],
150
- traits: {}
151
- },
152
- array: {
153
- compareGroup: "array",
154
- castTargets: ["array", "text"],
155
- traits: {}
156
- },
157
- money: {
158
- compareGroup: "money",
159
- castTargets: ["money", "text", "numeric"],
160
- traits: {
161
- ordered: true
162
- }
163
- },
164
- null: {
165
- compareGroup: "null",
166
- castTargets: [
167
- "text",
168
- "numeric",
169
- "boolean",
170
- "date",
171
- "time",
172
- "timestamp",
173
- "interval",
174
- "binary",
175
- "uuid",
176
- "json",
177
- "xml",
178
- "bit",
179
- "oid",
180
- "identifier",
181
- "network",
182
- "spatial",
183
- "textsearch",
184
- "range",
185
- "multirange",
186
- "array",
187
- "money",
188
- "null"
189
- ],
190
- traits: {}
191
- }
192
- } as const satisfies Record<string, DatatypeFamilySpec>
193
-
194
- export const postgresDatatypeKinds = {
195
- text: { family: "text", runtime: "string" },
196
- varchar: { family: "text", runtime: "string" },
197
- char: { family: "text", runtime: "string" },
198
- citext: { family: "text", runtime: "string" },
199
- name: { family: "text", runtime: "string" },
200
- uuid: { family: "uuid", runtime: "string" },
201
- int2: { family: "numeric", runtime: "number" },
202
- int4: { family: "numeric", runtime: "number" },
203
- int8: { family: "numeric", runtime: "bigintString" },
204
- numeric: { family: "numeric", runtime: "decimalString" },
205
- float4: { family: "numeric", runtime: "number" },
206
- float8: { family: "numeric", runtime: "number" },
207
- money: { family: "money", runtime: "number" },
208
- bool: { family: "boolean", runtime: "boolean" },
209
- date: { family: "date", runtime: "localDate" },
210
- time: { family: "time", runtime: "localTime" },
211
- timetz: { family: "time", runtime: "offsetTime" },
212
- timestamp: { family: "timestamp", runtime: "localDateTime" },
213
- timestamptz: { family: "timestamp", runtime: "instant" },
214
- interval: { family: "interval", runtime: "string" },
215
- bytea: { family: "binary", runtime: "bytes" },
216
- json: { family: "json", runtime: "json" },
217
- jsonb: { family: "json", runtime: "json" },
218
- xml: { family: "xml", runtime: "string" },
219
- bit: { family: "bit", runtime: "string" },
220
- varbit: { family: "bit", runtime: "string" },
221
- oid: { family: "oid", runtime: "number" },
222
- xid: { family: "oid", runtime: "number" },
223
- xid8: { family: "oid", runtime: "bigintString" },
224
- cid: { family: "oid", runtime: "number" },
225
- tid: { family: "identifier", runtime: "string" },
226
- regclass: { family: "identifier", runtime: "string" },
227
- regtype: { family: "identifier", runtime: "string" },
228
- regproc: { family: "identifier", runtime: "string" },
229
- regprocedure: { family: "identifier", runtime: "string" },
230
- regoper: { family: "identifier", runtime: "string" },
231
- regoperator: { family: "identifier", runtime: "string" },
232
- regconfig: { family: "identifier", runtime: "string" },
233
- regdictionary: { family: "identifier", runtime: "string" },
234
- pg_lsn: { family: "identifier", runtime: "string" },
235
- txid_snapshot: { family: "identifier", runtime: "string" },
236
- inet: { family: "network", runtime: "string" },
237
- cidr: { family: "network", runtime: "string" },
238
- macaddr: { family: "network", runtime: "string" },
239
- macaddr8: { family: "network", runtime: "string" },
240
- point: { family: "spatial", runtime: "unknown" },
241
- line: { family: "spatial", runtime: "unknown" },
242
- lseg: { family: "spatial", runtime: "unknown" },
243
- box: { family: "spatial", runtime: "unknown" },
244
- path: { family: "spatial", runtime: "unknown" },
245
- polygon: { family: "spatial", runtime: "unknown" },
246
- circle: { family: "spatial", runtime: "unknown" },
247
- tsvector: { family: "textsearch", runtime: "string" },
248
- tsquery: { family: "textsearch", runtime: "string" },
249
- int4range: { family: "range", runtime: "unknown" },
250
- int8range: { family: "range", runtime: "unknown" },
251
- numrange: { family: "range", runtime: "unknown" },
252
- tsrange: { family: "range", runtime: "unknown" },
253
- tstzrange: { family: "range", runtime: "unknown" },
254
- daterange: { family: "range", runtime: "unknown" },
255
- int4multirange: { family: "multirange", runtime: "unknown" },
256
- int8multirange: { family: "multirange", runtime: "unknown" },
257
- nummultirange: { family: "multirange", runtime: "unknown" },
258
- tsmultirange: { family: "multirange", runtime: "unknown" },
259
- tstzmultirange: { family: "multirange", runtime: "unknown" },
260
- datemultirange: { family: "multirange", runtime: "unknown" }
261
- } as const satisfies Record<string, DatatypeKindSpec>
6
+ export const postgresDatatypeFamilies = matrixPostgresDatatypeFamilies
7
+ export const postgresDatatypeKinds = matrixPostgresDatatypeKinds
262
8
 
263
9
  export type PostgresDatatypeFamily = keyof typeof postgresDatatypeFamilies
264
10
  export type PostgresDatatypeKind = keyof typeof postgresDatatypeKinds
@@ -29,7 +29,6 @@ const unwrapPostgresDriverCause = (cause: unknown): unknown => {
29
29
  while (
30
30
  isRecord(current) &&
31
31
  "_tag" in current &&
32
- current._tag === "SqlError" &&
33
32
  "cause" in current
34
33
  ) {
35
34
  current = current.cause
@@ -6,6 +6,7 @@ import * as CoreExecutor from "../internal/executor.js"
6
6
  import * as CoreQuery from "../internal/query.js"
7
7
  import * as CoreRenderer from "../internal/renderer.js"
8
8
  import type * as Expression from "../internal/scalar.js"
9
+ import type { PostgresDatatypeFamily, PostgresDatatypeKind } from "./datatypes/spec.js"
9
10
  import { renderPostgresPlan } from "./internal/renderer.js"
10
11
  import {
11
12
  narrowPostgresDriverErrorForReadQuery,
@@ -24,12 +25,13 @@ export type Driver<Error = never, Context = never> = CoreExecutor.Driver<"postgr
24
25
  export type Executor<Error = never, Context = never> = CoreExecutor.Executor<"postgres", Error, Context>
25
26
  /** Postgres-specialized renderer contract. */
26
27
  export type Renderer = CoreRenderer.Renderer<"postgres">
28
+ export type ValueMappings = Expression.DriverValueMappingsFor<PostgresDatatypeKind, PostgresDatatypeFamily>
27
29
  /** Optional renderer / driver overrides for the standard Postgres executor pipeline. */
28
30
  export interface MakeOptions<Error = never, Context = never> {
29
31
  readonly renderer?: Renderer
30
32
  readonly driver?: Driver<Error, Context>
31
33
  readonly driverMode?: CoreExecutor.DriverMode
32
- readonly valueMappings?: Expression.DriverValueMappings
34
+ readonly valueMappings?: ValueMappings
33
35
  }
34
36
  /** Standard composed error shape for Postgres executors. */
35
37
  export type PostgresExecutorError = PostgresDriverError | RowDecodeError
@@ -39,8 +41,6 @@ export type PostgresQueryError<PlanValue extends CoreQuery.QueryPlan<any, any, a
39
41
 
40
42
  /** Runs an effect within the ambient Postgres SQL transaction service. */
41
43
  export const withTransaction = CoreExecutor.withTransaction
42
- /** Runs an effect in a nested Postgres SQL transaction scope. */
43
- export const withSavepoint = CoreExecutor.withSavepoint
44
44
 
45
45
  /** Postgres executor whose error channel narrows based on the query plan. */
46
46
  export interface QueryExecutor<Context = never> {
@@ -181,7 +181,7 @@ export function make(
181
181
  options: {
182
182
  readonly renderer?: Renderer
183
183
  readonly driverMode?: CoreExecutor.DriverMode
184
- readonly valueMappings?: Expression.DriverValueMappings
184
+ readonly valueMappings?: ValueMappings
185
185
  }
186
186
  ): QueryExecutor<SqlClient.SqlClient>
187
187
  export function make<Error = never, Context = never>(
@@ -189,7 +189,7 @@ export function make<Error = never, Context = never>(
189
189
  readonly renderer?: Renderer
190
190
  readonly driver: Driver<Error, Context>
191
191
  readonly driverMode?: CoreExecutor.DriverMode
192
- readonly valueMappings?: Expression.DriverValueMappings
192
+ readonly valueMappings?: ValueMappings
193
193
  }
194
194
  ): QueryExecutor<Context>
195
195
  export function make<Error = never, Context = never>(
@@ -197,14 +197,14 @@ export function make<Error = never, Context = never>(
197
197
  ): QueryExecutor<any> {
198
198
  if (options.driver) {
199
199
  return fromDriver(
200
- options.renderer ?? CoreRenderer.make("postgres", (plan) => renderPostgresPlan(plan, { valueMappings: options.valueMappings })),
200
+ options.renderer ?? CoreRenderer.makeTrusted("postgres", (plan) => renderPostgresPlan(plan, { valueMappings: options.valueMappings })),
201
201
  options.driver,
202
202
  options.driverMode,
203
203
  options.valueMappings
204
204
  )
205
205
  }
206
206
  return fromDriver(
207
- options.renderer ?? CoreRenderer.make("postgres", (plan) => renderPostgresPlan(plan, { valueMappings: options.valueMappings })),
207
+ options.renderer ?? CoreRenderer.makeTrusted("postgres", (plan) => renderPostgresPlan(plan, { valueMappings: options.valueMappings })),
208
208
  sqlClientDriver(),
209
209
  options.driverMode,
210
210
  options.valueMappings