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

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 (126) hide show
  1. package/README.md +5 -2
  2. package/dist/index.js +9373 -0
  3. package/dist/mysql.js +3917 -2572
  4. package/dist/postgres/metadata.js +2491 -1373
  5. package/dist/postgres.js +5450 -5155
  6. package/dist/sqlite.js +6891 -5528
  7. package/dist/standard.js +9327 -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 +6975 -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/executor.ts +7 -7
  51. package/src/mysql/internal/dialect.ts +9 -4
  52. package/src/mysql/internal/dsl.ts +309 -154
  53. package/src/mysql/internal/renderer.ts +6 -2
  54. package/src/mysql/json.ts +7 -2
  55. package/src/mysql/query-extension.ts +16 -0
  56. package/src/mysql/renderer.ts +37 -3
  57. package/src/mysql/type.ts +60 -0
  58. package/src/mysql.ts +7 -13
  59. package/src/postgres/check.ts +1 -0
  60. package/src/postgres/column-extension.ts +28 -0
  61. package/src/postgres/column.ts +2 -8
  62. package/src/postgres/datatypes/index.d.ts +2 -1
  63. package/src/postgres/datatypes/index.ts +4 -2
  64. package/src/postgres/datatypes/spec.ts +6 -260
  65. package/src/postgres/executor.ts +7 -7
  66. package/src/postgres/foreign-key.ts +24 -0
  67. package/src/postgres/function/core.ts +1 -3
  68. package/src/postgres/function/index.ts +1 -17
  69. package/src/postgres/index.ts +1 -0
  70. package/src/postgres/internal/dialect.ts +9 -4
  71. package/src/postgres/internal/dsl.ts +303 -163
  72. package/src/postgres/internal/renderer.ts +6 -2
  73. package/src/postgres/internal/schema-ddl.ts +22 -10
  74. package/src/postgres/internal/schema-model.ts +238 -7
  75. package/src/postgres/json-extension.ts +7 -0
  76. package/src/postgres/json.ts +762 -173
  77. package/src/postgres/jsonb.ts +37 -0
  78. package/src/postgres/primary-key.ts +24 -0
  79. package/src/postgres/query-extension.ts +2 -0
  80. package/src/postgres/renderer.ts +37 -3
  81. package/src/postgres/schema-management.ts +12 -11
  82. package/src/postgres/schema.ts +106 -15
  83. package/src/postgres/table.ts +205 -530
  84. package/src/postgres/type.ts +93 -10
  85. package/src/postgres/unique.ts +32 -0
  86. package/src/postgres.ts +20 -16
  87. package/src/sqlite/column-extension.ts +3 -0
  88. package/src/sqlite/column.ts +8 -9
  89. package/src/sqlite/datatypes/index.ts +4 -2
  90. package/src/sqlite/datatypes/spec.ts +6 -94
  91. package/src/sqlite/executor.ts +7 -7
  92. package/src/sqlite/internal/dialect.ts +9 -4
  93. package/src/sqlite/internal/dsl.ts +298 -154
  94. package/src/sqlite/internal/renderer.ts +6 -2
  95. package/src/sqlite/json.ts +8 -2
  96. package/src/sqlite/query-extension.ts +2 -0
  97. package/src/sqlite/renderer.ts +37 -3
  98. package/src/sqlite/type.ts +40 -0
  99. package/src/sqlite.ts +7 -13
  100. package/src/standard/cast.ts +113 -0
  101. package/src/standard/check.ts +17 -0
  102. package/src/standard/column.ts +163 -0
  103. package/src/standard/datatypes/index.ts +83 -0
  104. package/src/standard/datatypes/spec.ts +12 -0
  105. package/src/standard/dialect.ts +40 -0
  106. package/src/standard/foreign-key.ts +37 -0
  107. package/src/standard/function/aggregate.ts +2 -0
  108. package/src/standard/function/core.ts +2 -0
  109. package/src/standard/function/index.ts +18 -0
  110. package/src/standard/function/string.ts +2 -0
  111. package/src/standard/function/temporal.ts +78 -0
  112. package/src/standard/function/window.ts +2 -0
  113. package/src/standard/index.ts +17 -0
  114. package/src/standard/internal/renderer.ts +45 -0
  115. package/src/standard/json.ts +883 -0
  116. package/src/standard/primary-key.ts +17 -0
  117. package/src/standard/query.ts +152 -0
  118. package/src/standard/renderer.ts +49 -0
  119. package/src/standard/table.ts +151 -0
  120. package/src/standard/unique.ts +17 -0
  121. package/src/standard.ts +32 -0
  122. package/src/internal/aggregation-validation.ts +0 -57
  123. package/src/internal/table.d.ts +0 -180
  124. package/src/mysql/table.ts +0 -186
  125. package/src/postgres/cast.ts +0 -45
  126. package/src/sqlite/table.ts +0 -175
