effect-qb 0.17.0 → 0.20.0

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 (137) hide show
  1. package/README.md +11 -1
  2. package/dist/index.js +9376 -0
  3. package/dist/mysql.js +4092 -2671
  4. package/dist/postgres/metadata.js +2589 -1402
  5. package/dist/postgres.js +3953 -3583
  6. package/dist/sqlite.js +5527 -4088
  7. package/dist/standard.js +9330 -0
  8. package/package.json +9 -4
  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.d.ts +3 -3
  14. package/src/internal/column-state.ts +24 -18
  15. package/src/internal/column.ts +52 -15
  16. package/src/internal/datatypes/define.ts +7 -1
  17. package/src/internal/datatypes/enrich.ts +23 -0
  18. package/src/internal/datatypes/lookup.ts +81 -25
  19. package/src/internal/datatypes/matrix.ts +903 -0
  20. package/src/internal/datatypes/shape.ts +2 -0
  21. package/src/internal/derived-table.ts +4 -36
  22. package/src/{mysql/internal/sql-expression-renderer.ts → internal/dialect-renderers/mysql.ts} +552 -361
  23. package/src/{postgres/internal/sql-expression-renderer.ts → internal/dialect-renderers/postgres.ts} +657 -400
  24. package/src/{sqlite/internal/sql-expression-renderer.ts → internal/dialect-renderers/sqlite.ts} +505 -347
  25. package/src/internal/dialect.ts +36 -1
  26. package/src/internal/dsl-mutation-runtime.ts +12 -162
  27. package/src/internal/dsl-plan-runtime.ts +10 -138
  28. package/src/internal/dsl-query-runtime.ts +5 -79
  29. package/src/internal/dsl-transaction-ddl-runtime.ts +41 -65
  30. package/src/internal/executor.ts +66 -49
  31. package/src/internal/grouping-key.ts +87 -20
  32. package/src/internal/implication-runtime.ts +1 -1
  33. package/src/internal/json/path-access.ts +351 -0
  34. package/src/internal/predicate/runtime.ts +3 -0
  35. package/src/internal/query.d.ts +39 -12
  36. package/src/internal/query.ts +65 -26
  37. package/src/internal/renderer.ts +26 -14
  38. package/src/internal/runtime/driver-value-mapping.ts +3 -3
  39. package/src/internal/runtime/normalize.ts +12 -5
  40. package/src/internal/runtime/schema.ts +28 -38
  41. package/src/internal/runtime/value.ts +20 -23
  42. package/src/internal/scalar.d.ts +1 -1
  43. package/src/internal/scalar.ts +8 -2
  44. package/src/internal/schema-derivation.d.ts +12 -61
  45. package/src/internal/schema-derivation.ts +95 -43
  46. package/src/internal/schema-expression.ts +2 -2
  47. package/src/internal/sql-expression-renderer.ts +19 -0
  48. package/src/internal/standard-dsl.ts +6978 -0
  49. package/src/internal/table-options.ts +126 -66
  50. package/src/internal/table.ts +819 -237
  51. package/src/mysql/column-extension.ts +3 -0
  52. package/src/mysql/column.ts +14 -15
  53. package/src/mysql/datatypes/index.ts +4 -2
  54. package/src/mysql/datatypes/spec.ts +6 -176
  55. package/src/mysql/errors/normalize.ts +0 -1
  56. package/src/mysql/executor.ts +11 -11
  57. package/src/mysql/function/temporal.ts +1 -1
  58. package/src/mysql/internal/dialect.ts +9 -4
  59. package/src/mysql/internal/dsl.ts +334 -170
  60. package/src/mysql/internal/renderer.ts +6 -2
  61. package/src/mysql/json.ts +7 -2
  62. package/src/mysql/query-extension.ts +16 -0
  63. package/src/mysql/renderer.ts +37 -3
  64. package/src/mysql/type.ts +60 -0
  65. package/src/mysql.ts +7 -13
  66. package/src/postgres/check.ts +1 -0
  67. package/src/postgres/column-extension.ts +28 -0
  68. package/src/postgres/column.ts +13 -19
  69. package/src/postgres/datatypes/index.d.ts +2 -1
  70. package/src/postgres/datatypes/index.ts +4 -2
  71. package/src/postgres/datatypes/spec.ts +6 -260
  72. package/src/postgres/errors/normalize.ts +0 -1
  73. package/src/postgres/executor.ts +11 -11
  74. package/src/postgres/foreign-key.ts +24 -0
  75. package/src/postgres/function/core.ts +1 -3
  76. package/src/postgres/function/index.ts +1 -17
  77. package/src/postgres/function/temporal.ts +1 -1
  78. package/src/postgres/index.ts +1 -0
  79. package/src/postgres/internal/dialect.ts +9 -4
  80. package/src/postgres/internal/dsl.ts +328 -179
  81. package/src/postgres/internal/renderer.ts +6 -2
  82. package/src/postgres/internal/schema-ddl.ts +22 -10
  83. package/src/postgres/internal/schema-model.ts +238 -7
  84. package/src/postgres/json-extension.ts +7 -0
  85. package/src/postgres/json.ts +762 -173
  86. package/src/postgres/jsonb.ts +37 -0
  87. package/src/postgres/primary-key.ts +24 -0
  88. package/src/postgres/query-extension.ts +2 -0
  89. package/src/postgres/renderer.ts +37 -3
  90. package/src/postgres/schema-management.ts +13 -13
  91. package/src/postgres/schema.ts +106 -15
  92. package/src/postgres/table.ts +205 -538
  93. package/src/postgres/type.ts +93 -10
  94. package/src/postgres/unique.ts +32 -0
  95. package/src/postgres.ts +20 -16
  96. package/src/sqlite/column-extension.ts +3 -0
  97. package/src/sqlite/column.ts +14 -15
  98. package/src/sqlite/datatypes/index.ts +4 -2
  99. package/src/sqlite/datatypes/spec.ts +6 -94
  100. package/src/sqlite/errors/normalize.ts +0 -1
  101. package/src/sqlite/executor.ts +11 -11
  102. package/src/sqlite/function/temporal.ts +1 -1
  103. package/src/sqlite/internal/dialect.ts +9 -4
  104. package/src/sqlite/internal/dsl.ts +307 -159
  105. package/src/sqlite/internal/renderer.ts +6 -2
  106. package/src/sqlite/json.ts +8 -2
  107. package/src/sqlite/query-extension.ts +2 -0
  108. package/src/sqlite/renderer.ts +37 -3
  109. package/src/sqlite/type.ts +40 -0
  110. package/src/sqlite.ts +7 -13
  111. package/src/standard/cast.ts +113 -0
  112. package/src/standard/check.ts +17 -0
  113. package/src/standard/column.ts +163 -0
  114. package/src/standard/datatypes/index.ts +83 -0
  115. package/src/standard/datatypes/spec.ts +12 -0
  116. package/src/standard/dialect.ts +40 -0
  117. package/src/standard/foreign-key.ts +37 -0
  118. package/src/standard/function/aggregate.ts +2 -0
  119. package/src/standard/function/core.ts +2 -0
  120. package/src/standard/function/index.ts +18 -0
  121. package/src/standard/function/string.ts +2 -0
  122. package/src/standard/function/temporal.ts +78 -0
  123. package/src/standard/function/window.ts +2 -0
  124. package/src/standard/index.ts +17 -0
  125. package/src/standard/internal/renderer.ts +45 -0
  126. package/src/standard/json.ts +883 -0
  127. package/src/standard/primary-key.ts +17 -0
  128. package/src/standard/query.ts +152 -0
  129. package/src/standard/renderer.ts +49 -0
  130. package/src/standard/table.ts +151 -0
  131. package/src/standard/unique.ts +17 -0
  132. package/src/standard.ts +32 -0
  133. package/src/internal/aggregation-validation.ts +0 -57
  134. package/src/internal/table.d.ts +0 -173
  135. package/src/mysql/table.ts +0 -183
  136. package/src/postgres/cast.ts +0 -45
  137. package/src/sqlite/table.ts +0 -183
