effect-qb 0.16.0 → 4.0.0-beta.66

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 (88) hide show
  1. package/README.md +7 -0
  2. package/dist/mysql.js +1858 -715
  3. package/dist/postgres/metadata.js +2036 -172
  4. package/dist/postgres.js +8011 -6849
  5. package/dist/sqlite.js +8433 -0
  6. package/package.json +7 -4
  7. package/src/internal/column-state.d.ts +3 -3
  8. package/src/internal/column-state.ts +3 -3
  9. package/src/internal/column.ts +8 -8
  10. package/src/internal/derived-table.ts +29 -3
  11. package/src/internal/dialect.ts +3 -1
  12. package/src/internal/dsl-mutation-runtime.ts +173 -4
  13. package/src/internal/dsl-plan-runtime.ts +165 -20
  14. package/src/internal/dsl-query-runtime.ts +60 -6
  15. package/src/internal/dsl-transaction-ddl-runtime.ts +72 -2
  16. package/src/internal/executor.ts +100 -43
  17. package/src/internal/expression-ast.ts +3 -2
  18. package/src/internal/grouping-key.ts +141 -1
  19. package/src/internal/implication-runtime.ts +2 -1
  20. package/src/internal/json/types.ts +155 -40
  21. package/src/internal/predicate/context.ts +14 -1
  22. package/src/internal/predicate/key.ts +19 -2
  23. package/src/internal/predicate/runtime.ts +27 -3
  24. package/src/internal/query.d.ts +1 -1
  25. package/src/internal/query.ts +253 -31
  26. package/src/internal/renderer.ts +35 -2
  27. package/src/internal/runtime/driver-value-mapping.ts +60 -2
  28. package/src/internal/runtime/normalize.ts +62 -38
  29. package/src/internal/runtime/schema.ts +32 -40
  30. package/src/internal/runtime/value.ts +159 -39
  31. package/src/internal/scalar.d.ts +1 -1
  32. package/src/internal/scalar.ts +1 -1
  33. package/src/internal/schema-derivation.d.ts +12 -61
  34. package/src/internal/schema-derivation.ts +95 -43
  35. package/src/internal/table-options.ts +108 -1
  36. package/src/internal/table.d.ts +29 -22
  37. package/src/internal/table.ts +260 -53
  38. package/src/mysql/column.ts +24 -8
  39. package/src/mysql/datatypes/index.ts +21 -0
  40. package/src/mysql/errors/catalog.ts +5 -5
  41. package/src/mysql/errors/normalize.ts +2 -2
  42. package/src/mysql/executor.ts +4 -4
  43. package/src/mysql/function/temporal.ts +1 -1
  44. package/src/mysql/internal/dsl.ts +759 -235
  45. package/src/mysql/internal/renderer.ts +2 -1
  46. package/src/mysql/internal/sql-expression-renderer.ts +486 -130
  47. package/src/mysql/query.ts +9 -2
  48. package/src/mysql/table.ts +64 -35
  49. package/src/postgres/column.ts +14 -12
  50. package/src/postgres/errors/normalize.ts +2 -2
  51. package/src/postgres/executor.ts +52 -9
  52. package/src/postgres/function/core.ts +19 -1
  53. package/src/postgres/function/temporal.ts +1 -1
  54. package/src/postgres/internal/dsl.ts +705 -256
  55. package/src/postgres/internal/renderer.ts +2 -1
  56. package/src/postgres/internal/schema-ddl.ts +2 -1
  57. package/src/postgres/internal/schema-model.ts +6 -3
  58. package/src/postgres/internal/sql-expression-renderer.ts +420 -91
  59. package/src/postgres/json.ts +57 -17
  60. package/src/postgres/query.ts +9 -2
  61. package/src/postgres/schema-management.ts +92 -6
  62. package/src/postgres/schema.ts +1 -1
  63. package/src/postgres/table.ts +203 -75
  64. package/src/sqlite/column.ts +128 -0
  65. package/src/sqlite/datatypes/index.ts +79 -0
  66. package/src/sqlite/datatypes/spec.ts +98 -0
  67. package/src/sqlite/errors/catalog.ts +103 -0
  68. package/src/sqlite/errors/fields.ts +19 -0
  69. package/src/sqlite/errors/index.ts +19 -0
  70. package/src/sqlite/errors/normalize.ts +229 -0
  71. package/src/sqlite/errors/requirements.ts +71 -0
  72. package/src/sqlite/errors/types.ts +29 -0
  73. package/src/sqlite/executor.ts +227 -0
  74. package/src/sqlite/function/aggregate.ts +2 -0
  75. package/src/sqlite/function/core.ts +2 -0
  76. package/src/sqlite/function/index.ts +19 -0
  77. package/src/sqlite/function/string.ts +2 -0
  78. package/src/sqlite/function/temporal.ts +100 -0
  79. package/src/sqlite/function/window.ts +2 -0
  80. package/src/sqlite/internal/dialect.ts +37 -0
  81. package/src/sqlite/internal/dsl.ts +6927 -0
  82. package/src/sqlite/internal/renderer.ts +47 -0
  83. package/src/sqlite/internal/sql-expression-renderer.ts +1821 -0
  84. package/src/sqlite/json.ts +2 -0
  85. package/src/sqlite/query.ts +196 -0
  86. package/src/sqlite/renderer.ts +24 -0
  87. package/src/sqlite/table.ts +175 -0
  88. package/src/sqlite.ts +22 -0