@@ -0,0 +1,3 @@
1
+ export { custom } from "./column.js"
2
+
3
+ export type { Any, AnyBound } from "./column.js"
@@ -3,6 +3,8 @@ import * as Schema from "effect/Schema"
3
3
  import * as BaseColumn from "../internal/column.js"
4
4
  import { makeColumnDefinition, type AnyColumnDefinition, type ColumnDefinition } from "../internal/column-state.js"
5
5
  import type * as Expression from "../internal/scalar.js"
6
+ import type { NonEmptyStringInput } from "../internal/table-options.js"
7
+ import { enrichDbType } from "../internal/datatypes/enrich.js"
6
8
  import {
7
9
  DecimalStringSchema,
8
10
  LocalDateStringSchema,
@@ -13,13 +15,6 @@ import {
13
15
  } from "../internal/runtime/value.js"
14
16
  import { mysqlDatatypes } from "./datatypes/index.js"
15
17
 
16
- const enrichDbType = <Db extends Expression.DbType.Any>(dbType: Db): Db => {
17
- const candidate = (mysqlDatatypes as unknown as Record<string, (() => Expression.DbType.Any) | undefined>)[dbType.kind]
18
- return typeof candidate === "function"
19
- ? { ...candidate(), ...dbType } as Db
20
- : dbType
21
- }
22
-
23
18
  const primitive = <Type, Db extends Expression.DbType.Any>(
24
19
  schema: Schema.Schema<Type>,
25
20
  dbType: Db
@@ -51,7 +46,7 @@ export const custom = <SchemaType extends Schema.Top, Db extends Expression.DbTy
51
46
  dbType: Db
52
47
  ) =>
53
48
  makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>>, {
54
- dbType: enrichDbType(dbType),
49
+ dbType: enrichDbType(mysqlDatatypes, dbType),
55
50
  nullable: false,
56
51
  hasDefault: false,
57
52
  generated: false,
@@ -106,10 +101,14 @@ type MysqlUniqueOptions = {
106
101
  readonly initiallyDeferred?: never
107
102
  }
108
103
 
104
+ type NonEmptyOptionNameInput<Options> = Options extends { readonly name: infer Name extends string }
105
+ ? NonEmptyStringInput<Name> extends never ? never : unknown
106
+ : unknown
107
+
109
108
  type UniqueModifier = {
110
109
  <Column extends AnyColumnDefinition>(column: Column): UniqueColumn<Column>
111
110
  readonly options: <const Options extends MysqlUniqueOptions>(
112
- options: Options
111
+ options: Options & NonEmptyOptionNameInput<Options>
113
112
  ) => <Column extends AnyColumnDefinition>(column: Column) => UniqueColumn<Column>
114
113
  }
115
114
 
@@ -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 { mysqlDatatypeFamilies, mysqlDatatypeKinds } from "./spec.js"
4
5
 
5
6
  const withMetadata = <Kind extends keyof typeof mysqlDatatypeKinds & string>(
@@ -14,14 +15,15 @@ const withMetadata = <Kind extends keyof typeof mysqlDatatypeKinds & 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 mysqlDatatypeModule = {
22
- custom: (kind: string) => ({
24
+ custom: <Kind extends string>(kind: NonEmptyStringInput<Kind>) => ({
23
25
  dialect: "mysql",
24
- kind
26
+ kind: kind as Kind
25
27
  }),
26
28
  uuid: () => ({
27
29
  dialect: "mysql",
@@ -1,180 +1,10 @@
1
- import type { DatatypeFamilySpec, DatatypeKindSpec } from "../../internal/datatypes/shape.js"
1
+ import {
2
+ mysqlDatatypeFamilies as matrixMysqlDatatypeFamilies,
3
+ mysqlDatatypeKinds as matrixMysqlDatatypeKinds
4
+ } from "../../internal/datatypes/matrix.js"
2
5
 
3
- export const mysqlDatatypeFamilies = {
4
- text: {
5
- compareGroup: "text",
6
- castTargets: [
7
- "text",
8
- "numeric",
9
- "boolean",
10
- "date",
11
- "time",
12
- "datetime",
13
- "timestamp",
14
- "year",
15
- "binary",
16
- "json",
17
- "bit",
18
- "enum",
19
- "set",
20
- "null"
21
- ],
22
- traits: {
23
- textual: true,
24
- ordered: true
25
- }
26
- },
27
- numeric: {
28
- compareGroup: "numeric",
29
- castTargets: ["numeric", "text", "boolean", "date", "time", "datetime", "timestamp", "year", "bit"],
30
- traits: {
31
- ordered: true
32
- }
33
- },
34
- boolean: {
35
- compareGroup: "boolean",
36
- castTargets: ["boolean", "text", "numeric"],
37
- traits: {}
38
- },
39
- bit: {
40
- compareGroup: "bit",
41
- castTargets: ["bit", "text", "numeric"],
42
- traits: {}
43
- },
44
- date: {
45
- compareGroup: "date",
46
- castTargets: ["date", "datetime", "timestamp", "text"],
47
- traits: {
48
- ordered: true
49
- }
50
- },
51
- time: {
52
- compareGroup: "time",
53
- castTargets: ["time", "datetime", "timestamp", "text"],
54
- traits: {
55
- ordered: true
56
- }
57
- },
58
- datetime: {
59
- compareGroup: "datetime",
60
- castTargets: ["datetime", "timestamp", "date", "text"],
61
- traits: {
62
- ordered: true
63
- }
64
- },
65
- timestamp: {
66
- compareGroup: "timestamp",
67
- castTargets: ["timestamp", "datetime", "date", "text"],
68
- traits: {
69
- ordered: true
70
- }
71
- },
72
- year: {
73
- compareGroup: "year",
74
- castTargets: ["year", "text", "numeric"],
75
- traits: {
76
- ordered: true
77
- }
78
- },
79
- binary: {
80
- compareGroup: "binary",
81
- castTargets: ["binary", "text"],
82
- traits: {}
83
- },
84
- json: {
85
- compareGroup: "json",
86
- castTargets: ["json", "text"],
87
- traits: {}
88
- },
89
- spatial: {
90
- compareGroup: "spatial",
91
- castTargets: ["spatial", "text"],
92
- traits: {}
93
- },
94
- enum: {
95
- compareGroup: "enum",
96
- castTargets: ["enum", "text"],
97
- traits: {
98
- textual: true,
99
- ordered: true
100
- }
101
- },
102
- set: {
103
- compareGroup: "set",
104
- castTargets: ["set", "text"],
105
- traits: {
106
- textual: true
107
- }
108
- },
109
- null: {
110
- compareGroup: "null",
111
- castTargets: [
112
- "text",
113
- "numeric",
114
- "boolean",
115
- "bit",
116
- "date",
117
- "time",
118
- "datetime",
119
- "timestamp",
120
- "year",
121
- "binary",
122
- "json",
123
- "spatial",
124
- "enum",
125
- "set",
126
- "null"
127
- ],
128
- traits: {}
129
- }
130
- } as const satisfies Record<string, DatatypeFamilySpec>
131
-
132
- export const mysqlDatatypeKinds = {
133
- char: { family: "text", runtime: "string" },
134
- varchar: { family: "text", runtime: "string" },
135
- tinytext: { family: "text", runtime: "string" },
136
- text: { family: "text", runtime: "string" },
137
- mediumtext: { family: "text", runtime: "string" },
138
- longtext: { family: "text", runtime: "string" },
139
- tinyint: { family: "numeric", runtime: "number" },
140
- smallint: { family: "numeric", runtime: "number" },
141
- mediumint: { family: "numeric", runtime: "number" },
142
- int: { family: "numeric", runtime: "number" },
143
- integer: { family: "numeric", runtime: "number" },
144
- bigint: { family: "numeric", runtime: "bigintString" },
145
- decimal: { family: "numeric", runtime: "decimalString" },
146
- dec: { family: "numeric", runtime: "decimalString" },
147
- numeric: { family: "numeric", runtime: "decimalString" },
148
- fixed: { family: "numeric", runtime: "decimalString" },
149
- float: { family: "numeric", runtime: "number" },
150
- double: { family: "numeric", runtime: "number" },
151
- real: { family: "numeric", runtime: "number" },
152
- bool: { family: "boolean", runtime: "boolean" },
153
- boolean: { family: "boolean", runtime: "boolean" },
154
- bit: { family: "bit", runtime: "string" },
155
- date: { family: "date", runtime: "localDate" },
156
- time: { family: "time", runtime: "localTime" },
157
- datetime: { family: "datetime", runtime: "localDateTime" },
158
- timestamp: { family: "timestamp", runtime: "localDateTime" },
159
- year: { family: "year", runtime: "year" },
160
- binary: { family: "binary", runtime: "bytes" },
161
- varbinary: { family: "binary", runtime: "bytes" },
162
- tinyblob: { family: "binary", runtime: "bytes" },
163
- blob: { family: "binary", runtime: "bytes" },
164
- mediumblob: { family: "binary", runtime: "bytes" },
165
- longblob: { family: "binary", runtime: "bytes" },
166
- json: { family: "json", runtime: "json" },
167
- geometry: { family: "spatial", runtime: "unknown" },
168
- point: { family: "spatial", runtime: "unknown" },
169
- linestring: { family: "spatial", runtime: "unknown" },
170
- polygon: { family: "spatial", runtime: "unknown" },
171
- multipoint: { family: "spatial", runtime: "unknown" },
172
- multilinestring: { family: "spatial", runtime: "unknown" },
173
- multipolygon: { family: "spatial", runtime: "unknown" },
174
- geometrycollection: { family: "spatial", runtime: "unknown" },
175
- enum: { family: "enum", runtime: "string" },
176
- set: { family: "set", runtime: "string" }
177
- } as const satisfies Record<string, DatatypeKindSpec>
6
+ export const mysqlDatatypeFamilies = matrixMysqlDatatypeFamilies
7
+ export const mysqlDatatypeKinds = matrixMysqlDatatypeKinds
178
8
 
179
9
  export type MysqlDatatypeFamily = keyof typeof mysqlDatatypeFamilies
180
10
  export type MysqlDatatypeKind = keyof typeof mysqlDatatypeKinds
@@ -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 { MysqlDatatypeFamily, MysqlDatatypeKind } from "./datatypes/spec.js"
9
10
  import { renderMysqlPlan } from "./internal/renderer.js"
10
11
  import {
11
12
  narrowMysqlDriverErrorForReadQuery,
@@ -24,12 +25,13 @@ export type Driver<Error = never, Context = never> = CoreExecutor.Driver<"mysql"
24
25
  export type Executor<Error = never, Context = never> = CoreExecutor.Executor<"mysql", Error, Context>
25
26
  /** MySQL-specialized renderer contract. */
26
27
  export type Renderer = CoreRenderer.Renderer<"mysql">
28
+ export type ValueMappings = Expression.DriverValueMappingsFor<MysqlDatatypeKind | "uuid", MysqlDatatypeFamily | "uuid">
27
29
  /** Optional renderer / driver overrides for the standard MySQL 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 MySQL executors. */
35
37
  export type MysqlExecutorError = MysqlDriverError | RowDecodeError
@@ -39,8 +41,6 @@ export type MysqlQueryError<PlanValue extends CoreQuery.QueryPlan<any, any, any,
39
41
 
40
42
  /** Runs an effect within the ambient MySQL SQL transaction service. */
41
43
  export const withTransaction = CoreExecutor.withTransaction
42
- /** Runs an effect in a nested MySQL SQL transaction scope. */
43
- export const withSavepoint = CoreExecutor.withSavepoint
44
44
 
45
45
  /** MySQL executor whose error channel narrows based on the query plan. */
46
46
  export interface QueryExecutor<Context = never> {
@@ -172,7 +172,7 @@ export function make(
172
172
  options: {
173
173
  readonly renderer?: Renderer
174
174
  readonly driverMode?: CoreExecutor.DriverMode
175
- readonly valueMappings?: Expression.DriverValueMappings
175
+ readonly valueMappings?: ValueMappings
176
176
  }
177
177
  ): QueryExecutor<SqlClient.SqlClient>
178
178
  export function make<Error = never, Context = never>(
@@ -180,7 +180,7 @@ export function make<Error = never, Context = never>(
180
180
  readonly renderer?: Renderer
181
181
  readonly driver: Driver<Error, Context>
182
182
  readonly driverMode?: CoreExecutor.DriverMode
183
- readonly valueMappings?: Expression.DriverValueMappings
183
+ readonly valueMappings?: ValueMappings
184
184
  }
185
185
  ): QueryExecutor<Context>
186
186
  export function make<Error = never, Context = never>(
@@ -188,14 +188,14 @@ export function make<Error = never, Context = never>(
188
188
  ): QueryExecutor<any> {
189
189
  if (options.driver) {
190
190
  return fromDriver(
191
- options.renderer ?? CoreRenderer.make("mysql", (plan) => renderMysqlPlan(plan, { valueMappings: options.valueMappings })),
191
+ options.renderer ?? CoreRenderer.makeTrusted("mysql", (plan) => renderMysqlPlan(plan, { valueMappings: options.valueMappings })),
192
192
  options.driver,
193
193
  options.driverMode,
194
194
  options.valueMappings
195
195
  )
196
196
  }
197
197
  return fromDriver(
198
- options.renderer ?? CoreRenderer.make("mysql", (plan) => renderMysqlPlan(plan, { valueMappings: options.valueMappings })),
198
+ options.renderer ?? CoreRenderer.makeTrusted("mysql", (plan) => renderMysqlPlan(plan, { valueMappings: options.valueMappings })),
199
199
  sqlClientDriver(),
200
200
  options.driverMode,
201
201
  options.valueMappings
@@ -1,7 +1,9 @@
1
- import type { RenderState, RenderValueContext, SqlDialect } from "../../internal/dialect.js"
1
+ import { quoteBacktickIdentifier, type RenderState, type RenderValueContext, type SqlDialect } from "../../internal/dialect.js"
2
+ import { renderExpression, renderQueryAst } from "../../internal/dialect-renderers/mysql.js"
2
3
  import { toDriverValue } from "../../internal/runtime/driver-value-mapping.js"
4
+ import { standardDialect } from "../../standard/dialect.js"
3
5
 
4
- const quoteIdentifier = (value: string): string => `\`${value.replaceAll("`", "``")}\``
6
+ const quoteIdentifier = quoteBacktickIdentifier
5
7
 
6
8
  const renderLiteral = (value: unknown, state: RenderState, context: RenderValueContext = {}): string => {
7
9
  const driverValue = toDriverValue(value, {
@@ -28,11 +30,12 @@ const renderLiteral = (value: unknown, state: RenderState, context: RenderValueC
28
30
  * grows.
29
31
  */
30
32
  export const mysqlDialect: SqlDialect<"mysql"> = {
33
+ ...standardDialect,
31
34
  name: "mysql",
32
35
  quoteIdentifier,
33
36
  renderLiteral,
34
37
  renderTableReference(tableName, baseTableName, schemaName) {
35
- const renderedBase = schemaName
38
+ const renderedBase = schemaName && schemaName !== "public"
36
39
  ? `${quoteIdentifier(schemaName)}.${quoteIdentifier(baseTableName)}`
37
40
  : quoteIdentifier(baseTableName)
38
41
  return tableName === baseTableName
@@ -41,5 +44,7 @@ export const mysqlDialect: SqlDialect<"mysql"> = {
41
44
  },
42
45
  renderConcat(values) {
43
46
  return `concat(${values.join(", ")})`
44
- }
47
+ },
48
+ renderQueryAst,
49
+ renderExpression
45
50
  }