effect-qb 0.12.3 → 0.14.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 (65) hide show
  1. package/README.md +6 -1283
  2. package/dist/mysql.js +6376 -4978
  3. package/dist/postgres/metadata.js +2724 -0
  4. package/dist/postgres.js +5475 -3636
  5. package/package.json +13 -8
  6. package/src/internal/column-state.ts +88 -6
  7. package/src/internal/column.ts +569 -34
  8. package/src/internal/datatypes/define.ts +0 -30
  9. package/src/internal/executor.ts +45 -11
  10. package/src/internal/expression-ast.ts +15 -0
  11. package/src/internal/expression.ts +3 -1
  12. package/src/internal/implication-runtime.ts +171 -0
  13. package/src/internal/mysql-query.ts +7173 -0
  14. package/src/internal/mysql-renderer.ts +2 -2
  15. package/src/internal/plan.ts +14 -4
  16. package/src/internal/{query-factory.ts → postgres-query.ts} +669 -230
  17. package/src/internal/postgres-renderer.ts +2 -2
  18. package/src/internal/postgres-schema-model.ts +144 -0
  19. package/src/internal/predicate-analysis.ts +10 -0
  20. package/src/internal/predicate-context.ts +112 -36
  21. package/src/internal/predicate-formula.ts +31 -19
  22. package/src/internal/predicate-normalize.ts +177 -106
  23. package/src/internal/predicate-runtime.ts +676 -0
  24. package/src/internal/query.ts +471 -41
  25. package/src/internal/renderer.ts +2 -2
  26. package/src/internal/runtime-schema.ts +74 -20
  27. package/src/internal/schema-ddl.ts +55 -0
  28. package/src/internal/schema-derivation.ts +93 -21
  29. package/src/internal/schema-expression.ts +44 -0
  30. package/src/internal/sql-expression-renderer.ts +123 -35
  31. package/src/internal/table-options.ts +88 -7
  32. package/src/internal/table.ts +106 -42
  33. package/src/mysql/column.ts +3 -1
  34. package/src/mysql/datatypes/index.ts +17 -2
  35. package/src/mysql/executor.ts +20 -17
  36. package/src/mysql/function/aggregate.ts +6 -0
  37. package/src/mysql/function/core.ts +5 -0
  38. package/src/mysql/function/index.ts +20 -0
  39. package/src/mysql/function/json.ts +4 -0
  40. package/src/mysql/function/string.ts +6 -0
  41. package/src/mysql/function/temporal.ts +103 -0
  42. package/src/mysql/function/window.ts +7 -0
  43. package/src/mysql/private/query.ts +1 -0
  44. package/src/mysql/query.ts +6 -26
  45. package/src/mysql.ts +2 -0
  46. package/src/postgres/cast.ts +31 -0
  47. package/src/postgres/column.ts +27 -1
  48. package/src/postgres/datatypes/index.ts +40 -5
  49. package/src/postgres/executor.ts +19 -17
  50. package/src/postgres/function/aggregate.ts +6 -0
  51. package/src/postgres/function/core.ts +16 -0
  52. package/src/postgres/function/index.ts +20 -0
  53. package/src/postgres/function/json.ts +501 -0
  54. package/src/postgres/function/string.ts +6 -0
  55. package/src/postgres/function/temporal.ts +107 -0
  56. package/src/postgres/function/window.ts +7 -0
  57. package/src/postgres/metadata.ts +31 -0
  58. package/src/postgres/private/query.ts +1 -0
  59. package/src/postgres/query.ts +6 -28
  60. package/src/postgres/schema-expression.ts +16 -0
  61. package/src/postgres/schema-management.ts +204 -0
  62. package/src/postgres/schema.ts +35 -0
  63. package/src/postgres/table.ts +307 -41
  64. package/src/postgres/type.ts +4 -0
  65. package/src/postgres.ts +16 -0