@@ -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,15 +22,8 @@ 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
- schema: Schema.Schema<Type, any, any>,
26
+ schema: Schema.Schema<Type>,
33
27
  dbType: Db
34
28
  ): ColumnDefinition<Type, Type, Type, Db, false, false, false, false, false, undefined> =>
35
29
  makeColumnDefinition(schema as Schema.Schema<NonNullable<Type>>, {
@@ -57,16 +51,16 @@ const renderNumericDdlType = (
57
51
  const boundedString = (length?: number): Schema.Schema<string> =>
58
52
  length === undefined
59
53
  ? Schema.String
60
- : Schema.String.pipe(Schema.maxLength(length))
54
+ : Schema.String.check(Schema.isMaxLength(length))
61
55
 
62
- const finiteNumber = Schema.Number.pipe(Schema.finite())
56
+ const finiteNumber = Schema.Number.check(Schema.isFinite())
63
57
 
64
- export const custom = <SchemaType extends Schema.Schema.Any, Db extends Expression.DbType.Any>(
58
+ export const custom = <SchemaType extends Schema.Top, Db extends Expression.DbType.Any>(
65
59
  schema: SchemaType,
66
60
  dbType: Db
67
61
  ) =>
68
- makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>, any, any>, {
69
- dbType: enrichDbType(dbType),
62
+ makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>>, {
63
+ dbType: enrichDbType(postgresDatatypes, dbType),
70
64
  nullable: false,
71
65
  hasDefault: false,
72
66
  generated: false,
@@ -77,7 +71,7 @@ export const custom = <SchemaType extends Schema.Schema.Any, Db extends Expressi
77
71
  identity: undefined
78
72
  })
79
73
 
80
- export const uuid = () => primitive(Schema.UUID, postgresDatatypes.uuid())
74
+ export const uuid = () => primitive(Schema.String.check(Schema.isUUID()), postgresDatatypes.uuid())
81
75
  export const text = () => primitive(Schema.String, postgresDatatypes.text())
82
76
  export const int = () => primitive(Schema.Int, postgresDatatypes.int4())
83
77
  export const int2 = () => primitive(Schema.Int, postgresDatatypes.int2())
@@ -103,7 +97,7 @@ export const time = () => primitive(LocalTimeStringSchema, postgresDatatypes.tim
103
97
  export const timetz = () => primitive(OffsetTimeStringSchema, postgresDatatypes.timetz())
104
98
  export const timestamptz = () => primitive(InstantStringSchema, postgresDatatypes.timestamptz())
105
99
  export const interval = () => primitive(Schema.String, postgresDatatypes.interval())
106
- export const bytea = () => primitive(Schema.Uint8ArrayFromSelf, postgresDatatypes.bytea())
100
+ export const bytea = () => primitive(Schema.Uint8Array, postgresDatatypes.bytea())
107
101
  export const name = () => primitive(Schema.String, postgresDatatypes.name())
108
102
  export const oid = () => primitive(Schema.Int, postgresDatatypes.oid())
109
103
  export const regclass = () => primitive(Schema.String, postgresDatatypes.regclass())
@@ -135,8 +129,8 @@ export const varchar = (length?: number) =>
135
129
  ddlType: length === undefined ? "varchar" : `varchar(${length})`,
136
130
  identity: undefined
137
131
  })
138
- export const json = <SchemaType extends Schema.Schema.Any>(schema: SchemaType) =>
139
- makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>, any, any>, {
132
+ export const json = <SchemaType extends Schema.Top>(schema: SchemaType) =>
133
+ makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>>, {
140
134
  dbType: postgresDatatypes.json(),
141
135
  nullable: false,
142
136
  hasDefault: false,
@@ -147,8 +141,8 @@ export const json = <SchemaType extends Schema.Schema.Any>(schema: SchemaType) =
147
141
  ddlType: undefined,
148
142
  identity: undefined
149
143
  })
150
- export const jsonb = <SchemaType extends Schema.Schema.Any>(schema: SchemaType) =>
151
- makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>, any, any>, {
144
+ export const jsonb = <SchemaType extends Schema.Top>(schema: SchemaType) =>
145
+ makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>>, {
152
146
  dbType: postgresDatatypes.jsonb(),
153
147
  nullable: false,
154
148
  hasDefault: 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