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
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import type * as Brand from "effect/Brand"
|
|
1
2
|
import { pipeArguments, type Pipeable } from "effect/Pipeable"
|
|
2
3
|
import * as Schema from "effect/Schema"
|
|
3
4
|
|
|
4
|
-
import * as Expression from "./
|
|
5
|
+
import * as Expression from "./scalar.js"
|
|
5
6
|
import * as ExpressionAst from "./expression-ast.js"
|
|
7
|
+
import type * as SchemaExpression from "./schema-expression.js"
|
|
6
8
|
|
|
7
9
|
/** Symbol used to attach column-definition metadata. */
|
|
8
10
|
export const ColumnTypeId: unique symbol = Symbol.for("effect-qb/Column")
|
|
@@ -12,9 +14,36 @@ export const BoundColumnTypeId: unique symbol = Symbol.for("effect-qb/BoundColum
|
|
|
12
14
|
export type ColumnTypeId = typeof ColumnTypeId
|
|
13
15
|
export type BoundColumnTypeId = typeof BoundColumnTypeId
|
|
14
16
|
|
|
17
|
+
export type DdlExpression = Expression.Any | SchemaExpression.Any
|
|
18
|
+
|
|
15
19
|
/** Lazy reference to another bound column. */
|
|
16
20
|
export interface ColumnReference<Target = unknown> {
|
|
17
21
|
readonly target: () => Target
|
|
22
|
+
readonly name?: string
|
|
23
|
+
readonly onUpdate?: "noAction" | "restrict" | "cascade" | "setNull" | "setDefault"
|
|
24
|
+
readonly onDelete?: "noAction" | "restrict" | "cascade" | "setNull" | "setDefault"
|
|
25
|
+
readonly deferrable?: boolean
|
|
26
|
+
readonly initiallyDeferred?: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Inline single-column index metadata. */
|
|
30
|
+
export interface ColumnIndexOptions {
|
|
31
|
+
readonly name?: string
|
|
32
|
+
readonly method?: string
|
|
33
|
+
readonly include?: readonly string[]
|
|
34
|
+
readonly predicate?: DdlExpression
|
|
35
|
+
readonly order?: "asc" | "desc"
|
|
36
|
+
readonly nulls?: "first" | "last"
|
|
37
|
+
readonly operatorClass?: string
|
|
38
|
+
readonly collation?: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Inline single-column unique-constraint metadata. */
|
|
42
|
+
export interface ColumnUniqueOptions {
|
|
43
|
+
readonly name?: string
|
|
44
|
+
readonly nullsNotDistinct?: boolean
|
|
45
|
+
readonly deferrable?: boolean
|
|
46
|
+
readonly initiallyDeferred?: boolean
|
|
18
47
|
}
|
|
19
48
|
|
|
20
49
|
/** Complete static state tracked for a column definition. */
|
|
@@ -29,8 +58,7 @@ export interface ColumnState<
|
|
|
29
58
|
PrimaryKey extends boolean,
|
|
30
59
|
Unique extends boolean,
|
|
31
60
|
Ref,
|
|
32
|
-
|
|
33
|
-
Dependencies extends Expression.SourceDependencies = {}
|
|
61
|
+
Dependencies extends Expression.BindingId = never
|
|
34
62
|
> {
|
|
35
63
|
readonly select: Select
|
|
36
64
|
readonly insert: Insert
|
|
@@ -42,10 +70,21 @@ export interface ColumnState<
|
|
|
42
70
|
readonly primaryKey: PrimaryKey
|
|
43
71
|
readonly unique: Unique
|
|
44
72
|
readonly references: Ref
|
|
45
|
-
readonly
|
|
46
|
-
readonly
|
|
47
|
-
readonly
|
|
48
|
-
readonly
|
|
73
|
+
readonly brand?: true
|
|
74
|
+
readonly index?: ColumnIndexOptions
|
|
75
|
+
readonly uniqueConstraint?: ColumnUniqueOptions
|
|
76
|
+
readonly defaultValue?: DdlExpression
|
|
77
|
+
readonly generatedValue?: DdlExpression
|
|
78
|
+
readonly ddlType?: string
|
|
79
|
+
readonly identity?: {
|
|
80
|
+
readonly generation: "always" | "byDefault"
|
|
81
|
+
}
|
|
82
|
+
readonly enum?: {
|
|
83
|
+
readonly name: string
|
|
84
|
+
readonly schemaName?: string
|
|
85
|
+
readonly values: readonly [string, ...string[]]
|
|
86
|
+
}
|
|
87
|
+
readonly dependencies?: Dependencies
|
|
49
88
|
}
|
|
50
89
|
|
|
51
90
|
/** Unbound column definition produced by the `Column` DSL. */
|
|
@@ -60,15 +99,13 @@ export interface ColumnDefinition<
|
|
|
60
99
|
PrimaryKey extends boolean,
|
|
61
100
|
Unique extends boolean,
|
|
62
101
|
Ref,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
> extends Pipeable, Expression.Expression<
|
|
102
|
+
Dependencies extends Expression.BindingId = never
|
|
103
|
+
> extends Pipeable, Expression.Scalar<
|
|
66
104
|
Select,
|
|
67
105
|
Db,
|
|
68
106
|
Nullable extends true ? "maybe" : "never",
|
|
69
107
|
Db["dialect"],
|
|
70
108
|
"scalar",
|
|
71
|
-
Source,
|
|
72
109
|
Dependencies
|
|
73
110
|
> {
|
|
74
111
|
readonly pipe: Pipeable["pipe"]
|
|
@@ -83,7 +120,6 @@ export interface ColumnDefinition<
|
|
|
83
120
|
PrimaryKey,
|
|
84
121
|
Unique,
|
|
85
122
|
Ref,
|
|
86
|
-
Source,
|
|
87
123
|
Dependencies
|
|
88
124
|
>
|
|
89
125
|
readonly schema: Schema.Schema<NonNullable<Select>, any, any>
|
|
@@ -95,8 +131,20 @@ export interface ColumnDefinition<
|
|
|
95
131
|
readonly primaryKey: PrimaryKey
|
|
96
132
|
readonly unique: Unique
|
|
97
133
|
readonly references: Ref
|
|
98
|
-
readonly
|
|
99
|
-
readonly
|
|
134
|
+
readonly brand?: true
|
|
135
|
+
readonly index?: ColumnIndexOptions
|
|
136
|
+
readonly uniqueConstraint?: ColumnUniqueOptions
|
|
137
|
+
readonly defaultValue?: DdlExpression
|
|
138
|
+
readonly generatedValue?: DdlExpression
|
|
139
|
+
readonly ddlType?: string
|
|
140
|
+
readonly identity?: {
|
|
141
|
+
readonly generation: "always" | "byDefault"
|
|
142
|
+
}
|
|
143
|
+
readonly enum?: {
|
|
144
|
+
readonly name: string
|
|
145
|
+
readonly schemaName?: string
|
|
146
|
+
readonly values: readonly [string, ...string[]]
|
|
147
|
+
}
|
|
100
148
|
}
|
|
101
149
|
}
|
|
102
150
|
|
|
@@ -110,11 +158,11 @@ export interface BoundColumn<
|
|
|
110
158
|
HasDefault extends boolean,
|
|
111
159
|
Generated extends boolean,
|
|
112
160
|
PrimaryKey extends boolean,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
161
|
+
Unique extends boolean,
|
|
162
|
+
Ref,
|
|
163
|
+
TableName extends string,
|
|
164
|
+
ColumnName extends string,
|
|
165
|
+
BaseTableName extends string = TableName
|
|
118
166
|
> extends ColumnDefinition<
|
|
119
167
|
Select,
|
|
120
168
|
Insert,
|
|
@@ -126,8 +174,7 @@ export interface BoundColumn<
|
|
|
126
174
|
PrimaryKey,
|
|
127
175
|
Unique,
|
|
128
176
|
Ref,
|
|
129
|
-
|
|
130
|
-
Record<TableName, true>
|
|
177
|
+
TableName
|
|
131
178
|
> {
|
|
132
179
|
readonly [BoundColumnTypeId]: {
|
|
133
180
|
readonly tableName: TableName
|
|
@@ -141,9 +188,7 @@ export interface BoundColumn<
|
|
|
141
188
|
Nullable extends true ? "maybe" : "never",
|
|
142
189
|
Db["dialect"],
|
|
143
190
|
"scalar",
|
|
144
|
-
|
|
145
|
-
Record<TableName, true>,
|
|
146
|
-
"propagate"
|
|
191
|
+
TableName
|
|
147
192
|
>
|
|
148
193
|
readonly [ExpressionAst.TypeId]: ExpressionAst.ColumnNode<TableName, ColumnName>
|
|
149
194
|
}
|
|
@@ -175,6 +220,7 @@ export type AnyBoundColumn = BoundColumn<
|
|
|
175
220
|
boolean,
|
|
176
221
|
any,
|
|
177
222
|
string,
|
|
223
|
+
string,
|
|
178
224
|
string
|
|
179
225
|
>
|
|
180
226
|
|
|
@@ -184,6 +230,17 @@ const ColumnProto = {
|
|
|
184
230
|
}
|
|
185
231
|
}
|
|
186
232
|
|
|
233
|
+
const attachPipe = <Value extends object>(value: Value): Value => {
|
|
234
|
+
Object.defineProperty(value, "pipe", {
|
|
235
|
+
configurable: true,
|
|
236
|
+
writable: true,
|
|
237
|
+
value: function(this: unknown) {
|
|
238
|
+
return pipeArguments(value, arguments)
|
|
239
|
+
}
|
|
240
|
+
})
|
|
241
|
+
return value
|
|
242
|
+
}
|
|
243
|
+
|
|
187
244
|
/** Constructs a runtime column-definition object from schema and metadata. */
|
|
188
245
|
export const makeColumnDefinition = <
|
|
189
246
|
Select,
|
|
@@ -196,8 +253,7 @@ export const makeColumnDefinition = <
|
|
|
196
253
|
PrimaryKey extends boolean,
|
|
197
254
|
Unique extends boolean,
|
|
198
255
|
Ref,
|
|
199
|
-
|
|
200
|
-
Dependencies extends Expression.SourceDependencies = {}
|
|
256
|
+
Dependencies extends Expression.BindingId = never
|
|
201
257
|
>(
|
|
202
258
|
schema: Schema.Schema<NonNullable<Select>, any, any>,
|
|
203
259
|
metadata: ColumnDefinition<
|
|
@@ -211,7 +267,6 @@ export const makeColumnDefinition = <
|
|
|
211
267
|
PrimaryKey,
|
|
212
268
|
Unique,
|
|
213
269
|
Ref,
|
|
214
|
-
Source,
|
|
215
270
|
Dependencies
|
|
216
271
|
>["metadata"]
|
|
217
272
|
): ColumnDefinition<
|
|
@@ -225,10 +280,9 @@ export const makeColumnDefinition = <
|
|
|
225
280
|
PrimaryKey,
|
|
226
281
|
Unique,
|
|
227
282
|
Ref,
|
|
228
|
-
Source,
|
|
229
283
|
Dependencies
|
|
230
284
|
> => {
|
|
231
|
-
const column = Object.create(ColumnProto)
|
|
285
|
+
const column = attachPipe(Object.create(ColumnProto))
|
|
232
286
|
column.schema = schema
|
|
233
287
|
column.metadata = metadata
|
|
234
288
|
column[Expression.TypeId] = {
|
|
@@ -237,10 +291,8 @@ export const makeColumnDefinition = <
|
|
|
237
291
|
runtimeSchema: schema,
|
|
238
292
|
nullability: (metadata.nullable ? "maybe" : "never") as Nullable extends true ? "maybe" : "never",
|
|
239
293
|
dialect: metadata.dbType.dialect,
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
sourceNullability: "propagate" as const,
|
|
243
|
-
dependencies: {} as Dependencies
|
|
294
|
+
kind: "scalar",
|
|
295
|
+
dependencies: {}
|
|
244
296
|
}
|
|
245
297
|
column[ColumnTypeId] = {
|
|
246
298
|
select: undefined as Select,
|
|
@@ -255,8 +307,9 @@ export const makeColumnDefinition = <
|
|
|
255
307
|
references: metadata.references,
|
|
256
308
|
defaultValue: metadata.defaultValue,
|
|
257
309
|
generatedValue: metadata.generatedValue,
|
|
258
|
-
|
|
259
|
-
|
|
310
|
+
ddlType: metadata.ddlType,
|
|
311
|
+
identity: metadata.identity,
|
|
312
|
+
enum: metadata.enum
|
|
260
313
|
}
|
|
261
314
|
return column
|
|
262
315
|
}
|
|
@@ -272,8 +325,7 @@ export const remapColumnDefinition = <
|
|
|
272
325
|
PrimaryKey extends boolean,
|
|
273
326
|
Unique extends boolean,
|
|
274
327
|
Ref,
|
|
275
|
-
|
|
276
|
-
Dependencies extends Expression.SourceDependencies = {}
|
|
328
|
+
Dependencies extends Expression.BindingId = never
|
|
277
329
|
>(
|
|
278
330
|
column: ColumnDefinition<
|
|
279
331
|
Select,
|
|
@@ -286,7 +338,6 @@ export const remapColumnDefinition = <
|
|
|
286
338
|
PrimaryKey,
|
|
287
339
|
Unique,
|
|
288
340
|
Ref,
|
|
289
|
-
Source,
|
|
290
341
|
Dependencies
|
|
291
342
|
>,
|
|
292
343
|
options: {
|
|
@@ -302,7 +353,6 @@ export const remapColumnDefinition = <
|
|
|
302
353
|
PrimaryKey,
|
|
303
354
|
Unique,
|
|
304
355
|
Ref,
|
|
305
|
-
Source,
|
|
306
356
|
Dependencies
|
|
307
357
|
>["metadata"]
|
|
308
358
|
} = {}
|
|
@@ -317,12 +367,11 @@ export const remapColumnDefinition = <
|
|
|
317
367
|
PrimaryKey,
|
|
318
368
|
Unique,
|
|
319
369
|
Ref,
|
|
320
|
-
Source,
|
|
321
370
|
Dependencies
|
|
322
371
|
> => {
|
|
323
372
|
const schema = options.schema ?? column.schema
|
|
324
373
|
const metadata = options.metadata ?? column.metadata
|
|
325
|
-
const next = Object.create(ColumnProto)
|
|
374
|
+
const next = attachPipe(Object.create(ColumnProto))
|
|
326
375
|
next.schema = schema
|
|
327
376
|
next.metadata = metadata
|
|
328
377
|
next[Expression.TypeId] = {
|
|
@@ -346,7 +395,10 @@ export const remapColumnDefinition = <
|
|
|
346
395
|
unique: metadata.unique,
|
|
347
396
|
references: metadata.references,
|
|
348
397
|
defaultValue: metadata.defaultValue,
|
|
349
|
-
generatedValue: metadata.generatedValue
|
|
398
|
+
generatedValue: metadata.generatedValue,
|
|
399
|
+
ddlType: metadata.ddlType,
|
|
400
|
+
identity: metadata.identity,
|
|
401
|
+
enum: metadata.enum
|
|
350
402
|
}
|
|
351
403
|
if (ExpressionAst.TypeId in column) {
|
|
352
404
|
next[ExpressionAst.TypeId] = (column as unknown as {
|
|
@@ -380,25 +432,23 @@ export const bindColumn = <
|
|
|
380
432
|
baseTableName: BaseTableName,
|
|
381
433
|
schemaName?: SchemaName
|
|
382
434
|
): BoundColumnFrom<Column, TableName, ColumnName, BaseTableName> => {
|
|
383
|
-
const
|
|
384
|
-
|
|
435
|
+
const brandName = `${tableName}.${columnName}`
|
|
436
|
+
const schema = column.metadata.brand === true
|
|
437
|
+
? Schema.brand(brandName)(column.schema)
|
|
438
|
+
: column.schema
|
|
439
|
+
const bound = attachPipe(Object.create(ColumnProto))
|
|
440
|
+
bound.schema = schema
|
|
385
441
|
bound.metadata = column.metadata
|
|
386
442
|
bound[Expression.TypeId] = {
|
|
387
443
|
runtime: undefined as SelectType<Column>,
|
|
388
444
|
dbType: column.metadata.dbType,
|
|
389
|
-
runtimeSchema:
|
|
445
|
+
runtimeSchema: schema,
|
|
390
446
|
nullability: (column.metadata.nullable ? "maybe" : "never") as IsNullable<Column> extends true ? "maybe" : "never",
|
|
391
447
|
dialect: column.metadata.dbType.dialect,
|
|
392
|
-
|
|
393
|
-
source: {
|
|
394
|
-
tableName,
|
|
395
|
-
columnName,
|
|
396
|
-
baseTableName
|
|
397
|
-
},
|
|
398
|
-
sourceNullability: "propagate" as const,
|
|
448
|
+
kind: "scalar",
|
|
399
449
|
dependencies: {
|
|
400
450
|
[tableName]: true
|
|
401
|
-
}
|
|
451
|
+
}
|
|
402
452
|
}
|
|
403
453
|
bound[ExpressionAst.TypeId] = {
|
|
404
454
|
kind: "column",
|
|
@@ -438,6 +488,13 @@ export type ReferencesOf<Column extends AnyColumnDefinition> = ColumnStateOf<Col
|
|
|
438
488
|
/** Extracts the non-null select type of a column. */
|
|
439
489
|
export type BaseSelectType<Column extends AnyColumnDefinition> = NonNullable<SelectType<Column>>
|
|
440
490
|
|
|
491
|
+
type BrandedValue<
|
|
492
|
+
Value,
|
|
493
|
+
BrandName extends string
|
|
494
|
+
> = [Extract<Value, null | undefined>] extends [never]
|
|
495
|
+
? Value & Brand.Brand<BrandName>
|
|
496
|
+
: Exclude<Value, null | undefined> & Brand.Brand<BrandName> | Extract<Value, null | undefined>
|
|
497
|
+
|
|
441
498
|
/** Rebinds a generic column definition to a specific table and key. */
|
|
442
499
|
export type BoundColumnFrom<
|
|
443
500
|
Column extends AnyColumnDefinition,
|
|
@@ -445,9 +502,15 @@ export type BoundColumnFrom<
|
|
|
445
502
|
ColumnName extends string,
|
|
446
503
|
BaseTableName extends string = TableName
|
|
447
504
|
> = BoundColumn<
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
505
|
+
Column["metadata"]["brand"] extends true
|
|
506
|
+
? BrandedValue<SelectType<Column>, `${TableName}.${ColumnName}`>
|
|
507
|
+
: SelectType<Column>,
|
|
508
|
+
Column["metadata"]["brand"] extends true
|
|
509
|
+
? BrandedValue<InsertType<Column>, `${TableName}.${ColumnName}`>
|
|
510
|
+
: InsertType<Column>,
|
|
511
|
+
Column["metadata"]["brand"] extends true
|
|
512
|
+
? BrandedValue<UpdateType<Column>, `${TableName}.${ColumnName}`>
|
|
513
|
+
: UpdateType<Column>,
|
|
451
514
|
ColumnStateOf<Column>["dbType"],
|
|
452
515
|
IsNullable<Column>,
|
|
453
516
|
HasDefault<Column>,
|