@@ -0,0 +1,2 @@
1
+ /** SQLite JSON expression helpers. */
2
+ export { json } from "./internal/dsl.js"
@@ -0,0 +1,196 @@
1
+ import {
2
+ type AnyTableFunctionSource,
3
+ type AnyUnnestSource,
4
+ type AnyValuesSource,
5
+ type CapabilitiesOfPlan,
6
+ type CompletePlan,
7
+ type DialectCompatiblePlan,
8
+ type DerivedSourceRequiredError,
9
+ type CteSource,
10
+ type EffectiveNullability,
11
+ type ExpressionInput,
12
+ type ExpressionOutput,
13
+ type GroupByInput,
14
+ type MergeCapabilities,
15
+ type MergeCapabilityTuple,
16
+ type HavingPredicateInput,
17
+ type OrderDirection,
18
+ type OutputOfSelection,
19
+ type MutationTargetLike,
20
+ type NumericExpressionInput,
21
+ type PredicateInput,
22
+ type QueryCapability,
23
+ type QueryPlan,
24
+ type QueryRequirement,
25
+ type SetCompatiblePlan,
26
+ type SetCompatibleRightPlan,
27
+ type SetOperator,
28
+ type QueryStatement,
29
+ type ResultRow,
30
+ type ResultRows,
31
+ type RuntimeResultRow,
32
+ type RuntimeResultRows,
33
+ type SchemaTableLike,
34
+ type SourceCapabilitiesOf,
35
+ type SourceRequiredOf,
36
+ type SourceRequirementError,
37
+ type StatementOfPlan,
38
+ type StringExpressionInput
39
+ } from "../internal/query.js"
40
+ import {
41
+ type PublicNonStructuredFromApi,
42
+ type PublicStructuredFromConstraint,
43
+ type PublicStructuredFromResult,
44
+ type as sqliteType,
45
+ values,
46
+ unnest,
47
+ select,
48
+ insert,
49
+ from as dslFrom
50
+ } from "./internal/dsl.js"
51
+
52
+ export {
53
+ literal,
54
+ column,
55
+ cast,
56
+ eq,
57
+ neq,
58
+ lt,
59
+ lte,
60
+ gt,
61
+ gte,
62
+ isNull,
63
+ isNotNull,
64
+ like,
65
+ ilike,
66
+ regexMatch,
67
+ regexIMatch,
68
+ regexNotMatch,
69
+ regexNotIMatch,
70
+ and,
71
+ or,
72
+ not,
73
+ all,
74
+ any,
75
+ case_ as case,
76
+ match,
77
+ in_ as in,
78
+ notIn,
79
+ between,
80
+ contains,
81
+ containedBy,
82
+ overlaps,
83
+ exists,
84
+ isDistinctFrom,
85
+ isNotDistinctFrom,
86
+ excluded,
87
+ as,
88
+ with_ as with,
89
+ withRecursive,
90
+ lateral,
91
+ scalar,
92
+ inSubquery,
93
+ compareAny,
94
+ compareAll,
95
+ generateSeries,
96
+ values,
97
+ unnest,
98
+ select,
99
+ returning,
100
+ onConflict,
101
+ insert,
102
+ update,
103
+ upsert,
104
+ delete_ as delete,
105
+ truncate,
106
+ merge,
107
+ transaction,
108
+ commit,
109
+ rollback,
110
+ savepoint,
111
+ rollbackTo,
112
+ releaseSavepoint,
113
+ createTable,
114
+ dropTable,
115
+ createIndex,
116
+ dropIndex,
117
+ union,
118
+ unionAll,
119
+ intersect,
120
+ intersectAll,
121
+ except,
122
+ exceptAll,
123
+ where,
124
+ having,
125
+ innerJoin,
126
+ leftJoin,
127
+ rightJoin,
128
+ fullJoin,
129
+ crossJoin,
130
+ distinct,
131
+ distinctOn,
132
+ limit,
133
+ offset,
134
+ lock,
135
+ orderBy,
136
+ groupBy
137
+ } from "./internal/dsl.js"
138
+ import type * as Expression from "../internal/scalar.js"
139
+ export { sqliteType as type }
140
+
141
+ type SqliteMutationValueInput<Value> =
142
+ | Value
143
+ | Expression.Scalar<Value, Expression.DbType.Any, Expression.Nullability, "sqlite", Expression.ScalarKind, Expression.BindingId>
144
+
145
+ export type MutationInputOf<Shape> = {
146
+ readonly [K in keyof Shape]: SqliteMutationValueInput<Shape[K]>
147
+ }
148
+
149
+ type StructuredSource = AnyValuesSource | AnyUnnestSource | AnyTableFunctionSource
150
+
151
+ type StructuredFromApi = <CurrentSource extends StructuredSource>(
152
+ source: CurrentSource
153
+ ) => <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
154
+ plan: PlanValue & PublicStructuredFromConstraint<PlanValue, CurrentSource, "sqlite">
155
+ ) => PublicStructuredFromResult<PlanValue, CurrentSource, "sqlite">
156
+
157
+ export const from: StructuredFromApi & PublicNonStructuredFromApi = dslFrom as StructuredFromApi & PublicNonStructuredFromApi
158
+
159
+ export type {
160
+ CapabilitiesOfPlan,
161
+ CompletePlan,
162
+ DialectCompatiblePlan,
163
+ DerivedSourceRequiredError,
164
+ CteSource,
165
+ EffectiveNullability,
166
+ ExpressionInput,
167
+ ExpressionOutput,
168
+ GroupByInput,
169
+ MergeCapabilities,
170
+ MergeCapabilityTuple,
171
+ HavingPredicateInput,
172
+ OrderDirection,
173
+ OutputOfSelection,
174
+ MutationTargetLike,
175
+ NumericExpressionInput,
176
+ PredicateInput,
177
+ QueryCapability,
178
+ QueryPlan,
179
+ QueryStatement,
180
+ QueryRequirement,
181
+ SetCompatiblePlan,
182
+ SetCompatibleRightPlan,
183
+ SetOperator,
184
+ ResultRow,
185
+ ResultRows,
186
+ RuntimeResultRow,
187
+ RuntimeResultRows,
188
+ SchemaTableLike,
189
+ SourceCapabilitiesOf,
190
+ SourceRequiredOf,
191
+ SourceRequirementError,
192
+ StatementOfPlan,
193
+ StringExpressionInput
194
+ }
195
+
196
+ export { union_query_capabilities } from "../internal/query.js"
@@ -0,0 +1,24 @@
1
+ import * as CoreRenderer from "../internal/renderer.js"
2
+ import type * as Expression from "../internal/scalar.js"
3
+ import { renderSqlitePlan } from "./internal/renderer.js"
4
+
5
+ /** SQLite-specialized rendered query shape. */
6
+ export type RenderedQuery<Row> = CoreRenderer.RenderedQuery<Row, "sqlite">
7
+ /** Extracts the row type carried by a SQLite rendered query. */
8
+ export type RowOf<Value extends RenderedQuery<any>> = CoreRenderer.RowOf<Value>
9
+ /** SQLite-specialized renderer contract. */
10
+ export type Renderer = CoreRenderer.Renderer<"sqlite">
11
+
12
+ export interface MakeOptions {
13
+ readonly valueMappings?: Expression.DriverValueMappings
14
+ }
15
+
16
+ export { TypeId } from "../internal/renderer.js"
17
+ export type { Projection } from "../internal/renderer.js"
18
+
19
+ /** Creates the built-in SQLite renderer. */
20
+ export const make = (options: MakeOptions = {}): Renderer =>
21
+ CoreRenderer.make("sqlite", (plan) => renderSqlitePlan(plan, options))
22
+
23
+ /** Shared built-in SQLite renderer instance. */
24
+ export const sqlite = make()
@@ -0,0 +1,175 @@
1
+ import type * as Expression from "../internal/scalar.js"
2
+ import { ColumnTypeId, type AnyColumnDefinition } from "../internal/column-state.js"
3
+ import * as BaseTable from "../internal/table.js"
4
+
5
+ type Dialect = "sqlite"
6
+
7
+ type DialectColumn = AnyColumnDefinition & {
8
+ readonly [ColumnTypeId]: {
9
+ readonly dbType: Expression.DbType.Any & { readonly dialect: Dialect }
10
+ }
11
+ }
12
+
13
+ type DialectFieldMap = Record<string, DialectColumn>
14
+
15
+ type InlinePrimaryKeyKeys<Fields extends DialectFieldMap> = Extract<{
16
+ [K in keyof Fields]: Fields[K]["metadata"]["primaryKey"] extends true ? K : never
17
+ }[keyof Fields], string>
18
+
19
+ export type TableDefinition<
20
+ Name extends string,
21
+ Fields extends DialectFieldMap,
22
+ PrimaryKeyColumns extends keyof Fields & string = InlinePrimaryKeyKeys<Fields>,
23
+ Kind extends "schema" | "alias" = "schema",
24
+ SchemaName extends string | undefined = undefined
25
+ > = BaseTable.TableDefinition<Name, Fields, PrimaryKeyColumns, Kind, SchemaName>
26
+
27
+ export type TableClassStatic<
28
+ Name extends string,
29
+ Fields extends DialectFieldMap,
30
+ PrimaryKeyColumns extends keyof Fields & string = InlinePrimaryKeyKeys<Fields>,
31
+ SchemaName extends string | undefined = undefined
32
+ > = BaseTable.TableClassStatic<Name, Fields, PrimaryKeyColumns, SchemaName>
33
+
34
+ export type AnyTable = BaseTable.AnyTable<Dialect>
35
+
36
+ type FieldsOfTable<Table extends BaseTable.AnyTable> = Table[typeof BaseTable.TypeId]["fields"] extends infer Fields extends DialectFieldMap
37
+ ? Fields
38
+ : never
39
+
40
+ type PrimaryKeyOfTable<Table extends BaseTable.AnyTable> = Table[typeof BaseTable.TypeId]["primaryKey"][number]
41
+
42
+ type SchemaNameOfTable<Table extends BaseTable.AnyTable> = Table[typeof BaseTable.TypeId]["schemaName"]
43
+
44
+ type ApplySchemaTableOptions<
45
+ Name extends string,
46
+ Fields extends DialectFieldMap,
47
+ PrimaryKeyColumns extends keyof Fields & string,
48
+ SchemaName extends string,
49
+ Options extends BaseTable.DeclaredTableOptions
50
+ > = BaseTable.ApplyDeclaredOptions<
51
+ BaseTable.TableDefinition<Name, Fields, PrimaryKeyColumns, "schema", SchemaName>,
52
+ Options
53
+ > extends BaseTable.TableDefinition<any, any, infer AppliedPrimaryKeyColumns extends keyof Fields & string, "schema", any>
54
+ ? TableDefinition<Name, Fields, AppliedPrimaryKeyColumns, "schema", SchemaName>
55
+ : TableDefinition<Name, Fields, PrimaryKeyColumns, "schema", SchemaName>
56
+
57
+ export type TableSchemaNamespace<SchemaName extends string> = {
58
+ readonly schemaName: SchemaName
59
+ readonly table: <
60
+ Name extends string,
61
+ Fields extends DialectFieldMap,
62
+ const Options extends BaseTable.DeclaredTableOptions,
63
+ PrimaryKeyColumns extends keyof Fields & string = InlinePrimaryKeyKeys<Fields>
64
+ >(
65
+ name: Name,
66
+ fields: Fields,
67
+ ...options: Options & BaseTable.ValidateDeclaredOptions<BaseTable.TableDefinition<Name, Fields, PrimaryKeyColumns, "schema", SchemaName>, Options>
68
+ ) => ApplySchemaTableOptions<Name, Fields, PrimaryKeyColumns, SchemaName, Options>
69
+ }
70
+
71
+ export type TableOption = BaseTable.TableOption
72
+
73
+ export const TypeId = BaseTable.TypeId
74
+ export const OptionsSymbol = BaseTable.OptionsSymbol
75
+ export const options = BaseTable.options
76
+
77
+ export const make = <
78
+ Name extends string,
79
+ Fields extends DialectFieldMap,
80
+ SchemaName extends string | undefined = undefined
81
+ >(
82
+ name: Name,
83
+ fields: Fields,
84
+ schemaName: SchemaName = undefined as SchemaName
85
+ ): TableDefinition<Name, Fields> =>
86
+ BaseTable.make(name, fields, schemaName) as TableDefinition<Name, Fields>
87
+
88
+ export const schema = <SchemaName extends string>(
89
+ schemaName: SchemaName
90
+ ): TableSchemaNamespace<SchemaName> => {
91
+ const table = <
92
+ Name extends string,
93
+ Fields extends DialectFieldMap,
94
+ const Options extends BaseTable.DeclaredTableOptions,
95
+ PrimaryKeyColumns extends keyof Fields & string = InlinePrimaryKeyKeys<Fields>
96
+ >(
97
+ name: Name,
98
+ fields: Fields,
99
+ ...declaredOptions: Options & BaseTable.ValidateDeclaredOptions<BaseTable.TableDefinition<Name, Fields, PrimaryKeyColumns, "schema", SchemaName>, Options>
100
+ ) =>
101
+ (BaseTable.schema(schemaName).table as (
102
+ name: Name,
103
+ fields: Fields,
104
+ ...options: BaseTable.DeclaredTableOptions
105
+ ) => BaseTable.TableDefinition<any, any, any, "schema", any>)(
106
+ name,
107
+ fields,
108
+ ...declaredOptions
109
+ ) as ApplySchemaTableOptions<Name, Fields, PrimaryKeyColumns, SchemaName, Options>
110
+ return {
111
+ schemaName,
112
+ table
113
+ } as unknown as TableSchemaNamespace<SchemaName>
114
+ }
115
+
116
+ export const alias = <
117
+ Table extends AnyTable,
118
+ AliasName extends string
119
+ >(
120
+ table: Table,
121
+ aliasName: AliasName
122
+ ): TableDefinition<
123
+ AliasName,
124
+ FieldsOfTable<Table>,
125
+ PrimaryKeyOfTable<Table>,
126
+ "alias",
127
+ SchemaNameOfTable<Table>
128
+ > =>
129
+ BaseTable.alias(table as any, aliasName) as TableDefinition<
130
+ AliasName,
131
+ FieldsOfTable<Table>,
132
+ PrimaryKeyOfTable<Table>,
133
+ "alias",
134
+ SchemaNameOfTable<Table>
135
+ >
136
+
137
+ export const Class = <Self = never, SchemaName extends string | undefined = undefined>(
138
+ name: string,
139
+ schemaName: SchemaName = undefined as SchemaName
140
+ ) => {
141
+ const base = BaseTable.Class<Self, SchemaName>(name, schemaName)
142
+ return base as unknown as <
143
+ Fields extends DialectFieldMap
144
+ >(fields: Fields) => [Self] extends [never]
145
+ ? BaseTable.MissingSelfGeneric
146
+ : TableClassStatic<typeof name, Fields, InlinePrimaryKeyKeys<Fields>, SchemaName>
147
+ }
148
+
149
+ export const primaryKey = BaseTable.primaryKey
150
+ export const unique = BaseTable.unique
151
+ export const index = BaseTable.index
152
+ export const foreignKey = <
153
+ LocalColumns extends string | readonly string[],
154
+ TargetTable extends AnyTable,
155
+ TargetColumns extends string | readonly string[]
156
+ >(
157
+ columns: LocalColumns & BaseTable.NonEmptyColumnInput<LocalColumns>,
158
+ target: () => TargetTable,
159
+ referencedColumns: TargetColumns & BaseTable.NonEmptyColumnInput<TargetColumns> & BaseTable.MatchingColumnArityInput<LocalColumns, TargetColumns>
160
+ ) =>
161
+ BaseTable.foreignKey<LocalColumns, TargetTable, TargetColumns>(
162
+ columns as LocalColumns & BaseTable.NonEmptyColumnInput<LocalColumns>,
163
+ target,
164
+ referencedColumns as TargetColumns & BaseTable.NonEmptyColumnInput<TargetColumns> & BaseTable.MatchingColumnArityInput<LocalColumns, TargetColumns>
165
+ )
166
+
167
+ export const check = BaseTable.check
168
+
169
+ export const selectSchema = BaseTable.selectSchema
170
+ export const insertSchema = BaseTable.insertSchema
171
+ export const updateSchema = BaseTable.updateSchema
172
+
173
+ export type SelectOf<Table extends AnyTable> = BaseTable.SelectOf<Table>
174
+ export type InsertOf<Table extends AnyTable> = BaseTable.InsertOf<Table>
175
+ export type UpdateOf<Table extends AnyTable> = BaseTable.UpdateOf<Table>
package/src/sqlite.ts ADDED
@@ -0,0 +1,22 @@
1
+ /** SQLite-specialized column-definition DSL. */
2
+ export * as Column from "./sqlite/column.js"
3
+ /** SQLite datatype witnesses and coercion families. */
4
+ export * as Datatypes from "./sqlite/datatypes/index.js"
5
+ /** SQLite error catalog and error normalization helpers. */
6
+ export * as Errors from "./sqlite/errors/index.js"
7
+ /** Shared scalar SQL interfaces and DB-type descriptors. */
8
+ export * as Scalar from "./internal/scalar.js"
9
+ /** SQLite-specialized SQL function expressions. */
10
+ export * as Function from "./sqlite/function/index.js"
11
+ /** SQLite-specialized JSON expression helpers. */
12
+ export * as Json from "./sqlite/json.js"
13
+ /** SQLite-specialized typed query execution contracts. */
14
+ export * as Executor from "./sqlite/executor.js"
15
+ /** Shared logical row-set interfaces. */
16
+ export * as RowSet from "./internal/row-set.js"
17
+ /** SQLite-specialized query-construction DSL. */
18
+ export * as Query from "./sqlite/query.js"
19
+ /** SQLite-specialized table-definition DSL. */
20
+ export * as Table from "./sqlite/table.js"
21
+ /** SQLite-specialized built-in renderer entrypoint. */
22
+ export * as Renderer from "./sqlite/renderer.js"