effect-qb 0.13.0 → 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.
- package/README.md +6 -1431
- package/dist/mysql.js +1678 -355
- package/dist/postgres/metadata.js +2724 -0
- package/dist/postgres.js +7197 -5433
- package/package.json +8 -10
- package/src/internal/column-state.ts +84 -10
- package/src/internal/column.ts +556 -34
- package/src/internal/datatypes/define.ts +0 -30
- package/src/internal/executor.ts +45 -11
- package/src/internal/expression-ast.ts +4 -0
- package/src/internal/expression.ts +1 -1
- package/src/internal/implication-runtime.ts +171 -0
- package/src/internal/mysql-query.ts +7173 -0
- package/src/internal/mysql-renderer.ts +2 -2
- package/src/internal/plan.ts +14 -4
- package/src/internal/{query-factory.ts → postgres-query.ts} +619 -167
- package/src/internal/postgres-renderer.ts +2 -2
- package/src/internal/postgres-schema-model.ts +144 -0
- package/src/internal/predicate-analysis.ts +10 -0
- package/src/internal/predicate-context.ts +112 -36
- package/src/internal/predicate-formula.ts +31 -19
- package/src/internal/predicate-normalize.ts +177 -106
- package/src/internal/predicate-runtime.ts +676 -0
- package/src/internal/query.ts +455 -39
- package/src/internal/renderer.ts +2 -2
- package/src/internal/runtime-schema.ts +74 -20
- package/src/internal/schema-ddl.ts +55 -0
- package/src/internal/schema-derivation.ts +93 -21
- package/src/internal/schema-expression.ts +44 -0
- package/src/internal/sql-expression-renderer.ts +95 -31
- package/src/internal/table-options.ts +87 -7
- package/src/internal/table.ts +104 -41
- package/src/mysql/column.ts +1 -0
- package/src/mysql/datatypes/index.ts +17 -2
- package/src/mysql/function/core.ts +1 -0
- package/src/mysql/function/index.ts +1 -0
- package/src/mysql/private/query.ts +1 -13
- package/src/mysql/query.ts +5 -0
- package/src/postgres/cast.ts +31 -0
- package/src/postgres/column.ts +26 -0
- package/src/postgres/datatypes/index.ts +40 -5
- package/src/postgres/function/core.ts +12 -0
- package/src/postgres/function/index.ts +2 -1
- package/src/postgres/function/json.ts +499 -2
- package/src/postgres/metadata.ts +31 -0
- package/src/postgres/private/query.ts +1 -13
- package/src/postgres/query.ts +5 -2
- package/src/postgres/schema-expression.ts +16 -0
- package/src/postgres/schema-management.ts +204 -0
- package/src/postgres/schema.ts +35 -0
- package/src/postgres/table.ts +307 -41
- package/src/postgres/type.ts +4 -0
- package/src/postgres.ts +14 -0
- package/CHANGELOG.md +0 -134
package/src/internal/table.ts
CHANGED
|
@@ -3,14 +3,17 @@ import * as Schema from "effect/Schema"
|
|
|
3
3
|
|
|
4
4
|
import * as Plan from "./plan.js"
|
|
5
5
|
import type { Any as AnyExpression } from "./expression.js"
|
|
6
|
+
import type { TrueFormula } from "./predicate-formula.js"
|
|
6
7
|
import type { BoundColumnFrom } from "./column-state.js"
|
|
7
8
|
import { bindColumn, type AnyColumnDefinition } from "./column-state.js"
|
|
8
9
|
import {
|
|
9
10
|
collectInlineOptions,
|
|
10
11
|
normalizeColumnList,
|
|
11
12
|
resolvePrimaryKeyColumns,
|
|
12
|
-
type
|
|
13
|
+
type DdlExpressionLike,
|
|
14
|
+
type IndexKeySpec,
|
|
13
15
|
type NormalizeColumns,
|
|
16
|
+
type ReferentialAction,
|
|
14
17
|
type TableOptionSpec,
|
|
15
18
|
type ValidateKnownColumns,
|
|
16
19
|
type ValidatePrimaryKeyColumns,
|
|
@@ -42,7 +45,16 @@ type TableDialect<Fields extends TableFieldMap> = Fields[keyof Fields][typeof im
|
|
|
42
45
|
type TableKind = "schema" | "alias"
|
|
43
46
|
type DefaultSchemaName = "public"
|
|
44
47
|
type ClassOptionSpec = Exclude<TableOptionSpec, { readonly kind: "primaryKey" }>
|
|
45
|
-
|
|
48
|
+
interface TableOptionBuilderLike<
|
|
49
|
+
Spec extends TableOptionSpec = TableOptionSpec
|
|
50
|
+
> {
|
|
51
|
+
(
|
|
52
|
+
table: TableDefinition<any, any, any, "schema", any>
|
|
53
|
+
): TableDefinition<any, any, any, "schema", any>
|
|
54
|
+
readonly option: Spec
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
type ClassTableOption = TableOptionBuilderLike<ClassOptionSpec>
|
|
46
58
|
type ClassDeclaredTableOptions = readonly ClassTableOption[]
|
|
47
59
|
|
|
48
60
|
type BuildPrimaryKey<
|
|
@@ -83,12 +95,13 @@ export type BoundColumns<
|
|
|
83
95
|
|
|
84
96
|
/** Derived runtime schemas exposed by a table definition. */
|
|
85
97
|
export interface TableSchemas<
|
|
98
|
+
Name extends string,
|
|
86
99
|
Fields extends TableFieldMap,
|
|
87
100
|
PrimaryKeyColumns extends keyof Fields & string
|
|
88
101
|
> {
|
|
89
|
-
readonly select: Schema.Schema<SelectRow<Fields>>
|
|
90
|
-
readonly insert: Schema.Schema<InsertRow<Fields>>
|
|
91
|
-
readonly update: Schema.Schema<UpdateRow<Fields, PrimaryKeyColumns>>
|
|
102
|
+
readonly select: Schema.Schema<SelectRow<Name, Fields>>
|
|
103
|
+
readonly insert: Schema.Schema<InsertRow<Name, Fields>>
|
|
104
|
+
readonly update: Schema.Schema<UpdateRow<Name, Fields, PrimaryKeyColumns>>
|
|
92
105
|
}
|
|
93
106
|
|
|
94
107
|
interface TableState<
|
|
@@ -116,11 +129,12 @@ export interface TableSchemaNamespace<SchemaName extends string> {
|
|
|
116
129
|
>(
|
|
117
130
|
name: Name,
|
|
118
131
|
fields: Fields,
|
|
119
|
-
...options:
|
|
132
|
+
...options: DeclaredTableOptions
|
|
120
133
|
) => TableDefinition<Name, Fields, PrimaryKeyColumns, "schema", SchemaName>
|
|
121
134
|
}
|
|
122
135
|
|
|
123
|
-
export type DeclaredTableOptions =
|
|
136
|
+
export type DeclaredTableOptions = readonly TableOptionBuilderLike[]
|
|
137
|
+
export type { DdlExpressionLike, IndexKeySpec, NormalizeColumns, ReferentialAction } from "./table-options.js"
|
|
124
138
|
|
|
125
139
|
export type TableDefinition<
|
|
126
140
|
Name extends string,
|
|
@@ -131,12 +145,12 @@ export type TableDefinition<
|
|
|
131
145
|
> = Pipeable & {
|
|
132
146
|
readonly name: Name
|
|
133
147
|
readonly columns: BoundColumns<Name, Fields>
|
|
134
|
-
readonly schemas: TableSchemas<Fields, PrimaryKeyColumns>
|
|
148
|
+
readonly schemas: TableSchemas<Name, Fields, PrimaryKeyColumns>
|
|
135
149
|
readonly [TypeId]: TableState<Name, Fields, PrimaryKeyColumns, Kind, SchemaName>
|
|
136
150
|
readonly [Plan.TypeId]: Plan.State<
|
|
137
151
|
BoundColumns<Name, Fields>,
|
|
138
152
|
never,
|
|
139
|
-
Record<Name, Plan.Source<Name>>,
|
|
153
|
+
Record<Name, Plan.Source<Name, "required", TrueFormula>>,
|
|
140
154
|
TableDialect<Fields>
|
|
141
155
|
>
|
|
142
156
|
readonly [OptionsSymbol]: readonly TableOptionSpec[]
|
|
@@ -144,7 +158,7 @@ export type TableDefinition<
|
|
|
144
158
|
} & BoundColumns<Name, Fields> & Plan.Plan<
|
|
145
159
|
BoundColumns<Name, Fields>,
|
|
146
160
|
never,
|
|
147
|
-
Record<Name, Plan.Source<Name>>,
|
|
161
|
+
Record<Name, Plan.Source<Name, "required", TrueFormula>>,
|
|
148
162
|
TableDialect<Fields>
|
|
149
163
|
>
|
|
150
164
|
|
|
@@ -161,12 +175,12 @@ export type TableClassStatic<
|
|
|
161
175
|
SchemaName extends string | undefined = DefaultSchemaName
|
|
162
176
|
> = (abstract new (...args: any[]) => any) & Pipeable & {
|
|
163
177
|
readonly columns: BoundColumns<Name, Fields>
|
|
164
|
-
readonly schemas: TableSchemas<Fields, PrimaryKeyColumns>
|
|
178
|
+
readonly schemas: TableSchemas<Name, Fields, PrimaryKeyColumns>
|
|
165
179
|
readonly [TypeId]: TableState<Name, Fields, PrimaryKeyColumns, "schema", SchemaName>
|
|
166
180
|
readonly [Plan.TypeId]: Plan.State<
|
|
167
181
|
BoundColumns<Name, Fields>,
|
|
168
182
|
never,
|
|
169
|
-
Record<Name, Plan.Source<Name>>,
|
|
183
|
+
Record<Name, Plan.Source<Name, "required", TrueFormula>>,
|
|
170
184
|
TableDialect<Fields>
|
|
171
185
|
>
|
|
172
186
|
readonly [OptionsSymbol]: readonly TableOptionSpec[]
|
|
@@ -176,7 +190,7 @@ export type TableClassStatic<
|
|
|
176
190
|
} & BoundColumns<Name, Fields> & Plan.Plan<
|
|
177
191
|
BoundColumns<Name, Fields>,
|
|
178
192
|
never,
|
|
179
|
-
Record<Name, Plan.Source<Name>>,
|
|
193
|
+
Record<Name, Plan.Source<Name, "required", TrueFormula>>,
|
|
180
194
|
TableDialect<Fields>
|
|
181
195
|
>
|
|
182
196
|
|
|
@@ -209,7 +223,7 @@ type BuildArtifacts<
|
|
|
209
223
|
PrimaryKeyColumns extends keyof Fields & string
|
|
210
224
|
> = {
|
|
211
225
|
readonly columns: BoundColumns<Name, Fields>
|
|
212
|
-
readonly schemas: TableSchemas<Fields, PrimaryKeyColumns>
|
|
226
|
+
readonly schemas: TableSchemas<Name, Fields, PrimaryKeyColumns>
|
|
213
227
|
readonly normalizedOptions: readonly TableOptionSpec[]
|
|
214
228
|
readonly primaryKey: readonly PrimaryKeyColumns[]
|
|
215
229
|
}
|
|
@@ -231,7 +245,7 @@ const buildArtifacts = <
|
|
|
231
245
|
const columns = Object.fromEntries(
|
|
232
246
|
Object.entries(fields).map(([key, column]) => [key, bindColumn(name, key, column, name, schemaName)])
|
|
233
247
|
) as BoundColumns<Name, Fields>
|
|
234
|
-
const schemas = deriveSchemas(fields, primaryKey)
|
|
248
|
+
const schemas = deriveSchemas(name, fields, primaryKey)
|
|
235
249
|
return {
|
|
236
250
|
columns,
|
|
237
251
|
schemas,
|
|
@@ -299,6 +313,21 @@ const extractDeclaredOptions = (
|
|
|
299
313
|
declaredOptions: DeclaredTableOptions | undefined
|
|
300
314
|
): readonly TableOptionSpec[] => declaredOptions?.map((option) => option.option) ?? []
|
|
301
315
|
|
|
316
|
+
const applyDeclaredOptions = <
|
|
317
|
+
Table extends TableDefinition<any, any, any, "schema", any>
|
|
318
|
+
>(
|
|
319
|
+
table: Table,
|
|
320
|
+
declaredOptions: DeclaredTableOptions | undefined
|
|
321
|
+
): Table => {
|
|
322
|
+
if (declaredOptions === undefined || declaredOptions.length === 0) {
|
|
323
|
+
return table
|
|
324
|
+
}
|
|
325
|
+
return declaredOptions.reduce<TableDefinition<any, any, any, "schema", any>>(
|
|
326
|
+
(current, option) => option(current),
|
|
327
|
+
table
|
|
328
|
+
) as unknown as Table
|
|
329
|
+
}
|
|
330
|
+
|
|
302
331
|
const validateClassOptions = (declaredOptions: readonly TableOptionSpec[]): void => {
|
|
303
332
|
for (const option of declaredOptions) {
|
|
304
333
|
if (option.kind === "primaryKey") {
|
|
@@ -340,14 +369,26 @@ const ensureClassArtifacts = <
|
|
|
340
369
|
return cached
|
|
341
370
|
}
|
|
342
371
|
const state = self[TypeId]
|
|
343
|
-
const
|
|
344
|
-
validateClassOptions(
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
372
|
+
const classOptions = self[options]
|
|
373
|
+
validateClassOptions(extractDeclaredOptions(classOptions))
|
|
374
|
+
const table = applyDeclaredOptions(
|
|
375
|
+
makeTable(
|
|
376
|
+
state.name,
|
|
377
|
+
state.fields,
|
|
378
|
+
[],
|
|
379
|
+
state.name,
|
|
380
|
+
"schema",
|
|
381
|
+
state.schemaName,
|
|
382
|
+
state.schemaName === undefined || state.schemaName === "public" ? "default" : "explicit"
|
|
383
|
+
) as TableDefinition<Name, Fields, PrimaryKeyColumns, "schema", typeof state.schemaName>,
|
|
384
|
+
classOptions
|
|
385
|
+
)
|
|
386
|
+
const artifacts = {
|
|
387
|
+
columns: table.columns,
|
|
388
|
+
schemas: table.schemas,
|
|
389
|
+
normalizedOptions: table[OptionsSymbol],
|
|
390
|
+
primaryKey: table[TypeId].primaryKey as readonly PrimaryKeyColumns[]
|
|
391
|
+
} satisfies BuildArtifacts<Name, Fields, PrimaryKeyColumns>
|
|
351
392
|
Object.defineProperty(self, CacheSymbol, {
|
|
352
393
|
configurable: true,
|
|
353
394
|
value: artifacts
|
|
@@ -384,6 +425,25 @@ const makeOption = <Spec extends TableOptionSpec>(option: Spec): TableOption<Spe
|
|
|
384
425
|
return builder
|
|
385
426
|
}
|
|
386
427
|
|
|
428
|
+
const makeResolvedOption = <Spec extends TableOptionSpec>(
|
|
429
|
+
option: Spec,
|
|
430
|
+
resolve: (table: TableDefinition<any, any, any, "schema", any>) => Spec
|
|
431
|
+
): TableOption<Spec> => {
|
|
432
|
+
const builder = ((table: TableDefinition<any, any, any, "schema", any>) =>
|
|
433
|
+
appendOption(table, resolve(table))) as unknown as TableOption<Spec>
|
|
434
|
+
;(builder as { option: Spec }).option = option
|
|
435
|
+
return builder
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export const option = <Spec extends TableOptionSpec>(spec: Spec): TableOption<Spec> =>
|
|
439
|
+
makeOption(spec)
|
|
440
|
+
|
|
441
|
+
export const optionFromTable = <Spec extends TableOptionSpec>(
|
|
442
|
+
spec: Spec,
|
|
443
|
+
resolve: (table: TableDefinition<any, any, any, "schema", any>) => Spec
|
|
444
|
+
): TableOption<Spec> =>
|
|
445
|
+
makeResolvedOption(spec, resolve)
|
|
446
|
+
|
|
387
447
|
/** Creates a table definition from a name and field map. */
|
|
388
448
|
export function make<
|
|
389
449
|
Name extends string,
|
|
@@ -422,17 +482,20 @@ export const schema = <SchemaName extends string>(
|
|
|
422
482
|
>(
|
|
423
483
|
name: Name,
|
|
424
484
|
fields: Fields,
|
|
425
|
-
...options:
|
|
485
|
+
...options: DeclaredTableOptions
|
|
426
486
|
): TableDefinition<Name, Fields, PrimaryKeyColumns, "schema", SchemaName> =>
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
487
|
+
applyDeclaredOptions(
|
|
488
|
+
makeTable(
|
|
489
|
+
name,
|
|
490
|
+
fields,
|
|
491
|
+
[],
|
|
492
|
+
name,
|
|
493
|
+
"schema",
|
|
494
|
+
schemaName,
|
|
495
|
+
"explicit"
|
|
496
|
+
) as TableDefinition<Name, Fields, PrimaryKeyColumns, "schema", SchemaName>,
|
|
497
|
+
options
|
|
498
|
+
)
|
|
436
499
|
})
|
|
437
500
|
|
|
438
501
|
/**
|
|
@@ -465,7 +528,7 @@ export const alias = <
|
|
|
465
528
|
const aliased = Object.create(TableProto)
|
|
466
529
|
aliased.name = aliasName
|
|
467
530
|
aliased.columns = columns
|
|
468
|
-
aliased.schemas =
|
|
531
|
+
aliased.schemas = deriveSchemas(aliasName, state.fields, state.primaryKey)
|
|
469
532
|
aliased[TypeId] = {
|
|
470
533
|
name: aliasName,
|
|
471
534
|
baseName: state.baseName,
|
|
@@ -581,7 +644,7 @@ export function Class<
|
|
|
581
644
|
|
|
582
645
|
/** Declares a table-level primary key. */
|
|
583
646
|
export const primaryKey = <
|
|
584
|
-
Columns extends string | readonly string[]
|
|
647
|
+
const Columns extends string | readonly string[]
|
|
585
648
|
>(
|
|
586
649
|
columns: Columns
|
|
587
650
|
): TableOption<{
|
|
@@ -594,7 +657,7 @@ export const primaryKey = <
|
|
|
594
657
|
|
|
595
658
|
/** Declares a table-level unique constraint. */
|
|
596
659
|
export const unique = <
|
|
597
|
-
Columns extends string | readonly string[]
|
|
660
|
+
const Columns extends string | readonly string[]
|
|
598
661
|
>(
|
|
599
662
|
columns: Columns
|
|
600
663
|
): TableOption<{
|
|
@@ -607,7 +670,7 @@ export const unique = <
|
|
|
607
670
|
|
|
608
671
|
/** Declares a table-level index. */
|
|
609
672
|
export const index = <
|
|
610
|
-
Columns extends string | readonly string[]
|
|
673
|
+
const Columns extends string | readonly string[]
|
|
611
674
|
>(
|
|
612
675
|
columns: Columns
|
|
613
676
|
): TableOption<{
|
|
@@ -620,9 +683,9 @@ export const index = <
|
|
|
620
683
|
|
|
621
684
|
/** Declares a table-level foreign key. */
|
|
622
685
|
export const foreignKey = <
|
|
623
|
-
LocalColumns extends string | readonly string[],
|
|
686
|
+
const LocalColumns extends string | readonly string[],
|
|
624
687
|
TargetTable extends AnyTable,
|
|
625
|
-
TargetColumns extends string | readonly string[]
|
|
688
|
+
const TargetColumns extends string | readonly string[]
|
|
626
689
|
>(
|
|
627
690
|
columns: LocalColumns,
|
|
628
691
|
target: () => TargetTable,
|
|
@@ -650,11 +713,11 @@ export const foreignKey = <
|
|
|
650
713
|
/** Declares a check constraint expression. */
|
|
651
714
|
export const check = <Name extends string>(
|
|
652
715
|
name: Name,
|
|
653
|
-
predicate:
|
|
716
|
+
predicate: DdlExpressionLike
|
|
654
717
|
): TableOption<{
|
|
655
718
|
readonly kind: "check"
|
|
656
719
|
readonly name: Name
|
|
657
|
-
readonly predicate:
|
|
720
|
+
readonly predicate: DdlExpressionLike
|
|
658
721
|
}> => makeOption({
|
|
659
722
|
kind: "check",
|
|
660
723
|
name,
|
package/src/mysql/column.ts
CHANGED
|
@@ -19,6 +19,7 @@ export const json = BaseColumn.mysql.json
|
|
|
19
19
|
export const custom = BaseColumn.mysql.custom
|
|
20
20
|
|
|
21
21
|
export const nullable = BaseColumn.nullable
|
|
22
|
+
export const brand = BaseColumn.brand
|
|
22
23
|
export const primaryKey = BaseColumn.primaryKey
|
|
23
24
|
export const unique = BaseColumn.unique
|
|
24
25
|
const default_ = BaseColumn.default_
|
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { DatatypeModule } from "../../internal/datatypes/define.js"
|
|
2
|
+
import type * as Expression from "../../internal/expression.js"
|
|
2
3
|
import { mysqlDatatypeKinds } from "./spec.js"
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
const mysqlDatatypeModule = {
|
|
6
|
+
custom: (kind: string) => ({
|
|
7
|
+
dialect: "mysql",
|
|
8
|
+
kind
|
|
9
|
+
})
|
|
10
|
+
} as Record<string, (...args: readonly any[]) => Expression.DbType.Base<"mysql", string>>
|
|
11
|
+
|
|
12
|
+
for (const kind of Object.keys(mysqlDatatypeKinds)) {
|
|
13
|
+
mysqlDatatypeModule[kind] = () => ({
|
|
14
|
+
dialect: "mysql",
|
|
15
|
+
kind
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const mysqlDatatypes = mysqlDatatypeModule as DatatypeModule<"mysql", typeof mysqlDatatypeKinds>
|
|
5
20
|
|
|
6
21
|
export type MysqlDatatypeModule = typeof mysqlDatatypes
|
|
@@ -6,6 +6,7 @@ export { json } from "./json.js"
|
|
|
6
6
|
export * as temporal from "./temporal.js"
|
|
7
7
|
|
|
8
8
|
export { coalesce } from "./core.js"
|
|
9
|
+
export { call } from "./core.js"
|
|
9
10
|
export { lower, upper, concat } from "./string.js"
|
|
10
11
|
export { count, max, min } from "./aggregate.js"
|
|
11
12
|
export { over, rowNumber, rank, denseRank } from "./window.js"
|
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { makeDialectQuery } from "../../internal/query-factory.js"
|
|
3
|
-
import { mysqlDatatypes } from "../datatypes/index.js"
|
|
4
|
-
|
|
5
|
-
export const mysqlQuery = makeDialectQuery({
|
|
6
|
-
dialect: "mysql",
|
|
7
|
-
textDb: { dialect: "mysql", kind: "text" } as Expression.DbType.MySqlText,
|
|
8
|
-
numericDb: { dialect: "mysql", kind: "double" } as Expression.DbType.MySqlDouble,
|
|
9
|
-
boolDb: { dialect: "mysql", kind: "boolean" } as Expression.DbType.MySqlBool,
|
|
10
|
-
timestampDb: { dialect: "mysql", kind: "timestamp" } as Expression.DbType.MySqlTimestamp,
|
|
11
|
-
nullDb: { dialect: "mysql", kind: "null" } as Expression.DbType.Base<"mysql", "null">,
|
|
12
|
-
type: mysqlDatatypes
|
|
13
|
-
})
|
|
1
|
+
export { mysqlQuery } from "../../internal/mysql-query.js"
|
package/src/mysql/query.ts
CHANGED
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
import { mysqlQuery } from "./private/query.js"
|
|
39
39
|
|
|
40
40
|
export const literal = mysqlQuery.literal
|
|
41
|
+
export const column = mysqlQuery.column
|
|
41
42
|
export const cast = mysqlQuery.cast
|
|
42
43
|
export const type = mysqlQuery.type
|
|
43
44
|
export const eq = mysqlQuery.eq
|
|
@@ -50,6 +51,10 @@ export const isNull = mysqlQuery.isNull
|
|
|
50
51
|
export const isNotNull = mysqlQuery.isNotNull
|
|
51
52
|
export const like = mysqlQuery.like
|
|
52
53
|
export const ilike = mysqlQuery.ilike
|
|
54
|
+
export const regexMatch = mysqlQuery.regexMatch
|
|
55
|
+
export const regexIMatch = mysqlQuery.regexIMatch
|
|
56
|
+
export const regexNotMatch = mysqlQuery.regexNotMatch
|
|
57
|
+
export const regexNotIMatch = mysqlQuery.regexNotIMatch
|
|
53
58
|
export const and = mysqlQuery.and
|
|
54
59
|
export const or = mysqlQuery.or
|
|
55
60
|
export const not = mysqlQuery.not
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type * as Expression from "../internal/expression.js"
|
|
2
|
+
import { postgresQuery } from "./private/query.js"
|
|
3
|
+
|
|
4
|
+
type CastInput = Parameters<typeof postgresQuery.cast>[0]
|
|
5
|
+
type CastTarget = Parameters<typeof postgresQuery.cast>[1]
|
|
6
|
+
type CastExpression<Target extends CastTarget> = Expression.Expression<
|
|
7
|
+
Expression.RuntimeOfDbType<Target>,
|
|
8
|
+
Target,
|
|
9
|
+
Expression.Nullability,
|
|
10
|
+
string,
|
|
11
|
+
Expression.AggregationKind,
|
|
12
|
+
any,
|
|
13
|
+
Expression.SourceDependencies,
|
|
14
|
+
Expression.SourceNullabilityMode
|
|
15
|
+
>
|
|
16
|
+
|
|
17
|
+
const to: {
|
|
18
|
+
<Value extends CastInput, Target extends CastTarget>(
|
|
19
|
+
value: Value,
|
|
20
|
+
target: Target
|
|
21
|
+
): CastExpression<Target>
|
|
22
|
+
<Target extends CastTarget>(
|
|
23
|
+
target: Target
|
|
24
|
+
): <Value extends CastInput>(value: Value) => CastExpression<Target>
|
|
25
|
+
} = ((...args: [CastInput, CastTarget] | [CastTarget]) =>
|
|
26
|
+
args.length === 1
|
|
27
|
+
? ((value: CastInput) => postgresQuery.cast(value as never, args[0] as never))
|
|
28
|
+
: postgresQuery.cast(args[0] as never, args[1] as never)) as unknown as typeof to
|
|
29
|
+
|
|
30
|
+
/** Postgres cast helpers. */
|
|
31
|
+
export const cast = { to }
|
package/src/postgres/column.ts
CHANGED
|
@@ -1,11 +1,37 @@
|
|
|
1
1
|
export {
|
|
2
|
+
brand,
|
|
3
|
+
ddlType,
|
|
4
|
+
int2,
|
|
2
5
|
boolean,
|
|
3
6
|
date,
|
|
4
7
|
default_ as default,
|
|
8
|
+
int8,
|
|
9
|
+
float4,
|
|
10
|
+
float8,
|
|
5
11
|
generated,
|
|
12
|
+
array,
|
|
13
|
+
identityAlways,
|
|
14
|
+
identityByDefault,
|
|
15
|
+
foreignKey,
|
|
16
|
+
index,
|
|
6
17
|
int,
|
|
18
|
+
char,
|
|
19
|
+
varchar,
|
|
7
20
|
json,
|
|
21
|
+
jsonb,
|
|
8
22
|
nullable,
|
|
23
|
+
time,
|
|
24
|
+
timetz,
|
|
25
|
+
timestamptz,
|
|
26
|
+
interval,
|
|
27
|
+
bytea,
|
|
28
|
+
name,
|
|
29
|
+
oid,
|
|
30
|
+
regclass,
|
|
31
|
+
bit,
|
|
32
|
+
varbit,
|
|
33
|
+
xml,
|
|
34
|
+
pg_lsn,
|
|
9
35
|
number,
|
|
10
36
|
primaryKey,
|
|
11
37
|
references,
|
|
@@ -1,8 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import type { DatatypeModule } from "../../internal/datatypes/define.js"
|
|
2
|
+
import type * as Expression from "../../internal/expression.js"
|
|
3
|
+
import { postgresDatatypeFamilies, postgresDatatypeKinds } from "./spec.js"
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const postgresDatatypeModule = {
|
|
6
|
+
custom: (kind: string) => ({
|
|
7
|
+
dialect: "postgres",
|
|
8
|
+
kind
|
|
9
|
+
}),
|
|
10
|
+
boolean: () => ({
|
|
11
|
+
dialect: "postgres",
|
|
12
|
+
kind: "bool"
|
|
13
|
+
})
|
|
14
|
+
} as Record<string, (...args: readonly any[]) => Expression.DbType.Base<"postgres", string>>
|
|
15
|
+
|
|
16
|
+
for (const kind of Object.keys(postgresDatatypeKinds)) {
|
|
17
|
+
postgresDatatypeModule[kind] = () => ({
|
|
18
|
+
dialect: "postgres",
|
|
19
|
+
kind
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const postgresDatatypes = {
|
|
24
|
+
...(postgresDatatypeModule as DatatypeModule<
|
|
25
|
+
"postgres",
|
|
26
|
+
typeof postgresDatatypeKinds,
|
|
27
|
+
{ readonly boolean: "bool" }
|
|
28
|
+
>),
|
|
29
|
+
json: (): Expression.DbType.Json<"postgres", "json"> => ({
|
|
30
|
+
dialect: "postgres",
|
|
31
|
+
kind: "json",
|
|
32
|
+
variant: "json"
|
|
33
|
+
}),
|
|
34
|
+
jsonb: (): Expression.DbType.Json<"postgres", "jsonb"> => ({
|
|
35
|
+
dialect: "postgres",
|
|
36
|
+
kind: "jsonb",
|
|
37
|
+
variant: "jsonb"
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { postgresDatatypeFamilies, postgresDatatypeKinds }
|
|
7
42
|
|
|
8
43
|
export type PostgresDatatypeModule = typeof postgresDatatypes
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
+
import type { ExpressionInput } from "../query.js"
|
|
1
2
|
import { postgresQuery } from "../private/query.js"
|
|
3
|
+
import { isSequenceDefinition, type SequenceDefinition } from "../schema-management.js"
|
|
2
4
|
|
|
3
5
|
/** Postgres scalar core functions. */
|
|
4
6
|
export const coalesce = postgresQuery.coalesce
|
|
7
|
+
export const call = postgresQuery.call
|
|
8
|
+
export const uuidGenerateV4 = postgresQuery.uuidGenerateV4
|
|
9
|
+
export const nextVal = (
|
|
10
|
+
value: ExpressionInput | SequenceDefinition<string, string | undefined>
|
|
11
|
+
) =>
|
|
12
|
+
postgresQuery.nextVal(
|
|
13
|
+
isSequenceDefinition(value)
|
|
14
|
+
? postgresQuery.cast(postgresQuery.literal(value.qualifiedName()), postgresQuery.type.regclass())
|
|
15
|
+
: value
|
|
16
|
+
)
|
|
@@ -2,10 +2,11 @@ export * as core from "./core.js"
|
|
|
2
2
|
export * as string from "./string.js"
|
|
3
3
|
export * as aggregate from "./aggregate.js"
|
|
4
4
|
export * as window from "./window.js"
|
|
5
|
-
export { json } from "./json.js"
|
|
5
|
+
export { json, jsonb } from "./json.js"
|
|
6
6
|
export * as temporal from "./temporal.js"
|
|
7
7
|
|
|
8
8
|
export { coalesce } from "./core.js"
|
|
9
|
+
export { call, uuidGenerateV4, nextVal } from "./core.js"
|
|
9
10
|
export { lower, upper, concat } from "./string.js"
|
|
10
11
|
export { count, max, min } from "./aggregate.js"
|
|
11
12
|
export { over, rowNumber, rank, denseRank } from "./window.js"
|