effect-qb 0.13.0 → 0.15.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.
- package/README.md +6 -1431
- package/dist/mysql.js +61945 -3611
- package/dist/postgres/metadata.js +2818 -0
- package/dist/postgres.js +9942 -5591
- package/package.json +21 -10
- package/src/internal/aggregation-validation.ts +3 -3
- package/src/internal/case-analysis.d.ts +18 -0
- package/src/internal/case-analysis.ts +4 -4
- package/src/internal/coercion/analysis.d.ts +7 -0
- package/src/internal/{coercion-analysis.ts → coercion/analysis.ts} +3 -3
- package/src/internal/coercion/errors.d.ts +17 -0
- package/src/internal/{coercion-errors.ts → coercion/errors.ts} +1 -1
- package/src/internal/coercion/kind.d.ts +4 -0
- package/src/internal/{coercion-kind.ts → coercion/kind.ts} +2 -2
- package/src/internal/{coercion-normalize.ts → coercion/normalize.ts} +1 -1
- package/src/internal/coercion/rules.d.ts +6 -0
- package/src/internal/{coercion-rules.ts → coercion/rules.ts} +2 -2
- package/src/internal/column-state.d.ts +190 -0
- package/src/internal/column-state.ts +119 -56
- package/src/internal/column.ts +387 -149
- package/src/internal/datatypes/define.d.ts +17 -0
- package/src/internal/datatypes/define.ts +18 -34
- package/src/internal/datatypes/lookup.d.ts +44 -0
- package/src/internal/datatypes/lookup.ts +61 -152
- package/src/internal/datatypes/shape.d.ts +16 -0
- package/src/internal/datatypes/shape.ts +1 -1
- package/src/internal/derived-table.d.ts +4 -0
- package/src/internal/derived-table.ts +21 -16
- package/src/internal/dsl-mutation-runtime.ts +378 -0
- package/src/internal/dsl-plan-runtime.ts +387 -0
- package/src/internal/dsl-query-runtime.ts +160 -0
- package/src/internal/dsl-transaction-ddl-runtime.ts +263 -0
- package/src/internal/executor.ts +173 -38
- package/src/internal/expression-ast.ts +19 -5
- package/src/internal/grouping-key.d.ts +3 -0
- package/src/internal/grouping-key.ts +1 -1
- package/src/internal/implication-runtime.d.ts +15 -0
- package/src/internal/implication-runtime.ts +171 -0
- package/src/internal/json/ast.d.ts +30 -0
- package/src/internal/json/ast.ts +1 -1
- package/src/internal/json/errors.d.ts +8 -0
- package/src/internal/json/path.d.ts +75 -0
- package/src/internal/json/path.ts +1 -1
- package/src/internal/json/types.d.ts +62 -0
- package/src/internal/predicate/analysis.d.ts +20 -0
- package/src/internal/{predicate-analysis.ts → predicate/analysis.ts} +13 -3
- package/src/internal/predicate/atom.d.ts +28 -0
- package/src/internal/{predicate-branches.ts → predicate/branches.ts} +2 -2
- package/src/internal/predicate/context.d.ts +67 -0
- package/src/internal/{predicate-context.ts → predicate/context.ts} +111 -32
- package/src/internal/predicate/formula.d.ts +35 -0
- package/src/internal/{predicate-formula.ts → predicate/formula.ts} +32 -20
- package/src/internal/predicate/key.d.ts +11 -0
- package/src/internal/{predicate-key.ts → predicate/key.ts} +2 -2
- package/src/internal/{predicate-nnf.ts → predicate/nnf.ts} +2 -2
- package/src/internal/predicate/normalize.d.ts +53 -0
- package/src/internal/predicate/normalize.ts +273 -0
- package/src/internal/predicate/runtime.d.ts +31 -0
- package/src/internal/predicate/runtime.ts +679 -0
- package/src/internal/projection-alias.d.ts +13 -0
- package/src/internal/projections.d.ts +31 -0
- package/src/internal/projections.ts +1 -1
- package/src/internal/query-ast.d.ts +217 -0
- package/src/internal/query-ast.ts +1 -1
- package/src/internal/query-requirements.d.ts +20 -0
- package/src/internal/query.d.ts +775 -0
- package/src/internal/query.ts +767 -275
- package/src/internal/renderer.ts +7 -21
- package/src/internal/row-set.d.ts +53 -0
- package/src/internal/{plan.ts → row-set.ts} +23 -11
- package/src/internal/{runtime-normalize.ts → runtime/normalize.ts} +9 -31
- package/src/internal/{runtime-schema.ts → runtime/schema.ts} +84 -55
- package/src/internal/runtime/value.d.ts +22 -0
- package/src/internal/{runtime-value.ts → runtime/value.ts} +2 -2
- package/src/internal/scalar.d.ts +107 -0
- package/src/internal/scalar.ts +191 -0
- package/src/internal/schema-derivation.d.ts +105 -0
- package/src/internal/schema-derivation.ts +93 -21
- package/src/internal/schema-expression.d.ts +18 -0
- package/src/internal/schema-expression.ts +75 -0
- package/src/internal/table-options.d.ts +94 -0
- package/src/internal/table-options.ts +94 -8
- package/src/internal/table.d.ts +173 -0
- package/src/internal/table.ts +135 -54
- package/src/mysql/column.ts +95 -18
- package/src/mysql/datatypes/index.ts +58 -3
- package/src/mysql/errors/generated.ts +57336 -0
- package/src/mysql/errors/index.ts +1 -0
- package/src/mysql/errors/normalize.ts +55 -53
- package/src/mysql/errors/types.ts +74 -0
- package/src/mysql/executor.ts +69 -7
- package/src/mysql/function/aggregate.ts +1 -5
- package/src/mysql/function/core.ts +1 -3
- package/src/mysql/function/index.ts +1 -1
- package/src/mysql/function/string.ts +1 -5
- package/src/mysql/function/temporal.ts +12 -15
- package/src/mysql/function/window.ts +1 -6
- package/src/{internal/mysql-dialect.ts → mysql/internal/dialect.ts} +1 -1
- package/src/mysql/internal/dsl.ts +6115 -0
- package/src/{internal/mysql-renderer.ts → mysql/internal/renderer.ts} +6 -6
- package/src/mysql/internal/sql-expression-renderer.ts +1455 -0
- package/src/mysql/json.ts +2 -0
- package/src/mysql/query.ts +111 -86
- package/src/mysql/renderer.ts +1 -1
- package/src/mysql/table.ts +1 -1
- package/src/mysql.ts +6 -4
- package/src/postgres/cast.ts +30 -0
- package/src/postgres/column.ts +178 -20
- package/src/postgres/datatypes/index.d.ts +515 -0
- package/src/postgres/datatypes/index.ts +49 -5
- package/src/postgres/datatypes/spec.d.ts +412 -0
- package/src/postgres/errors/generated.ts +2636 -0
- package/src/postgres/errors/index.ts +1 -0
- package/src/postgres/errors/normalize.ts +47 -62
- package/src/postgres/errors/types.ts +92 -34
- package/src/postgres/executor.ts +37 -5
- package/src/postgres/function/aggregate.ts +1 -5
- package/src/postgres/function/core.ts +20 -2
- package/src/postgres/function/index.ts +1 -1
- package/src/postgres/function/string.ts +1 -5
- package/src/postgres/function/temporal.ts +12 -15
- package/src/postgres/function/window.ts +1 -6
- package/src/{internal/postgres-dialect.ts → postgres/internal/dialect.ts} +1 -1
- package/src/{internal/query-factory.ts → postgres/internal/dsl.ts} +1568 -2120
- package/src/{internal/postgres-renderer.ts → postgres/internal/renderer.ts} +6 -6
- package/src/postgres/internal/schema-ddl.ts +108 -0
- package/src/postgres/internal/schema-model.ts +150 -0
- package/src/{internal → postgres/internal}/sql-expression-renderer.ts +112 -46
- package/src/postgres/json.ts +493 -0
- package/src/postgres/metadata.ts +31 -0
- package/src/postgres/query.ts +113 -86
- package/src/postgres/renderer.ts +3 -13
- package/src/postgres/schema-expression.ts +17 -0
- package/src/postgres/schema-management.ts +204 -0
- package/src/postgres/schema.ts +35 -0
- package/src/postgres/table.ts +316 -42
- package/src/postgres/type.ts +31 -0
- package/src/postgres.ts +20 -4
- package/CHANGELOG.md +0 -134
- package/src/internal/expression.ts +0 -327
- package/src/internal/predicate-normalize.ts +0 -202
- package/src/mysql/function/json.ts +0 -4
- package/src/mysql/private/query.ts +0 -13
- package/src/postgres/function/json.ts +0 -4
- package/src/postgres/private/query.ts +0 -13
- /package/src/internal/{predicate-atom.ts → predicate/atom.ts} +0 -0
package/src/postgres/table.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as Schema from "effect/Schema"
|
|
2
2
|
|
|
3
|
-
import type * as Expression from "../internal/
|
|
3
|
+
import type * as Expression from "../internal/scalar.js"
|
|
4
4
|
import { ColumnTypeId, type AnyColumnDefinition } from "../internal/column-state.js"
|
|
5
5
|
import * as BaseTable from "../internal/table.js"
|
|
6
6
|
|
|
@@ -53,20 +53,26 @@ type SchemaNameOfTable<Table> = Table extends BaseTable.TableDefinition<any, any
|
|
|
53
53
|
? SchemaName
|
|
54
54
|
: never
|
|
55
55
|
|
|
56
|
-
export type
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
>
|
|
63
|
-
name: Name,
|
|
64
|
-
fields: Fields,
|
|
65
|
-
...options: BaseTable.DeclaredTableOptions
|
|
66
|
-
) => TableDefinition<Name, Fields, PrimaryKeyColumns, "schema", SchemaName>
|
|
56
|
+
export type TableOption = BaseTable.TableOption
|
|
57
|
+
export type DdlExpressionLike = BaseTable.DdlExpressionLike
|
|
58
|
+
export type IndexKey = BaseTable.IndexKeySpec
|
|
59
|
+
export type ReferentialAction = BaseTable.ReferentialAction
|
|
60
|
+
|
|
61
|
+
type SchemaTable = {
|
|
62
|
+
readonly columns: Record<string, unknown>
|
|
67
63
|
}
|
|
68
64
|
|
|
69
|
-
|
|
65
|
+
type TableExpressionFactory<Table extends SchemaTable> = (
|
|
66
|
+
columns: Table["columns"]
|
|
67
|
+
) => DdlExpressionLike
|
|
68
|
+
|
|
69
|
+
type TableScopedOptionBuilder<
|
|
70
|
+
Table extends SchemaTable,
|
|
71
|
+
Spec extends import("../internal/table-options.js").TableOptionSpec = import("../internal/table-options.js").TableOptionSpec
|
|
72
|
+
> = {
|
|
73
|
+
(table: Table): Table
|
|
74
|
+
readonly option: Spec
|
|
75
|
+
}
|
|
70
76
|
|
|
71
77
|
export const TypeId = BaseTable.TypeId
|
|
72
78
|
export const OptionsSymbol = BaseTable.OptionsSymbol
|
|
@@ -83,26 +89,6 @@ export const make = <
|
|
|
83
89
|
): TableDefinition<Name, Fields> =>
|
|
84
90
|
BaseTable.make(name, fields, schemaName) as TableDefinition<Name, Fields>
|
|
85
91
|
|
|
86
|
-
export const schema = <SchemaName extends string>(
|
|
87
|
-
schemaName: SchemaName
|
|
88
|
-
): TableSchemaNamespace<SchemaName> => ({
|
|
89
|
-
schemaName,
|
|
90
|
-
table: <
|
|
91
|
-
Name extends string,
|
|
92
|
-
Fields extends DialectFieldMap,
|
|
93
|
-
PrimaryKeyColumns extends keyof Fields & string = InlinePrimaryKeyKeys<Fields>
|
|
94
|
-
>(
|
|
95
|
-
name: Name,
|
|
96
|
-
fields: Fields,
|
|
97
|
-
...declaredOptions: BaseTable.DeclaredTableOptions
|
|
98
|
-
) =>
|
|
99
|
-
BaseTable.schema(schemaName).table(
|
|
100
|
-
name,
|
|
101
|
-
fields,
|
|
102
|
-
...declaredOptions
|
|
103
|
-
) as TableDefinition<Name, Fields, PrimaryKeyColumns, "schema", SchemaName>
|
|
104
|
-
})
|
|
105
|
-
|
|
106
92
|
export const alias = <
|
|
107
93
|
Table extends AnyTable,
|
|
108
94
|
AliasName extends string
|
|
@@ -136,21 +122,309 @@ export const Class = <Self = never, SchemaName extends string | undefined = "pub
|
|
|
136
122
|
: TableClassStatic<typeof name, Fields, InlinePrimaryKeyKeys<Fields>, SchemaName>
|
|
137
123
|
}
|
|
138
124
|
|
|
139
|
-
export const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
125
|
+
export const option = BaseTable.option
|
|
126
|
+
|
|
127
|
+
type RichPrimaryKeyInput<Columns extends string | readonly string[]> = {
|
|
128
|
+
readonly columns: Columns
|
|
129
|
+
readonly name?: string
|
|
130
|
+
readonly deferrable?: boolean
|
|
131
|
+
readonly initiallyDeferred?: boolean
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
type RichUniqueInput<Columns extends string | readonly string[]> = {
|
|
135
|
+
readonly columns: Columns
|
|
136
|
+
readonly name?: string
|
|
137
|
+
readonly nullsNotDistinct?: boolean
|
|
138
|
+
readonly deferrable?: boolean
|
|
139
|
+
readonly initiallyDeferred?: boolean
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
type RichIndexKeyInput =
|
|
143
|
+
| {
|
|
144
|
+
readonly column: string
|
|
145
|
+
readonly order?: "asc" | "desc"
|
|
146
|
+
readonly nulls?: "first" | "last"
|
|
147
|
+
readonly operatorClass?: string
|
|
148
|
+
readonly collation?: string
|
|
149
|
+
}
|
|
150
|
+
| {
|
|
151
|
+
readonly expression: DdlExpressionLike
|
|
152
|
+
readonly order?: "asc" | "desc"
|
|
153
|
+
readonly nulls?: "first" | "last"
|
|
154
|
+
readonly operatorClass?: string
|
|
155
|
+
readonly collation?: string
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
type RichIndexInput<Columns extends string | readonly string[] = string | readonly string[]> = {
|
|
159
|
+
readonly columns?: Columns
|
|
160
|
+
readonly keys?: readonly [RichIndexKeyInput, ...RichIndexKeyInput[]]
|
|
161
|
+
readonly name?: string
|
|
162
|
+
readonly unique?: boolean
|
|
163
|
+
readonly method?: string
|
|
164
|
+
readonly include?: readonly string[]
|
|
165
|
+
readonly predicate?: DdlExpressionLike
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
type RichForeignKeyInput<
|
|
143
169
|
LocalColumns extends string | readonly string[],
|
|
144
170
|
TargetTable extends AnyTable,
|
|
145
171
|
TargetColumns extends string | readonly string[]
|
|
172
|
+
> = {
|
|
173
|
+
readonly columns: LocalColumns
|
|
174
|
+
readonly target: () => TargetTable
|
|
175
|
+
readonly referencedColumns: TargetColumns
|
|
176
|
+
readonly name?: string
|
|
177
|
+
readonly onUpdate?: ReferentialAction
|
|
178
|
+
readonly onDelete?: ReferentialAction
|
|
179
|
+
readonly deferrable?: boolean
|
|
180
|
+
readonly initiallyDeferred?: boolean
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
type RichCheckInput<Name extends string = string> = {
|
|
184
|
+
readonly name: Name
|
|
185
|
+
readonly predicate: DdlExpressionLike
|
|
186
|
+
readonly noInherit?: boolean
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const isObject = (value: unknown): value is Record<string, unknown> =>
|
|
190
|
+
typeof value === "object" && value !== null && !Array.isArray(value)
|
|
191
|
+
|
|
192
|
+
const isTableExpressionFactory = (value: unknown): value is TableExpressionFactory<SchemaTable> =>
|
|
193
|
+
typeof value === "function"
|
|
194
|
+
|
|
195
|
+
const makeTableScopedOption = <
|
|
196
|
+
Table extends SchemaTable,
|
|
197
|
+
Spec extends import("../internal/table-options.js").TableOptionSpec
|
|
198
|
+
>(
|
|
199
|
+
placeholder: Spec,
|
|
200
|
+
resolve: (table: Table) => Spec
|
|
201
|
+
): TableScopedOptionBuilder<Table, Spec> => {
|
|
202
|
+
const builder = ((table: Table) =>
|
|
203
|
+
BaseTable.option(resolve(table))(table as never)) as unknown as TableScopedOptionBuilder<Table, Spec>
|
|
204
|
+
;(builder as { option: Spec }).option = placeholder
|
|
205
|
+
return builder
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const normalizeColumns = (columns: string | readonly string[]): readonly [string, ...string[]] =>
|
|
209
|
+
(Array.isArray(columns) ? [...columns] : [columns]) as unknown as readonly [string, ...string[]]
|
|
210
|
+
|
|
211
|
+
const normalizeIndexKeys = (
|
|
212
|
+
keys: readonly [RichIndexKeyInput, ...RichIndexKeyInput[]]
|
|
213
|
+
): readonly [BaseTable.IndexKeySpec, ...BaseTable.IndexKeySpec[]] =>
|
|
214
|
+
keys.map((key) => "expression" in key
|
|
215
|
+
? {
|
|
216
|
+
kind: "expression",
|
|
217
|
+
expression: key.expression,
|
|
218
|
+
order: key.order,
|
|
219
|
+
nulls: key.nulls,
|
|
220
|
+
operatorClass: key.operatorClass,
|
|
221
|
+
collation: key.collation
|
|
222
|
+
}
|
|
223
|
+
: {
|
|
224
|
+
kind: "column",
|
|
225
|
+
column: key.column,
|
|
226
|
+
order: key.order,
|
|
227
|
+
nulls: key.nulls,
|
|
228
|
+
operatorClass: key.operatorClass,
|
|
229
|
+
collation: key.collation
|
|
230
|
+
}) as unknown as readonly [BaseTable.IndexKeySpec, ...BaseTable.IndexKeySpec[]]
|
|
231
|
+
|
|
232
|
+
export const primaryKey: {
|
|
233
|
+
<const Columns extends string | readonly string[]>(
|
|
234
|
+
columns: Columns
|
|
235
|
+
): BaseTable.TableOption<{
|
|
236
|
+
readonly kind: "primaryKey"
|
|
237
|
+
readonly columns: BaseTable.NormalizeColumns<Columns>
|
|
238
|
+
}>
|
|
239
|
+
<const Columns extends string | readonly string[]>(
|
|
240
|
+
spec: RichPrimaryKeyInput<Columns>
|
|
241
|
+
): BaseTable.TableOption
|
|
242
|
+
} = ((input: unknown) =>
|
|
243
|
+
isObject(input) && "columns" in input
|
|
244
|
+
? BaseTable.option({
|
|
245
|
+
kind: "primaryKey",
|
|
246
|
+
columns: normalizeColumns((input as RichPrimaryKeyInput<string | readonly string[]>).columns),
|
|
247
|
+
name: (input as RichPrimaryKeyInput<string | readonly string[]>).name,
|
|
248
|
+
deferrable: (input as RichPrimaryKeyInput<string | readonly string[]>).deferrable,
|
|
249
|
+
initiallyDeferred: (input as RichPrimaryKeyInput<string | readonly string[]>).initiallyDeferred
|
|
250
|
+
})
|
|
251
|
+
: BaseTable.primaryKey(input as string | readonly string[])) as never
|
|
252
|
+
|
|
253
|
+
export const unique: {
|
|
254
|
+
<const Columns extends string | readonly string[]>(
|
|
255
|
+
columns: Columns
|
|
256
|
+
): BaseTable.TableOption<{
|
|
257
|
+
readonly kind: "unique"
|
|
258
|
+
readonly columns: BaseTable.NormalizeColumns<Columns>
|
|
259
|
+
}>
|
|
260
|
+
<const Columns extends string | readonly string[]>(
|
|
261
|
+
spec: RichUniqueInput<Columns>
|
|
262
|
+
): BaseTable.TableOption
|
|
263
|
+
} = ((input: unknown) =>
|
|
264
|
+
isObject(input) && "columns" in input && ("name" in input || "nullsNotDistinct" in input || "deferrable" in input || "initiallyDeferred" in input)
|
|
265
|
+
? BaseTable.option({
|
|
266
|
+
kind: "unique",
|
|
267
|
+
columns: normalizeColumns((input as RichUniqueInput<string | readonly string[]>).columns),
|
|
268
|
+
name: (input as RichUniqueInput<string | readonly string[]>).name,
|
|
269
|
+
nullsNotDistinct: (input as RichUniqueInput<string | readonly string[]>).nullsNotDistinct,
|
|
270
|
+
deferrable: (input as RichUniqueInput<string | readonly string[]>).deferrable,
|
|
271
|
+
initiallyDeferred: (input as RichUniqueInput<string | readonly string[]>).initiallyDeferred
|
|
272
|
+
})
|
|
273
|
+
: BaseTable.unique(input as string | readonly string[])) as never
|
|
274
|
+
|
|
275
|
+
export const index: {
|
|
276
|
+
<const Columns extends string | readonly string[]>(
|
|
277
|
+
columns: Columns
|
|
278
|
+
): BaseTable.TableOption<{
|
|
279
|
+
readonly kind: "index"
|
|
280
|
+
readonly columns: BaseTable.NormalizeColumns<Columns>
|
|
281
|
+
}>
|
|
282
|
+
<Table extends SchemaTable, const Columns extends string | readonly string[]>(
|
|
283
|
+
spec: Omit<RichIndexInput<Columns>, "predicate"> & {
|
|
284
|
+
readonly predicate: TableExpressionFactory<Table>
|
|
285
|
+
}
|
|
286
|
+
): TableScopedOptionBuilder<Table, {
|
|
287
|
+
readonly kind: "index"
|
|
288
|
+
readonly columns?: BaseTable.NormalizeColumns<Columns>
|
|
289
|
+
readonly keys?: readonly [BaseTable.IndexKeySpec, ...BaseTable.IndexKeySpec[]]
|
|
290
|
+
readonly name?: string
|
|
291
|
+
readonly unique?: boolean
|
|
292
|
+
readonly method?: string
|
|
293
|
+
readonly include?: readonly string[]
|
|
294
|
+
readonly predicate?: DdlExpressionLike
|
|
295
|
+
}>
|
|
296
|
+
<const Columns extends string | readonly string[]>(
|
|
297
|
+
spec: RichIndexInput<Columns>
|
|
298
|
+
): BaseTable.TableOption
|
|
299
|
+
} = ((input: unknown) =>
|
|
300
|
+
isObject(input) && ("keys" in input || "name" in input || "unique" in input || "method" in input || "include" in input || "predicate" in input)
|
|
301
|
+
? (() => {
|
|
302
|
+
const spec = input as RichIndexInput<string | readonly string[]> & {
|
|
303
|
+
readonly predicate?: DdlExpressionLike | TableExpressionFactory<SchemaTable>
|
|
304
|
+
}
|
|
305
|
+
const predicate = spec.predicate
|
|
306
|
+
const placeholder = {
|
|
307
|
+
kind: "index" as const,
|
|
308
|
+
columns: spec.columns === undefined
|
|
309
|
+
? undefined
|
|
310
|
+
: normalizeColumns(spec.columns),
|
|
311
|
+
keys: spec.keys === undefined
|
|
312
|
+
? undefined
|
|
313
|
+
: normalizeIndexKeys(spec.keys),
|
|
314
|
+
name: spec.name,
|
|
315
|
+
unique: spec.unique,
|
|
316
|
+
method: spec.method,
|
|
317
|
+
include: spec.include,
|
|
318
|
+
predicate: predicate as unknown as DdlExpressionLike
|
|
319
|
+
}
|
|
320
|
+
return isTableExpressionFactory(predicate)
|
|
321
|
+
? makeTableScopedOption(placeholder, (table) => ({
|
|
322
|
+
...placeholder,
|
|
323
|
+
predicate: predicate(table.columns)
|
|
324
|
+
}))
|
|
325
|
+
: BaseTable.option({
|
|
326
|
+
...placeholder,
|
|
327
|
+
predicate
|
|
328
|
+
})
|
|
329
|
+
})()
|
|
330
|
+
: BaseTable.index(input as string | readonly string[])) as never
|
|
331
|
+
export const foreignKey = <
|
|
332
|
+
const LocalColumns extends string | readonly string[],
|
|
333
|
+
TargetTable extends AnyTable,
|
|
334
|
+
const TargetColumns extends string | readonly string[]
|
|
146
335
|
>(
|
|
147
|
-
|
|
148
|
-
target
|
|
149
|
-
referencedColumns
|
|
336
|
+
columnsOrSpec: LocalColumns | RichForeignKeyInput<LocalColumns, TargetTable, TargetColumns>,
|
|
337
|
+
target?: () => TargetTable,
|
|
338
|
+
referencedColumns?: TargetColumns
|
|
150
339
|
): BaseTable.TableOption =>
|
|
151
|
-
|
|
340
|
+
isObject(columnsOrSpec) && "columns" in columnsOrSpec && "target" in columnsOrSpec
|
|
341
|
+
? (() => {
|
|
342
|
+
const spec = columnsOrSpec as RichForeignKeyInput<LocalColumns, TargetTable, TargetColumns>
|
|
343
|
+
const targetTable = spec.target() as BaseTable.AnyTable
|
|
344
|
+
const targetState = targetTable[BaseTable.TypeId]
|
|
345
|
+
return BaseTable.option({
|
|
346
|
+
kind: "foreignKey",
|
|
347
|
+
columns: normalizeColumns(spec.columns),
|
|
348
|
+
name: spec.name,
|
|
349
|
+
references: () => ({
|
|
350
|
+
tableName: targetState.baseName,
|
|
351
|
+
schemaName: targetState.schemaName,
|
|
352
|
+
columns: normalizeColumns(spec.referencedColumns),
|
|
353
|
+
knownColumns: Object.keys(targetState.fields)
|
|
354
|
+
}),
|
|
355
|
+
onUpdate: spec.onUpdate,
|
|
356
|
+
onDelete: spec.onDelete,
|
|
357
|
+
deferrable: spec.deferrable,
|
|
358
|
+
initiallyDeferred: spec.initiallyDeferred
|
|
359
|
+
})
|
|
360
|
+
})()
|
|
361
|
+
: BaseTable.foreignKey(
|
|
362
|
+
columnsOrSpec as LocalColumns,
|
|
363
|
+
target as () => BaseTable.AnyTable,
|
|
364
|
+
referencedColumns as TargetColumns
|
|
365
|
+
)
|
|
152
366
|
|
|
153
|
-
export const check
|
|
367
|
+
export const check: {
|
|
368
|
+
<Name extends string>(name: Name, predicate: DdlExpressionLike): BaseTable.TableOption
|
|
369
|
+
<Name extends string, Table extends SchemaTable>(
|
|
370
|
+
name: Name,
|
|
371
|
+
predicate: TableExpressionFactory<Table>
|
|
372
|
+
): TableScopedOptionBuilder<Table, {
|
|
373
|
+
readonly kind: "check"
|
|
374
|
+
readonly name: Name
|
|
375
|
+
readonly predicate: DdlExpressionLike
|
|
376
|
+
}>
|
|
377
|
+
<Name extends string, Table extends SchemaTable>(
|
|
378
|
+
spec: Omit<RichCheckInput<Name>, "predicate"> & {
|
|
379
|
+
readonly predicate: TableExpressionFactory<Table>
|
|
380
|
+
}
|
|
381
|
+
): TableScopedOptionBuilder<Table, {
|
|
382
|
+
readonly kind: "check"
|
|
383
|
+
readonly name: Name
|
|
384
|
+
readonly predicate: DdlExpressionLike
|
|
385
|
+
readonly noInherit?: boolean
|
|
386
|
+
}>
|
|
387
|
+
<Name extends string>(spec: RichCheckInput<Name>): BaseTable.TableOption
|
|
388
|
+
} = ((nameOrSpec: string | RichCheckInput, predicate?: DdlExpressionLike) =>
|
|
389
|
+
isObject(nameOrSpec)
|
|
390
|
+
? (() => {
|
|
391
|
+
const spec = nameOrSpec as RichCheckInput & {
|
|
392
|
+
readonly predicate: DdlExpressionLike | TableExpressionFactory<SchemaTable>
|
|
393
|
+
}
|
|
394
|
+
const specPredicate = spec.predicate
|
|
395
|
+
const placeholder = {
|
|
396
|
+
kind: "check" as const,
|
|
397
|
+
name: spec.name,
|
|
398
|
+
predicate: specPredicate as unknown as DdlExpressionLike,
|
|
399
|
+
noInherit: spec.noInherit
|
|
400
|
+
}
|
|
401
|
+
return isTableExpressionFactory(specPredicate)
|
|
402
|
+
? makeTableScopedOption(placeholder, (table) => ({
|
|
403
|
+
...placeholder,
|
|
404
|
+
predicate: specPredicate(table.columns)
|
|
405
|
+
}))
|
|
406
|
+
: BaseTable.option({
|
|
407
|
+
...placeholder,
|
|
408
|
+
predicate: specPredicate
|
|
409
|
+
})
|
|
410
|
+
})()
|
|
411
|
+
: (() => {
|
|
412
|
+
const predicateOrFactory = predicate as DdlExpressionLike | TableExpressionFactory<SchemaTable>
|
|
413
|
+
const placeholder = {
|
|
414
|
+
kind: "check" as const,
|
|
415
|
+
name: nameOrSpec,
|
|
416
|
+
predicate: predicateOrFactory as unknown as DdlExpressionLike
|
|
417
|
+
}
|
|
418
|
+
return isTableExpressionFactory(predicateOrFactory)
|
|
419
|
+
? makeTableScopedOption(placeholder, (table) => ({
|
|
420
|
+
...placeholder,
|
|
421
|
+
predicate: predicateOrFactory(table.columns)
|
|
422
|
+
}))
|
|
423
|
+
: BaseTable.option({
|
|
424
|
+
...placeholder,
|
|
425
|
+
predicate: predicateOrFactory
|
|
426
|
+
})
|
|
427
|
+
})()) as never
|
|
154
428
|
|
|
155
429
|
export type SelectOf<Table extends { readonly schemas: { readonly select: Schema.Schema<any> } }> = BaseTable.SelectOf<Table>
|
|
156
430
|
export type InsertOf<Table extends { readonly schemas: { readonly insert: Schema.Schema<any> } }> = BaseTable.InsertOf<Table>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type * as Expression from "../internal/scalar.js"
|
|
2
|
+
import { postgresDatatypes } from "./datatypes/index.js"
|
|
3
|
+
import { type as postgresType } from "./internal/dsl.js"
|
|
4
|
+
|
|
5
|
+
type PostgresTypeNamespace = typeof postgresDatatypes & {
|
|
6
|
+
readonly array: <Element extends Expression.DbType.Any>(
|
|
7
|
+
element: Element
|
|
8
|
+
) => Expression.DbType.Array<"postgres", Element, `${Element["kind"]}[]`>
|
|
9
|
+
readonly range: <Kind extends string, Subtype extends Expression.DbType.Any>(
|
|
10
|
+
kind: Kind,
|
|
11
|
+
subtype: Subtype
|
|
12
|
+
) => Expression.DbType.Range<"postgres", Subtype, Kind>
|
|
13
|
+
readonly multirange: <Kind extends string, Subtype extends Expression.DbType.Any>(
|
|
14
|
+
kind: Kind,
|
|
15
|
+
subtype: Subtype
|
|
16
|
+
) => Expression.DbType.Multirange<"postgres", Subtype, Kind>
|
|
17
|
+
readonly record: <Kind extends string, Fields extends Record<string, Expression.DbType.Any>>(
|
|
18
|
+
kind: Kind,
|
|
19
|
+
fields: Fields
|
|
20
|
+
) => Expression.DbType.Composite<"postgres", Fields, Kind>
|
|
21
|
+
readonly domain: <Kind extends string, Base extends Expression.DbType.Any>(
|
|
22
|
+
kind: Kind,
|
|
23
|
+
base: Base
|
|
24
|
+
) => Expression.DbType.Domain<"postgres", Base, Kind>
|
|
25
|
+
readonly enum: <Kind extends string>(kind: Kind) => Expression.DbType.Enum<"postgres", Kind>
|
|
26
|
+
readonly set: <Kind extends string>(kind: Kind) => Expression.DbType.Set<"postgres", Kind>
|
|
27
|
+
readonly custom: <Kind extends string>(kind: Kind) => Expression.DbType.Base<"postgres", Kind>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Postgres database-type constructors for casts and typed column references. */
|
|
31
|
+
export const type: PostgresTypeNamespace = postgresType
|
package/src/postgres.ts
CHANGED
|
@@ -4,16 +4,32 @@ export * as Column from "./postgres/column.js"
|
|
|
4
4
|
export * as Datatypes from "./postgres/datatypes/index.js"
|
|
5
5
|
/** Postgres SQLSTATE catalog and error normalization helpers. */
|
|
6
6
|
export * as Errors from "./postgres/errors/index.js"
|
|
7
|
-
/** Shared scalar SQL
|
|
8
|
-
export * as
|
|
7
|
+
/** Shared scalar SQL interfaces and DB-type descriptors. */
|
|
8
|
+
export * as Scalar from "./internal/scalar.js"
|
|
9
|
+
/** Postgres cast helpers. */
|
|
10
|
+
export { cast as Cast } from "./postgres/cast.js"
|
|
9
11
|
/** Postgres-specialized SQL function expressions. */
|
|
10
12
|
export * as Function from "./postgres/function/index.js"
|
|
13
|
+
/** Postgres-specialized JSON expression helpers. */
|
|
14
|
+
export * as Json from "./postgres/json.js"
|
|
11
15
|
/** Postgres-specialized typed query execution contracts. */
|
|
12
16
|
export * as Executor from "./postgres/executor.js"
|
|
13
|
-
/** Shared logical
|
|
14
|
-
export * as
|
|
17
|
+
/** Shared logical row-set interfaces. */
|
|
18
|
+
export * as RowSet from "./internal/row-set.js"
|
|
15
19
|
/** Postgres-specialized query-construction DSL. */
|
|
16
20
|
export * as Query from "./postgres/query.js"
|
|
21
|
+
/** Postgres database-type constructors for casts and typed references. */
|
|
22
|
+
export { type as Type } from "./postgres/type.js"
|
|
23
|
+
/** Postgres normalized table/enum metadata helpers. */
|
|
24
|
+
export * as Metadata from "./postgres/metadata.js"
|
|
25
|
+
/** Postgres schema-expression helpers for DDL-only metadata. */
|
|
26
|
+
export * as SchemaExpression from "./postgres/schema-expression.js"
|
|
27
|
+
/** Postgres schema-scoped table and enum builder helpers. */
|
|
28
|
+
export { schema } from "./postgres/schema.js"
|
|
29
|
+
export type { SchemaNamespace } from "./postgres/schema.js"
|
|
30
|
+
/** Postgres enum and sequence definition helpers. */
|
|
31
|
+
export { enumType as enum, sequence } from "./postgres/schema-management.js"
|
|
32
|
+
export type { EnumDefinition, SequenceDefinition } from "./postgres/schema-management.js"
|
|
17
33
|
/** Postgres-specialized table-definition DSL. */
|
|
18
34
|
export * as Table from "./postgres/table.js"
|
|
19
35
|
/** Postgres-specialized built-in renderer entrypoint. */
|
package/CHANGELOG.md
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project are documented here.
|
|
4
|
-
|
|
5
|
-
## Unreleased
|
|
6
|
-
|
|
7
|
-
## 0.13.0 - 2026-03-23
|
|
8
|
-
|
|
9
|
-
### Breaking Changes
|
|
10
|
-
|
|
11
|
-
- feat(api)!: move json helpers under Function namespaces
|
|
12
|
-
- feat(api)!: move scalar helpers under Function namespaces
|
|
13
|
-
- feat(column)!: require expressions for default and generated
|
|
14
|
-
- fix(table)!: require expressions for check constraints
|
|
15
|
-
|
|
16
|
-
### Fixes
|
|
17
|
-
|
|
18
|
-
- fix(release): use personal git identity
|
|
19
|
-
- fix(release): fall back to release commits when tags are missing
|
|
20
|
-
|
|
21
|
-
### Docs
|
|
22
|
-
|
|
23
|
-
- docs(readme): add postgres functions and defaults note
|
|
24
|
-
- docs(readme): add shaping results imports
|
|
25
|
-
- docs(readme): restructure intro and refresh examples
|
|
26
|
-
- docs(readme): document table options and check constraints
|
|
27
|
-
|
|
28
|
-
## 0.12.3 - 2026-03-21
|
|
29
|
-
|
|
30
|
-
### Breaking Changes
|
|
31
|
-
|
|
32
|
-
- feat(query)!: add schema-free implication typing and derived tables
|
|
33
|
-
- feat(query)!: add dialect-aware coercion guards for operators
|
|
34
|
-
- feat(table)!: split postgres and mysql table namespaces
|
|
35
|
-
- feat(query)!: replace insert helpers with composable values sources
|
|
36
|
-
- feat(query)!: remove insertUnnest helper
|
|
37
|
-
- feat(api)!: remove root exports in favor of dialect entrypoints
|
|
38
|
-
- feat(api)!: move shared core modules into internal
|
|
39
|
-
- refactor(api)!: rename dialect modules to lowercase
|
|
40
|
-
- feat(api)!: remove root export map
|
|
41
|
-
- feat(query)!: simplify insert source composition
|
|
42
|
-
- feat(executor)!: simplify dialect executor construction
|
|
43
|
-
- feat(runtime)!: normalize executor outputs and enforce runtime schemas
|
|
44
|
-
- feat(query)!: replace hasDefault with default helper
|
|
45
|
-
|
|
46
|
-
### Features
|
|
47
|
-
|
|
48
|
-
- feat(mysql): add mysql errors and rename modules snake_case
|
|
49
|
-
- feat(query): add read predicate builders and rendering
|
|
50
|
-
- feat(query): add common table expressions
|
|
51
|
-
- feat(query): add mutation statements and returning
|
|
52
|
-
- feat(query): add pagination, set ops, joins, windows, and ddl
|
|
53
|
-
- feat(query): add correlated sources and statement clauses
|
|
54
|
-
- feat(query): add data-modifying ctes and transaction helper
|
|
55
|
-
- feat(executor): add savepoint helper
|
|
56
|
-
- feat(query): add remaining read predicates and simple case
|
|
57
|
-
- feat(query): expand dialect datatype witnesses and runtime mapping
|
|
58
|
-
- feat(datatypes): model broader dialect catalogs
|
|
59
|
-
- feat(datatypes): model structured types and coercion
|
|
60
|
-
- feat(json): add postgres json operators and typed manipulation
|
|
61
|
-
- feat(table): add schema-qualified table namespaces
|
|
62
|
-
- feat(query): add truncate merge and transaction statements
|
|
63
|
-
- feat(query): add insert sources and conflict helpers
|
|
64
|
-
- feat(query): add standalone sources and quantified subqueries
|
|
65
|
-
- feat(query): add distinct on support
|
|
66
|
-
- feat(query): add curried aliases and preserve literal outputs
|
|
67
|
-
- feat(query): add curried cte source helpers
|
|
68
|
-
- feat(postgres): add function namespace for typed SQL expressions
|
|
69
|
-
- feat(release): use changelog section as GitHub release body
|
|
70
|
-
|
|
71
|
-
### Fixes
|
|
72
|
-
|
|
73
|
-
- fix(integration): run Bun tests by explicit path
|
|
74
|
-
- fix(integration): extend live database timeouts
|
|
75
|
-
|
|
76
|
-
### Refactors
|
|
77
|
-
|
|
78
|
-
- refactor(datatypes): derive coercion from family specs
|
|
79
|
-
- refactor(predicate): rewrite implication analysis around a stack walk
|
|
80
|
-
- refactor(modules): use js-relative specifiers across source files
|
|
81
|
-
- refactor(modules): split public and internal surfaces
|
|
82
|
-
|
|
83
|
-
### Docs
|
|
84
|
-
|
|
85
|
-
- docs: expand README with type-safety and query return examples
|
|
86
|
-
- docs(readme): document derived tables and type-driven queries
|
|
87
|
-
- docs(readme): document extended read predicates
|
|
88
|
-
- docs(readme): document common table expressions
|
|
89
|
-
- docs(readme): document pagination, set ops, joins, windows, and ddl
|
|
90
|
-
- docs(readme): document correlated sources and statement clauses
|
|
91
|
-
- docs(readme): document data-modifying ctes and transactions
|
|
92
|
-
- docs(readme): restructure guide around type safety
|
|
93
|
-
- docs: add AGENTS instructions
|
|
94
|
-
- docs(readme): add semantic SQL hook and native-preview commands
|
|
95
|
-
- docs(readme): update package layout docs
|
|
96
|
-
- docs(readme): strengthen proof-oriented examples
|
|
97
|
-
- docs(readme): align examples with the new query surface
|
|
98
|
-
- docs(readme): show dialect mismatch at executor boundary
|
|
99
|
-
- docs(readme): fix json mutation example semantics
|
|
100
|
-
- docs(readme): make predicate narrowing example self-contained
|
|
101
|
-
- docs(readme): use pipe style in mutation examples
|
|
102
|
-
- docs(readme): document onboarding and error handling
|
|
103
|
-
- docs(readme): refresh schema integration and package usage
|
|
104
|
-
- docs(readme): use pipe style in returning examples
|
|
105
|
-
- docs(readme): align guide examples with current query api
|
|
106
|
-
- docs(readme): add npm install commands
|
|
107
|
-
|
|
108
|
-
### Tests
|
|
109
|
-
|
|
110
|
-
- test(mutations): cover json mutation compatibility
|
|
111
|
-
- test(json): add exact mutation render coverage
|
|
112
|
-
- test: harden json and type coverage
|
|
113
|
-
- test: split query coverage and centralize assertions
|
|
114
|
-
- test(json): add reusable path object coverage
|
|
115
|
-
- test(integration): add docker-backed database coverage
|
|
116
|
-
|
|
117
|
-
### Build
|
|
118
|
-
|
|
119
|
-
- build(package): define npm publish layout for 0.12.3
|
|
120
|
-
|
|
121
|
-
### CI
|
|
122
|
-
|
|
123
|
-
- ci: add github actions workflow for tests and build
|
|
124
|
-
|
|
125
|
-
### Chores
|
|
126
|
-
|
|
127
|
-
- chore(types): switch typecheck to tsgo and trim depth-heavy tests
|
|
128
|
-
|
|
129
|
-
### Other
|
|
130
|
-
|
|
131
|
-
- Bootstrap effect-db with typed SQL core and dialect renderers
|
|
132
|
-
- Rename package to effect-qb and tighten query type semantics
|
|
133
|
-
- Implement predicate analysis and Postgres error normalization
|
|
134
|
-
|