effect-qb 0.15.0 → 0.17.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 (88) hide show
  1. package/dist/mysql.js +1957 -595
  2. package/dist/postgres/metadata.js +2507 -182
  3. package/dist/postgres.js +9587 -8201
  4. package/dist/sqlite.js +8360 -0
  5. package/package.json +7 -2
  6. package/src/internal/column-state.ts +7 -0
  7. package/src/internal/column.ts +22 -0
  8. package/src/internal/derived-table.ts +29 -3
  9. package/src/internal/dialect.ts +14 -1
  10. package/src/internal/dsl-mutation-runtime.ts +173 -4
  11. package/src/internal/dsl-plan-runtime.ts +165 -20
  12. package/src/internal/dsl-query-runtime.ts +60 -6
  13. package/src/internal/dsl-transaction-ddl-runtime.ts +72 -2
  14. package/src/internal/executor.ts +62 -13
  15. package/src/internal/expression-ast.ts +3 -2
  16. package/src/internal/grouping-key.ts +141 -1
  17. package/src/internal/implication-runtime.ts +2 -1
  18. package/src/internal/json/types.ts +155 -40
  19. package/src/internal/predicate/analysis.ts +103 -1
  20. package/src/internal/predicate/atom.ts +7 -0
  21. package/src/internal/predicate/context.ts +170 -17
  22. package/src/internal/predicate/key.ts +64 -2
  23. package/src/internal/predicate/normalize.ts +115 -34
  24. package/src/internal/predicate/runtime.ts +144 -13
  25. package/src/internal/query.ts +563 -103
  26. package/src/internal/renderer.ts +39 -2
  27. package/src/internal/runtime/driver-value-mapping.ts +244 -0
  28. package/src/internal/runtime/normalize.ts +62 -38
  29. package/src/internal/runtime/schema.ts +5 -3
  30. package/src/internal/runtime/value.ts +153 -30
  31. package/src/internal/scalar.ts +11 -0
  32. package/src/internal/table-options.ts +108 -1
  33. package/src/internal/table.ts +87 -29
  34. package/src/mysql/column.ts +19 -2
  35. package/src/mysql/datatypes/index.ts +21 -0
  36. package/src/mysql/errors/catalog.ts +5 -5
  37. package/src/mysql/errors/normalize.ts +2 -2
  38. package/src/mysql/executor.ts +20 -5
  39. package/src/mysql/internal/dialect.ts +12 -6
  40. package/src/mysql/internal/dsl.ts +995 -263
  41. package/src/mysql/internal/renderer.ts +13 -3
  42. package/src/mysql/internal/sql-expression-renderer.ts +530 -128
  43. package/src/mysql/query.ts +9 -2
  44. package/src/mysql/renderer.ts +7 -2
  45. package/src/mysql/table.ts +38 -12
  46. package/src/postgres/cast.ts +22 -7
  47. package/src/postgres/column.ts +5 -2
  48. package/src/postgres/errors/normalize.ts +2 -2
  49. package/src/postgres/executor.ts +68 -10
  50. package/src/postgres/function/core.ts +19 -1
  51. package/src/postgres/internal/dialect.ts +12 -6
  52. package/src/postgres/internal/dsl.ts +958 -288
  53. package/src/postgres/internal/renderer.ts +13 -3
  54. package/src/postgres/internal/schema-ddl.ts +2 -1
  55. package/src/postgres/internal/schema-model.ts +6 -3
  56. package/src/postgres/internal/sql-expression-renderer.ts +477 -96
  57. package/src/postgres/json.ts +57 -17
  58. package/src/postgres/query.ts +9 -2
  59. package/src/postgres/renderer.ts +7 -2
  60. package/src/postgres/schema-management.ts +91 -4
  61. package/src/postgres/schema.ts +1 -1
  62. package/src/postgres/table.ts +189 -53
  63. package/src/postgres/type.ts +4 -0
  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 +6926 -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 +183 -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,183 @@