@@ -1,5 +1,4 @@
1
- import * as Expression from "../internal/expression.js"
2
- import { postgresDatatypes } from "./datatypes/index.js"
1
+ import { postgresQuery } from "./private/query.js"
3
2
  import {
4
3
  type CapabilitiesOfPlan,
5
4
  type CompletePlan,
@@ -37,22 +36,9 @@ import {
37
36
  type StatementOfPlan,
38
37
  type StringExpressionInput
39
38
  } from "../internal/query.js"
40
- import { makeDialectQuery } from "../internal/query-factory.js"
41
-
42
- const postgresQuery = makeDialectQuery({
43
- dialect: "postgres",
44
- textDb: { dialect: "postgres", kind: "text" } as Expression.DbType.PgText,
45
- numericDb: { dialect: "postgres", kind: "float8" } as Expression.DbType.PgFloat8,
46
- boolDb: { dialect: "postgres", kind: "bool" } as Expression.DbType.PgBool,
47
- timestampDb: { dialect: "postgres", kind: "timestamp" } as Expression.DbType.PgTimestamp,
48
- nullDb: { dialect: "postgres", kind: "null" } as Expression.DbType.Base<"postgres", "null">,
49
- type: postgresDatatypes
50
- })
51
39
 
52
40
  export const literal = postgresQuery.literal
53
- export const cast = postgresQuery.cast
54
- export const type = postgresQuery.type
55
- export const json = postgresQuery.json
41
+ export const column = postgresQuery.column
56
42
  export const eq = postgresQuery.eq
57
43
  export const neq = postgresQuery.neq
58
44
  export const lt = postgresQuery.lt
@@ -61,10 +47,12 @@ export const gt = postgresQuery.gt
61
47
  export const gte = postgresQuery.gte
62
48
  export const isNull = postgresQuery.isNull
63
49
  export const isNotNull = postgresQuery.isNotNull
64
- export const upper = postgresQuery.upper
65
- export const lower = postgresQuery.lower
66
50
  export const like = postgresQuery.like
67
51
  export const ilike = postgresQuery.ilike
52
+ export const regexMatch = postgresQuery.regexMatch
53
+ export const regexIMatch = postgresQuery.regexIMatch
54
+ export const regexNotMatch = postgresQuery.regexNotMatch
55
+ export const regexNotIMatch = postgresQuery.regexNotIMatch
68
56
  export const and = postgresQuery.and
69
57
  export const or = postgresQuery.or
70
58
  export const not = postgresQuery.not
@@ -72,22 +60,13 @@ export const all = postgresQuery.all
72
60
  export const any = postgresQuery.any
73
61
  const case_ = postgresQuery.case
74
62
  export const match = postgresQuery.match
75
- export const coalesce = postgresQuery.coalesce
76
63
  export const in_ = postgresQuery.in
77
64
  export const notIn = postgresQuery.notIn
78
65
  export const between = postgresQuery.between
79
66
  export const contains = postgresQuery.contains
80
67
  export const containedBy = postgresQuery.containedBy
81
68
  export const overlaps = postgresQuery.overlaps
82
- export const concat = postgresQuery.concat
83
69
  export const exists = postgresQuery.exists
84
- export const over = postgresQuery.over
85
- export const rowNumber = postgresQuery.rowNumber
86
- export const rank = postgresQuery.rank
87
- export const denseRank = postgresQuery.denseRank
88
- export const count = postgresQuery.count
89
- export const max = postgresQuery.max
90
- export const min = postgresQuery.min
91
70
  export const isDistinctFrom = postgresQuery.isDistinctFrom
92
71
  export const isNotDistinctFrom = postgresQuery.isNotDistinctFrom
93
72
  export const excluded = postgresQuery.excluded
@@ -103,7 +82,6 @@ export const values = postgresQuery.values
103
82
  export const unnest = postgresQuery.unnest
104
83
  export const generateSeries = postgresQuery.generateSeries
105
84
  export const returning = postgresQuery.returning
106
- export const defaultValues = postgresQuery.defaultValues
107
85
  export const onConflict = postgresQuery.onConflict
108
86
  export const insert = postgresQuery.insert
109
87
  export const update = postgresQuery.update
@@ -0,0 +1,16 @@
1
+ export {
2
+ TypeId,
3
+ fromAst,
4
+ isSchemaExpression,
5
+ normalize,
6
+ parseExpression,
7
+ render,
8
+ toAst,
9
+ type Any,
10
+ type SchemaExpression
11
+ } from "../internal/schema-expression.js"
12
+
13
+ export {
14
+ normalizeDdlExpressionSql,
15
+ renderDdlExpressionSql
16
+ } from "../internal/schema-ddl.js"
@@ -0,0 +1,204 @@
1
+ import * as Schema from "effect/Schema"
2
+ import { pipeArguments, type Pipeable } from "effect/Pipeable"
3
+
4
+ import type * as Expression from "../internal/expression.js"
5
+ import { makeColumnDefinition, type ColumnDefinition } from "../internal/column-state.js"
6
+
7
+ export const EnumTypeId: unique symbol = Symbol.for("effect-qb/SchemaManagement/Enum")
8
+ export const SequenceTypeId: unique symbol = Symbol.for("effect-qb/SchemaManagement/Sequence")
9
+
10
+ type QualifiedName<
11
+ Name extends string,
12
+ SchemaName extends string | undefined
13
+ > = SchemaName extends string
14
+ ? SchemaName extends "public"
15
+ ? Name
16
+ : `${SchemaName}.${Name}`
17
+ : Name
18
+
19
+ type EnumColumn<
20
+ Name extends string,
21
+ Values extends readonly [string, ...string[]],
22
+ SchemaName extends string | undefined
23
+ > = ColumnDefinition<
24
+ Values[number],
25
+ Values[number],
26
+ Values[number],
27
+ Expression.DbType.Enum<"postgres", QualifiedName<Name, SchemaName>>,
28
+ false,
29
+ false,
30
+ false,
31
+ false,
32
+ false,
33
+ undefined
34
+ >
35
+
36
+ const EnumProto = {
37
+ pipe(this: unknown) {
38
+ return pipeArguments(this, arguments)
39
+ },
40
+ qualifiedName(this: EnumDefinition) {
41
+ return this.schemaName === undefined || this.schemaName === "public"
42
+ ? this.name
43
+ : `${this.schemaName}.${this.name}`
44
+ },
45
+ type(this: EnumDefinition) {
46
+ return {
47
+ dialect: "postgres",
48
+ kind: this.qualifiedName(),
49
+ variant: "enum"
50
+ }
51
+ },
52
+ column(this: EnumDefinition) {
53
+ const values = this.values.map((value) => Schema.Literal(value)) as unknown as readonly [Schema.Schema.Any, ...Schema.Schema.Any[]]
54
+ return makeColumnDefinition(
55
+ values.length === 1 ? values[0]! : Schema.Union(...values),
56
+ {
57
+ dbType: this.type(),
58
+ nullable: false,
59
+ hasDefault: false,
60
+ generated: false,
61
+ primaryKey: false,
62
+ unique: false,
63
+ references: undefined,
64
+ ddlType: this.qualifiedName(),
65
+ identity: undefined,
66
+ enum: {
67
+ name: this.name,
68
+ schemaName: this.schemaName,
69
+ values: this.values
70
+ }
71
+ }
72
+ )
73
+ }
74
+ }
75
+
76
+ const SequenceProto = {
77
+ pipe(this: unknown) {
78
+ return pipeArguments(this, arguments)
79
+ },
80
+ qualifiedName(this: SequenceDefinition) {
81
+ return this.schemaName === undefined || this.schemaName === "public"
82
+ ? this.name
83
+ : `${this.schemaName}.${this.name}`
84
+ }
85
+ }
86
+
87
+ export interface EnumDefinition<
88
+ Name extends string = string,
89
+ Values extends readonly [string, ...string[]] = readonly [string, ...string[]],
90
+ SchemaName extends string | undefined = undefined
91
+ > extends Pipeable {
92
+ readonly name: Name
93
+ readonly values: Values
94
+ readonly schemaName: SchemaName
95
+ readonly [EnumTypeId]: {
96
+ readonly kind: "enum"
97
+ readonly name: Name
98
+ readonly values: Values
99
+ readonly schemaName: SchemaName
100
+ }
101
+ readonly qualifiedName: () => QualifiedName<Name, SchemaName>
102
+ readonly type: () => Expression.DbType.Enum<"postgres", QualifiedName<Name, SchemaName>>
103
+ readonly column: () => EnumColumn<Name, Values, SchemaName>
104
+ }
105
+
106
+ export interface SequenceDefinition<
107
+ Name extends string = string,
108
+ SchemaName extends string | undefined = undefined
109
+ > extends Pipeable {
110
+ readonly name: Name
111
+ readonly schemaName: SchemaName
112
+ readonly [SequenceTypeId]: {
113
+ readonly kind: "sequence"
114
+ readonly name: Name
115
+ readonly schemaName: SchemaName
116
+ }
117
+ readonly qualifiedName: () => QualifiedName<Name, SchemaName>
118
+ }
119
+
120
+ export type AnyEnumDefinition = EnumDefinition<string, readonly [string, ...string[]], string | undefined>
121
+ export type AnySequenceDefinition = SequenceDefinition<string, string | undefined>
122
+ export type AnyDefinition = AnyEnumDefinition | AnySequenceDefinition
123
+
124
+ export function enumType<
125
+ Name extends string,
126
+ const Values extends readonly [string, ...string[]]
127
+ >(
128
+ name: Name,
129
+ values: Values
130
+ ): EnumDefinition<Name, Values, undefined>
131
+ export function enumType<
132
+ Name extends string,
133
+ const Values extends readonly [string, ...string[]],
134
+ SchemaName extends string
135
+ >(
136
+ name: Name,
137
+ values: Values,
138
+ schemaName: SchemaName
139
+ ): EnumDefinition<Name, Values, SchemaName>
140
+ export function enumType(
141
+ name: string,
142
+ values: readonly [string, ...string[]],
143
+ schemaName?: string
144
+ ): EnumDefinition<string, readonly [string, ...string[]], string | undefined> {
145
+ const definition = Object.create(EnumProto)
146
+ definition.name = name
147
+ definition.values = values
148
+ definition.schemaName = schemaName
149
+ definition[EnumTypeId] = {
150
+ kind: "enum",
151
+ name,
152
+ values,
153
+ schemaName
154
+ }
155
+ return definition
156
+ }
157
+
158
+ export function sequence<Name extends string>(
159
+ name: Name
160
+ ): SequenceDefinition<Name, undefined>
161
+ export function sequence<Name extends string, SchemaName extends string>(
162
+ name: Name,
163
+ schemaName: SchemaName
164
+ ): SequenceDefinition<Name, SchemaName>
165
+ export function sequence(
166
+ name: string,
167
+ schemaName?: string
168
+ ): SequenceDefinition<string, string | undefined> {
169
+ const definition = Object.create(SequenceProto)
170
+ definition.name = name
171
+ definition.schemaName = schemaName
172
+ definition[SequenceTypeId] = {
173
+ kind: "sequence",
174
+ name,
175
+ schemaName
176
+ }
177
+ return definition
178
+ }
179
+
180
+ export const schema = <SchemaName extends string>(
181
+ schemaName: SchemaName
182
+ ) => ({
183
+ schemaName,
184
+ enumType: <
185
+ Name extends string,
186
+ const Values extends readonly [string, ...string[]]
187
+ >(
188
+ name: Name,
189
+ values: Values
190
+ ): EnumDefinition<Name, Values, SchemaName> =>
191
+ enumType(name, values, schemaName) as EnumDefinition<Name, Values, SchemaName>,
192
+ sequence: <
193
+ Name extends string
194
+ >(
195
+ name: Name
196
+ ): SequenceDefinition<Name, SchemaName> =>
197
+ sequence(name, schemaName) as SequenceDefinition<Name, SchemaName>
198
+ })
199
+
200
+ export const isEnumDefinition = (value: unknown): value is AnyEnumDefinition =>
201
+ typeof value === "object" && value !== null && EnumTypeId in value
202
+
203
+ export const isSequenceDefinition = (value: unknown): value is AnySequenceDefinition =>
204
+ typeof value === "object" && value !== null && SequenceTypeId in value
@@ -0,0 +1,35 @@
1
+ import { schema as makeTableSchemaNamespace, type TableSchemaNamespace } from "../internal/table.js"
2
+ import { enumType, sequence, type EnumDefinition, type SequenceDefinition } from "./schema-management.js"
3
+
4
+ export type SchemaNamespace<SchemaName extends string> = TableSchemaNamespace<SchemaName> & {
5
+ readonly enum: <
6
+ Name extends string,
7
+ const Values extends readonly [string, ...string[]]
8
+ >(
9
+ name: Name,
10
+ values: Values
11
+ ) => EnumDefinition<Name, Values, SchemaName>
12
+ readonly sequence: <
13
+ Name extends string
14
+ >(
15
+ name: Name
16
+ ) => SequenceDefinition<Name, SchemaName>
17
+ }
18
+
19
+ export const schema = <SchemaName extends string>(
20
+ schemaName: SchemaName
21
+ ): SchemaNamespace<SchemaName> => ({
22
+ ...makeTableSchemaNamespace(schemaName),
23
+ enum: <
24
+ Name extends string,
25
+ const Values extends readonly [string, ...string[]]
26
+ >(
27
+ name: Name,
28
+ values: Values
29
+ ) => enumType(name, values, schemaName) as EnumDefinition<Name, Values, SchemaName>,
30
+ sequence: <
31
+ Name extends string
32
+ >(
33
+ name: Name
34
+ ) => sequence(name, schemaName) as SequenceDefinition<Name, SchemaName>
35
+ })