1
+ import type * as Schema from "effect/Schema"
2
+
3
+ import type * as Expression from "../internal/scalar.js"
4
+ import { ColumnTypeId, type AnyColumnDefinition } from "../internal/column-state.js"
5
+ import * as BaseTable from "../internal/table.js"
6
+
7
+ type Dialect = "sqlite"
8
+
9
+ type DialectColumn = AnyColumnDefinition & {
10
+ readonly [ColumnTypeId]: {
11
+ readonly dbType: Expression.DbType.Any & { readonly dialect: Dialect }
12
+ }
13
+ }
14
+
15
+ type DialectFieldMap = Record<string, DialectColumn>
16
+
17
+ type InlinePrimaryKeyKeys<Fields extends DialectFieldMap> = Extract<{
18
+ [K in keyof Fields]: Fields[K]["metadata"]["primaryKey"] extends true ? K : never
19
+ }[keyof Fields], string>
20
+
21
+ export type TableDefinition<
22
+ Name extends string,
23
+ Fields extends DialectFieldMap,
24
+ PrimaryKeyColumns extends keyof Fields & string = InlinePrimaryKeyKeys<Fields>,
25
+ Kind extends "schema" | "alias" = "schema",
26
+ SchemaName extends string | undefined = undefined
27
+ > = BaseTable.TableDefinition<Name, Fields, PrimaryKeyColumns, Kind, SchemaName>
28
+
29
+ export type TableClassStatic<
30
+ Name extends string,
31
+ Fields extends DialectFieldMap,
32
+ PrimaryKeyColumns extends keyof Fields & string = InlinePrimaryKeyKeys<Fields>,
33
+ SchemaName extends string | undefined = undefined
34
+ > = BaseTable.TableClassStatic<Name, Fields, PrimaryKeyColumns, SchemaName>
35
+
36
+ export type AnyTable = BaseTable.AnyTable
37
+
38
+ type FieldsOfTable<Table> = Table extends BaseTable.TableDefinition<any, infer Fields extends DialectFieldMap, any, any, any>
39
+ ? Fields
40
+ : Table extends BaseTable.TableClassStatic<any, infer Fields extends DialectFieldMap, any, any>
41
+ ? Fields
42
+ : never
43
+
44
+ type PrimaryKeyOfTable<Table> = Table extends BaseTable.TableDefinition<any, any, infer PrimaryKeyColumns extends string, any, any>
45
+ ? PrimaryKeyColumns
46
+ : Table extends BaseTable.TableClassStatic<any, any, infer PrimaryKeyColumns extends string, any>
47
+ ? PrimaryKeyColumns
48
+ : never
49
+
50
+ type SchemaNameOfTable<Table> = Table extends BaseTable.TableDefinition<any, any, any, any, infer SchemaName>
51
+ ? SchemaName
52
+ : Table extends BaseTable.TableClassStatic<any, any, any, infer SchemaName>
53
+ ? SchemaName
54
+ : never
55
+
56
+ type ApplySchemaTableOptions<
57
+ Name extends string,
58
+ Fields extends DialectFieldMap,
59
+ PrimaryKeyColumns extends keyof Fields & string,
60
+ SchemaName extends string,
61
+ Options extends BaseTable.DeclaredTableOptions
62
+ > = BaseTable.ApplyDeclaredOptions<
63
+ BaseTable.TableDefinition<Name, Fields, PrimaryKeyColumns, "schema", SchemaName>,
64
+ Options
65
+ > extends BaseTable.TableDefinition<any, any, infer AppliedPrimaryKeyColumns extends keyof Fields & string, "schema", any>
66
+ ? TableDefinition<Name, Fields, AppliedPrimaryKeyColumns, "schema", SchemaName>
67
+ : TableDefinition<Name, Fields, PrimaryKeyColumns, "schema", SchemaName>
68
+
69
+ export type TableSchemaNamespace<SchemaName extends string> = {
70
+ readonly schemaName: SchemaName
71
+ readonly table: <
72
+ Name extends string,
73
+ Fields extends DialectFieldMap,
74
+ const Options extends BaseTable.DeclaredTableOptions,
75
+ PrimaryKeyColumns extends keyof Fields & string = InlinePrimaryKeyKeys<Fields>
76
+ >(
77
+ name: Name,
78
+ fields: Fields,
79
+ ...options: Options & BaseTable.ValidateDeclaredOptions<BaseTable.TableDefinition<Name, Fields, PrimaryKeyColumns, "schema", SchemaName>, Options>
80
+ ) => ApplySchemaTableOptions<Name, Fields, PrimaryKeyColumns, SchemaName, Options>
81
+ }
82
+
83
+ export type TableOption = BaseTable.TableOption
84
+
85
+ export const TypeId = BaseTable.TypeId
86
+ export const OptionsSymbol = BaseTable.OptionsSymbol
87
+ export const options = BaseTable.options
88
+
89
+ export const make = <
90
+ Name extends string,
91
+ Fields extends DialectFieldMap,
92
+ SchemaName extends string | undefined = undefined
93
+ >(
94
+ name: Name,
95
+ fields: Fields,
96
+ schemaName: SchemaName = undefined as SchemaName
97
+ ): TableDefinition<Name, Fields> =>
98
+ BaseTable.make(name, fields, schemaName) as TableDefinition<Name, Fields>
99
+
100
+ export const schema = <SchemaName extends string>(
101
+ schemaName: SchemaName
102
+ ): TableSchemaNamespace<SchemaName> => {
103
+ const table = <
104
+ Name extends string,
105
+ Fields extends DialectFieldMap,
106
+ const Options extends BaseTable.DeclaredTableOptions,
107
+ PrimaryKeyColumns extends keyof Fields & string = InlinePrimaryKeyKeys<Fields>
108
+ >(
109
+ name: Name,
110
+ fields: Fields,
111
+ ...declaredOptions: Options & BaseTable.ValidateDeclaredOptions<BaseTable.TableDefinition<Name, Fields, PrimaryKeyColumns, "schema", SchemaName>, Options>
112
+ ) =>
113
+ (BaseTable.schema(schemaName).table as (
114
+ name: Name,
115
+ fields: Fields,
116
+ ...options: BaseTable.DeclaredTableOptions
117
+ ) => BaseTable.TableDefinition<any, any, any, "schema", any>)(
118
+ name,
119
+ fields,
120
+ ...declaredOptions
121
+ ) as ApplySchemaTableOptions<Name, Fields, PrimaryKeyColumns, SchemaName, Options>
122
+ return {
123
+ schemaName,
124
+ table
125
+ } as unknown as TableSchemaNamespace<SchemaName>
126
+ }
127
+
128
+ export const alias = <
129
+ Table extends AnyTable,
130
+ AliasName extends string
131
+ >(
132
+ table: Table,
133
+ aliasName: AliasName
134
+ ): TableDefinition<
135
+ AliasName,
136
+ FieldsOfTable<Table>,
137
+ PrimaryKeyOfTable<Table>,
138
+ "alias",
139
+ SchemaNameOfTable<Table>
140
+ > =>
141
+ BaseTable.alias(table as any, aliasName) as TableDefinition<
142
+ AliasName,
143
+ FieldsOfTable<Table>,
144
+ PrimaryKeyOfTable<Table>,
145
+ "alias",
146
+ SchemaNameOfTable<Table>
147
+ >
148
+
149
+ export const Class = <Self = never, SchemaName extends string | undefined = undefined>(
150
+ name: string,
151
+ schemaName: SchemaName = undefined as SchemaName
152
+ ) => {
153
+ const base = BaseTable.Class<Self, SchemaName>(name, schemaName)
154
+ return base as unknown as <
155
+ Fields extends DialectFieldMap
156
+ >(fields: Fields) => [Self] extends [never]
157
+ ? BaseTable.MissingSelfGeneric
158
+ : TableClassStatic<typeof name, Fields, InlinePrimaryKeyKeys<Fields>, SchemaName>
159
+ }
160
+
161
+ export const primaryKey = BaseTable.primaryKey
162
+ export const unique = BaseTable.unique
163
+ export const index = BaseTable.index
164
+ export const foreignKey = <
165
+ LocalColumns extends string | readonly string[],
166
+ TargetTable extends AnyTable,
167
+ TargetColumns extends string | readonly string[]
168
+ >(
169
+ columns: LocalColumns & BaseTable.NonEmptyColumnInput<LocalColumns>,
170
+ target: () => TargetTable,
171
+ referencedColumns: TargetColumns & BaseTable.NonEmptyColumnInput<TargetColumns> & BaseTable.MatchingColumnArityInput<LocalColumns, TargetColumns>
172
+ ): BaseTable.TableOption =>
173
+ BaseTable.foreignKey<LocalColumns, BaseTable.AnyTable, TargetColumns>(
174
+ columns as LocalColumns & BaseTable.NonEmptyColumnInput<LocalColumns>,
175
+ target as () => BaseTable.AnyTable,
176
+ referencedColumns as TargetColumns & BaseTable.NonEmptyColumnInput<TargetColumns> & BaseTable.MatchingColumnArityInput<LocalColumns, TargetColumns>
177
+ )
178
+
179
+ export const check = BaseTable.check
180
+
181
+ export type SelectOf<Table extends { readonly schemas: { readonly select: Schema.Schema<any> } }> = BaseTable.SelectOf<Table>
182
+ export type InsertOf<Table extends { readonly schemas: { readonly insert: Schema.Schema<any> } }> = BaseTable.InsertOf<Table>
183
+ export type UpdateOf<Table extends { readonly schemas: { readonly update: Schema.Schema<any> } }> = 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"