effect-qb 0.17.0 → 4.0.0-beta.66
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 +7 -0
- package/dist/mysql.js +207 -134
- package/dist/postgres/metadata.js +121 -52
- package/dist/postgres.js +210 -138
- package/dist/sqlite.js +207 -134
- package/package.json +2 -4
- package/src/internal/column-state.d.ts +3 -3
- package/src/internal/column-state.ts +3 -3
- package/src/internal/column.ts +8 -8
- package/src/internal/dialect.ts +1 -1
- package/src/internal/executor.ts +54 -35
- package/src/internal/query.d.ts +1 -1
- package/src/internal/query.ts +1 -1
- package/src/internal/runtime/driver-value-mapping.ts +3 -3
- package/src/internal/runtime/schema.ts +28 -38
- package/src/internal/runtime/value.ts +20 -23
- package/src/internal/scalar.d.ts +1 -1
- package/src/internal/scalar.ts +1 -1
- package/src/internal/schema-derivation.d.ts +12 -61
- package/src/internal/schema-derivation.ts +95 -43
- package/src/internal/table.d.ts +29 -22
- package/src/internal/table.ts +178 -29
- package/src/mysql/column.ts +6 -6
- package/src/mysql/executor.ts +4 -4
- package/src/mysql/function/temporal.ts +1 -1
- package/src/mysql/internal/dsl.ts +23 -17
- package/src/mysql/table.ts +28 -25
- package/src/postgres/column.ts +11 -11
- package/src/postgres/executor.ts +4 -4
- package/src/postgres/function/temporal.ts +1 -1
- package/src/postgres/internal/dsl.ts +23 -17
- package/src/postgres/schema-management.ts +1 -2
- package/src/postgres/table.ts +13 -21
- package/src/sqlite/column.ts +6 -6
- package/src/sqlite/executor.ts +4 -4
- package/src/sqlite/function/temporal.ts +1 -1
- package/src/sqlite/internal/dsl.ts +7 -6
- package/src/sqlite/table.ts +17 -25
package/src/mysql/column.ts
CHANGED
|
@@ -21,7 +21,7 @@ const enrichDbType = <Db extends Expression.DbType.Any>(dbType: Db): Db => {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const primitive = <Type, Db extends Expression.DbType.Any>(
|
|
24
|
-
schema: Schema.Schema<Type
|
|
24
|
+
schema: Schema.Schema<Type>,
|
|
25
25
|
dbType: Db
|
|
26
26
|
): ColumnDefinition<Type, Type, Type, Db, false, false, false, false, false, undefined> =>
|
|
27
27
|
makeColumnDefinition(schema as Schema.Schema<NonNullable<Type>>, {
|
|
@@ -46,11 +46,11 @@ const renderNumericDdlType = (
|
|
|
46
46
|
: `${kind}(${options.precision},${options.scale})`
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export const custom = <SchemaType extends Schema.
|
|
49
|
+
export const custom = <SchemaType extends Schema.Top, Db extends Expression.DbType.Any>(
|
|
50
50
|
schema: SchemaType,
|
|
51
51
|
dbType: Db
|
|
52
52
|
) =>
|
|
53
|
-
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType
|
|
53
|
+
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>>, {
|
|
54
54
|
dbType: enrichDbType(dbType),
|
|
55
55
|
nullable: false,
|
|
56
56
|
hasDefault: false,
|
|
@@ -62,7 +62,7 @@ export const custom = <SchemaType extends Schema.Schema.Any, Db extends Expressi
|
|
|
62
62
|
identity: undefined
|
|
63
63
|
})
|
|
64
64
|
|
|
65
|
-
export const uuid = () => primitive(Schema.
|
|
65
|
+
export const uuid = () => primitive(Schema.String.check(Schema.isUUID()), mysqlDatatypes.uuid())
|
|
66
66
|
export const text = () => primitive(Schema.String, mysqlDatatypes.text())
|
|
67
67
|
export const int = () => primitive(Schema.Int, mysqlDatatypes.int())
|
|
68
68
|
export const number = (options?: BaseColumn.NumericOptions) =>
|
|
@@ -81,8 +81,8 @@ export const boolean = () => primitive(Schema.Boolean, mysqlDatatypes.boolean())
|
|
|
81
81
|
export const date = () => primitive(LocalDateStringSchema, mysqlDatatypes.date())
|
|
82
82
|
export const datetime = () => primitive(LocalDateTimeStringSchema, mysqlDatatypes.datetime())
|
|
83
83
|
export const timestamp = () => primitive(LocalDateTimeStringSchema, mysqlDatatypes.timestamp())
|
|
84
|
-
export const json = <SchemaType extends Schema.
|
|
85
|
-
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType
|
|
84
|
+
export const json = <SchemaType extends Schema.Top>(schema: SchemaType) =>
|
|
85
|
+
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>>, {
|
|
86
86
|
dbType: { ...mysqlDatatypes.json(), variant: "json" } as Expression.DbType.Json<"mysql", "json">,
|
|
87
87
|
nullable: false,
|
|
88
88
|
hasDefault: false,
|
package/src/mysql/executor.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect"
|
|
2
|
-
import * as SqlClient from "
|
|
2
|
+
import * as SqlClient from "effect/unstable/sql/SqlClient"
|
|
3
3
|
import * as Stream from "effect/Stream"
|
|
4
4
|
|
|
5
5
|
import * as CoreExecutor from "../internal/executor.js"
|
|
@@ -131,10 +131,10 @@ const fromDriver = <
|
|
|
131
131
|
stream(plan) {
|
|
132
132
|
const rendered = renderer.render(plan)
|
|
133
133
|
return Stream.mapError(
|
|
134
|
-
Stream.
|
|
134
|
+
Stream.mapArrayEffect(
|
|
135
135
|
sqlDriver.stream(rendered),
|
|
136
136
|
(rows) => Effect.try({
|
|
137
|
-
try: () => CoreExecutor.
|
|
137
|
+
try: () => CoreExecutor.decodeRows(rendered, plan, rows, { driverMode, valueMappings }) as never,
|
|
138
138
|
catch: (error) => error as RowDecodeError
|
|
139
139
|
})
|
|
140
140
|
),
|
|
@@ -164,7 +164,7 @@ const sqlClientDriver = (): Driver<any, SqlClient.SqlClient> =>
|
|
|
164
164
|
* Creates the standard MySQL executor pipeline.
|
|
165
165
|
*
|
|
166
166
|
* By default this uses the built-in MySQL renderer plus the ambient
|
|
167
|
-
*
|
|
167
|
+
* `effect/unstable/sql` `SqlClient`. Advanced callers can override the renderer,
|
|
168
168
|
* driver, or both.
|
|
169
169
|
*/
|
|
170
170
|
export function make(): QueryExecutor<SqlClient.SqlClient>
|
|
@@ -35,7 +35,7 @@ const makeTemporal = <
|
|
|
35
35
|
>(
|
|
36
36
|
name: Name,
|
|
37
37
|
dbType: Db,
|
|
38
|
-
runtimeSchema: Schema.Schema<Runtime
|
|
38
|
+
runtimeSchema: Schema.Schema<Runtime>
|
|
39
39
|
): TemporalExpression<Runtime, Db, Name> =>
|
|
40
40
|
makeExpression({
|
|
41
41
|
runtime: undefined as unknown as Runtime,
|
|
@@ -80,10 +80,8 @@ import {
|
|
|
80
80
|
type TableDialectOf,
|
|
81
81
|
type StatementOfPlan,
|
|
82
82
|
type MutationInputOf,
|
|
83
|
-
type MutationTargetLike,
|
|
84
83
|
type MutationTargetOfPlan,
|
|
85
84
|
type MergeCapabilities,
|
|
86
|
-
type MutationTargetInput,
|
|
87
85
|
type MutationValuesInput,
|
|
88
86
|
type SourceDialectOf,
|
|
89
87
|
type SourceLike,
|
|
@@ -100,7 +98,6 @@ import {
|
|
|
100
98
|
type TableLike,
|
|
101
99
|
type UpdateInputOfTarget,
|
|
102
100
|
type MutationTargetNamesOf,
|
|
103
|
-
type MutationTargetTuple,
|
|
104
101
|
type TupleDependencies,
|
|
105
102
|
type TupleDialect,
|
|
106
103
|
type ResultRow
|
|
@@ -138,6 +135,10 @@ import * as ProjectionAlias from "../../internal/projection-alias.js"
|
|
|
138
135
|
import * as QueryAst from "../../internal/query-ast.js"
|
|
139
136
|
import { normalizeColumnList } from "../../internal/table-options.js"
|
|
140
137
|
|
|
138
|
+
type MutationTargetLike = Table.AnyTable<Dialect>
|
|
139
|
+
type MutationTargetTuple = readonly [MutationTargetLike, MutationTargetLike, ...MutationTargetLike[]]
|
|
140
|
+
type MutationTargetInput = MutationTargetLike | MutationTargetTuple
|
|
141
|
+
|
|
141
142
|
/**
|
|
142
143
|
* Dialect-specific DB type profile used to specialize the shared query
|
|
143
144
|
* operator surface.
|
|
@@ -1533,11 +1534,11 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
|
|
|
1533
1534
|
|
|
1534
1535
|
const literalSchemaOf = <Value extends LiteralValue>(
|
|
1535
1536
|
value: Value
|
|
1536
|
-
): Schema.
|
|
1537
|
+
): Schema.Top | undefined => {
|
|
1537
1538
|
if (value === null || value instanceof Date) {
|
|
1538
1539
|
return undefined
|
|
1539
1540
|
}
|
|
1540
|
-
return Schema.Literal(value) as unknown as Schema.
|
|
1541
|
+
return Schema.Literal(value) as unknown as Schema.Top
|
|
1541
1542
|
}
|
|
1542
1543
|
|
|
1543
1544
|
const literal = <const Value extends LiteralValue>(
|
|
@@ -5033,6 +5034,11 @@ type MutationTargetTupleDialectConstraint<
|
|
|
5033
5034
|
Dialect extends string
|
|
5034
5035
|
> = Exclude<TableDialectOf<Targets[number]>, Dialect> extends never ? unknown : never
|
|
5035
5036
|
|
|
5037
|
+
type TableDialectConstraint<
|
|
5038
|
+
Target extends TableLike,
|
|
5039
|
+
Dialect extends string
|
|
5040
|
+
> = Exclude<TableDialectOf<Target>, Dialect> extends never ? unknown : never
|
|
5041
|
+
|
|
5036
5042
|
type DuplicateMutationTargetSourceName<
|
|
5037
5043
|
Targets extends readonly MutationTargetLike[],
|
|
5038
5044
|
Seen extends string = never
|
|
@@ -6148,7 +6154,7 @@ type AsCurriedResult<
|
|
|
6148
6154
|
|
|
6149
6155
|
export interface InsertApi {
|
|
6150
6156
|
<Target extends MutationTargetLike>(
|
|
6151
|
-
target: Target
|
|
6157
|
+
target: Target & TableDialectConstraint<Target, Dialect>
|
|
6152
6158
|
): QueryPlan<
|
|
6153
6159
|
{},
|
|
6154
6160
|
never,
|
|
@@ -6165,7 +6171,7 @@ type AsCurriedResult<
|
|
|
6165
6171
|
EmptyFacts
|
|
6166
6172
|
>
|
|
6167
6173
|
<Target extends MutationTargetLike, Values extends Record<string, unknown>>(
|
|
6168
|
-
target: Target,
|
|
6174
|
+
target: Target & TableDialectConstraint<Target, Dialect>,
|
|
6169
6175
|
values: MutationValuesInput<"insert", Target, Values> & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
6170
6176
|
): QueryPlan<
|
|
6171
6177
|
{},
|
|
@@ -6237,7 +6243,7 @@ type AsCurriedResult<
|
|
|
6237
6243
|
EmptyFacts
|
|
6238
6244
|
>
|
|
6239
6245
|
<Target extends MutationTargetLike, Values extends Record<string, unknown>>(
|
|
6240
|
-
target: Target,
|
|
6246
|
+
target: Target & TableDialectConstraint<Target, Dialect>,
|
|
6241
6247
|
values: MutationValuesInput<"update", Target, Values> & UpdateValuesNonEmptyConstraint<Values> & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
6242
6248
|
): QueryPlan<
|
|
6243
6249
|
{},
|
|
@@ -6262,7 +6268,7 @@ type AsCurriedResult<
|
|
|
6262
6268
|
const Columns extends DdlColumnInput,
|
|
6263
6269
|
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = undefined
|
|
6264
6270
|
>(
|
|
6265
|
-
target: Target,
|
|
6271
|
+
target: Target & TableDialectConstraint<Target, Dialect>,
|
|
6266
6272
|
values: Values & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
6267
6273
|
conflictColumns: ValidateTargetColumnInput<Target, Columns>,
|
|
6268
6274
|
updateValues?: UpdateValues & UpdateValuesNonEmptyConstraint<Exclude<UpdateValues, undefined>> & MutationValuesDialectConstraint<Exclude<UpdateValues, undefined>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
@@ -6286,7 +6292,7 @@ type AsCurriedResult<
|
|
|
6286
6292
|
|
|
6287
6293
|
interface DeleteApi {
|
|
6288
6294
|
<Target extends MutationTargetLike>(
|
|
6289
|
-
target: Target
|
|
6295
|
+
target: Target & TableDialectConstraint<Target, Dialect>
|
|
6290
6296
|
): QueryPlan<
|
|
6291
6297
|
{},
|
|
6292
6298
|
never,
|
|
@@ -6322,7 +6328,7 @@ type AsCurriedResult<
|
|
|
6322
6328
|
}
|
|
6323
6329
|
|
|
6324
6330
|
type TruncateApi = <Target extends MutationTargetLike>(
|
|
6325
|
-
target: Target,
|
|
6331
|
+
target: Target & TableDialectConstraint<Target, Dialect>,
|
|
6326
6332
|
options?: TruncateOptions
|
|
6327
6333
|
) => QueryPlan<
|
|
6328
6334
|
{},
|
|
@@ -6355,10 +6361,10 @@ type AsCurriedResult<
|
|
|
6355
6361
|
MatchedPredicate extends PredicateInput | undefined = undefined,
|
|
6356
6362
|
NotMatchedPredicate extends PredicateInput | undefined = undefined
|
|
6357
6363
|
>(
|
|
6358
|
-
target: Target,
|
|
6364
|
+
target: Target & TableDialectConstraint<Target, Dialect>,
|
|
6359
6365
|
source: Source & (
|
|
6360
6366
|
SourceRequiredOf<Source> extends never ? unknown : SourceRequirementError<Source>
|
|
6361
|
-
),
|
|
6367
|
+
) & SourceDialectConstraint<Source, Dialect>,
|
|
6362
6368
|
on: On,
|
|
6363
6369
|
options: MergeOptions<Target, MatchedValues, InsertValues, MatchedPredicate, NotMatchedPredicate>
|
|
6364
6370
|
) => QueryPlan<
|
|
@@ -6612,7 +6618,7 @@ type AsCurriedResult<
|
|
|
6612
6618
|
>
|
|
6613
6619
|
|
|
6614
6620
|
type CreateTableApi = <Target extends SchemaTableLike>(
|
|
6615
|
-
target: Target,
|
|
6621
|
+
target: Target & TableDialectConstraint<Target, Dialect>,
|
|
6616
6622
|
options?: CreateTableOptions
|
|
6617
6623
|
) => QueryPlan<
|
|
6618
6624
|
{},
|
|
@@ -6628,7 +6634,7 @@ type AsCurriedResult<
|
|
|
6628
6634
|
>
|
|
6629
6635
|
|
|
6630
6636
|
type DropTableApi = <Target extends SchemaTableLike>(
|
|
6631
|
-
target: Target,
|
|
6637
|
+
target: Target & TableDialectConstraint<Target, Dialect>,
|
|
6632
6638
|
options?: DropTableOptions
|
|
6633
6639
|
) => QueryPlan<
|
|
6634
6640
|
{},
|
|
@@ -6644,7 +6650,7 @@ type AsCurriedResult<
|
|
|
6644
6650
|
>
|
|
6645
6651
|
|
|
6646
6652
|
type CreateIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
|
|
6647
|
-
target: Target,
|
|
6653
|
+
target: Target & TableDialectConstraint<Target, Dialect>,
|
|
6648
6654
|
columns: Columns & ValidateDdlColumnInput<Target, Columns>,
|
|
6649
6655
|
options?: CreateIndexOptions
|
|
6650
6656
|
) => QueryPlan<
|
|
@@ -6661,7 +6667,7 @@ type AsCurriedResult<
|
|
|
6661
6667
|
>
|
|
6662
6668
|
|
|
6663
6669
|
type DropIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
|
|
6664
|
-
target: Target,
|
|
6670
|
+
target: Target & TableDialectConstraint<Target, Dialect>,
|
|
6665
6671
|
columns: Columns & ValidateDdlColumnInput<Target, Columns>,
|
|
6666
6672
|
options?: DropIndexOptions
|
|
6667
6673
|
) => QueryPlan<
|
package/src/mysql/table.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type * as Schema from "effect/Schema"
|
|
2
|
-
|
|
3
1
|
import type * as Expression from "../internal/scalar.js"
|
|
4
2
|
import { ColumnTypeId, type AnyColumnDefinition } from "../internal/column-state.js"
|
|
5
3
|
import * as BaseTable from "../internal/table.js"
|
|
@@ -33,25 +31,17 @@ export type TableClassStatic<
|
|
|
33
31
|
SchemaName extends string | undefined = undefined
|
|
34
32
|
> = BaseTable.TableClassStatic<Name, Fields, PrimaryKeyColumns, SchemaName>
|
|
35
33
|
|
|
36
|
-
export type AnyTable = BaseTable.AnyTable
|
|
34
|
+
export type AnyTable = BaseTable.AnyTable<Dialect>
|
|
37
35
|
|
|
38
|
-
type FieldsOfTable<Table> = Table
|
|
36
|
+
type FieldsOfTable<Table extends BaseTable.AnyTable> = Table[typeof BaseTable.TypeId]["fields"] extends infer Fields extends DialectFieldMap
|
|
39
37
|
? Fields
|
|
40
|
-
:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
type PrimaryKeyOfTable<Table> = Table
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
? PrimaryKeyColumns
|
|
48
|
-
: never
|
|
49
|
-
|
|
50
|
-
type SchemaNameOfTable<Table> = Table extends BaseTable.TableDefinition<any, any, any, any, infer SchemaName>
|
|
51
|
-
? SchemaName
|
|
52
|
-
: Table extends BaseTable.TableClassStatic<any, any, any, infer SchemaName>
|
|
53
|
-
? SchemaName
|
|
54
|
-
: never
|
|
38
|
+
: never
|
|
39
|
+
|
|
40
|
+
type ColumnNamesOfTable<Table extends BaseTable.AnyTable> = Extract<keyof FieldsOfTable<Table>, string>
|
|
41
|
+
|
|
42
|
+
type PrimaryKeyOfTable<Table extends BaseTable.AnyTable> = Table[typeof BaseTable.TypeId]["primaryKey"][number]
|
|
43
|
+
|
|
44
|
+
type SchemaNameOfTable<Table extends BaseTable.AnyTable> = Table[typeof BaseTable.TypeId]["schemaName"]
|
|
55
45
|
|
|
56
46
|
type ApplySchemaTableOptions<
|
|
57
47
|
Name extends string,
|
|
@@ -169,15 +159,28 @@ export const foreignKey = <
|
|
|
169
159
|
columns: LocalColumns & BaseTable.NonEmptyColumnInput<LocalColumns>,
|
|
170
160
|
target: () => TargetTable,
|
|
171
161
|
referencedColumns: TargetColumns & BaseTable.NonEmptyColumnInput<TargetColumns> & BaseTable.MatchingColumnArityInput<LocalColumns, TargetColumns>
|
|
172
|
-
): BaseTable.TableOption
|
|
173
|
-
|
|
162
|
+
): BaseTable.TableOption<{
|
|
163
|
+
readonly kind: "foreignKey"
|
|
164
|
+
readonly columns: BaseTable.NormalizeColumns<LocalColumns>
|
|
165
|
+
readonly references: () => {
|
|
166
|
+
readonly tableName: string
|
|
167
|
+
readonly schemaName?: string
|
|
168
|
+
readonly columns: BaseTable.NormalizeColumns<TargetColumns>
|
|
169
|
+
readonly knownColumns: readonly ColumnNamesOfTable<TargetTable>[]
|
|
170
|
+
}
|
|
171
|
+
}> =>
|
|
172
|
+
BaseTable.foreignKey<LocalColumns, TargetTable, TargetColumns>(
|
|
174
173
|
columns as LocalColumns & BaseTable.NonEmptyColumnInput<LocalColumns>,
|
|
175
|
-
target
|
|
174
|
+
target,
|
|
176
175
|
referencedColumns as TargetColumns & BaseTable.NonEmptyColumnInput<TargetColumns> & BaseTable.MatchingColumnArityInput<LocalColumns, TargetColumns>
|
|
177
176
|
)
|
|
178
177
|
|
|
179
178
|
export const check = BaseTable.check
|
|
180
179
|
|
|
181
|
-
export
|
|
182
|
-
export
|
|
183
|
-
export
|
|
180
|
+
export const selectSchema = BaseTable.selectSchema
|
|
181
|
+
export const insertSchema = BaseTable.insertSchema
|
|
182
|
+
export const updateSchema = BaseTable.updateSchema
|
|
183
|
+
|
|
184
|
+
export type SelectOf<Table extends AnyTable> = BaseTable.SelectOf<Table>
|
|
185
|
+
export type InsertOf<Table extends AnyTable> = BaseTable.InsertOf<Table>
|
|
186
|
+
export type UpdateOf<Table extends AnyTable> = BaseTable.UpdateOf<Table>
|
package/src/postgres/column.ts
CHANGED
|
@@ -29,7 +29,7 @@ const enrichDbType = <Db extends Expression.DbType.Any>(dbType: Db): Db => {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
const primitive = <Type, Db extends Expression.DbType.Any>(
|
|
32
|
-
schema: Schema.Schema<Type
|
|
32
|
+
schema: Schema.Schema<Type>,
|
|
33
33
|
dbType: Db
|
|
34
34
|
): ColumnDefinition<Type, Type, Type, Db, false, false, false, false, false, undefined> =>
|
|
35
35
|
makeColumnDefinition(schema as Schema.Schema<NonNullable<Type>>, {
|
|
@@ -57,15 +57,15 @@ const renderNumericDdlType = (
|
|
|
57
57
|
const boundedString = (length?: number): Schema.Schema<string> =>
|
|
58
58
|
length === undefined
|
|
59
59
|
? Schema.String
|
|
60
|
-
: Schema.String.
|
|
60
|
+
: Schema.String.check(Schema.isMaxLength(length))
|
|
61
61
|
|
|
62
|
-
const finiteNumber = Schema.Number.
|
|
62
|
+
const finiteNumber = Schema.Number.check(Schema.isFinite())
|
|
63
63
|
|
|
64
|
-
export const custom = <SchemaType extends Schema.
|
|
64
|
+
export const custom = <SchemaType extends Schema.Top, Db extends Expression.DbType.Any>(
|
|
65
65
|
schema: SchemaType,
|
|
66
66
|
dbType: Db
|
|
67
67
|
) =>
|
|
68
|
-
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType
|
|
68
|
+
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>>, {
|
|
69
69
|
dbType: enrichDbType(dbType),
|
|
70
70
|
nullable: false,
|
|
71
71
|
hasDefault: false,
|
|
@@ -77,7 +77,7 @@ export const custom = <SchemaType extends Schema.Schema.Any, Db extends Expressi
|
|
|
77
77
|
identity: undefined
|
|
78
78
|
})
|
|
79
79
|
|
|
80
|
-
export const uuid = () => primitive(Schema.
|
|
80
|
+
export const uuid = () => primitive(Schema.String.check(Schema.isUUID()), postgresDatatypes.uuid())
|
|
81
81
|
export const text = () => primitive(Schema.String, postgresDatatypes.text())
|
|
82
82
|
export const int = () => primitive(Schema.Int, postgresDatatypes.int4())
|
|
83
83
|
export const int2 = () => primitive(Schema.Int, postgresDatatypes.int2())
|
|
@@ -103,7 +103,7 @@ export const time = () => primitive(LocalTimeStringSchema, postgresDatatypes.tim
|
|
|
103
103
|
export const timetz = () => primitive(OffsetTimeStringSchema, postgresDatatypes.timetz())
|
|
104
104
|
export const timestamptz = () => primitive(InstantStringSchema, postgresDatatypes.timestamptz())
|
|
105
105
|
export const interval = () => primitive(Schema.String, postgresDatatypes.interval())
|
|
106
|
-
export const bytea = () => primitive(Schema.
|
|
106
|
+
export const bytea = () => primitive(Schema.Uint8Array, postgresDatatypes.bytea())
|
|
107
107
|
export const name = () => primitive(Schema.String, postgresDatatypes.name())
|
|
108
108
|
export const oid = () => primitive(Schema.Int, postgresDatatypes.oid())
|
|
109
109
|
export const regclass = () => primitive(Schema.String, postgresDatatypes.regclass())
|
|
@@ -135,8 +135,8 @@ export const varchar = (length?: number) =>
|
|
|
135
135
|
ddlType: length === undefined ? "varchar" : `varchar(${length})`,
|
|
136
136
|
identity: undefined
|
|
137
137
|
})
|
|
138
|
-
export const json = <SchemaType extends Schema.
|
|
139
|
-
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType
|
|
138
|
+
export const json = <SchemaType extends Schema.Top>(schema: SchemaType) =>
|
|
139
|
+
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>>, {
|
|
140
140
|
dbType: postgresDatatypes.json(),
|
|
141
141
|
nullable: false,
|
|
142
142
|
hasDefault: false,
|
|
@@ -147,8 +147,8 @@ export const json = <SchemaType extends Schema.Schema.Any>(schema: SchemaType) =
|
|
|
147
147
|
ddlType: undefined,
|
|
148
148
|
identity: undefined
|
|
149
149
|
})
|
|
150
|
-
export const jsonb = <SchemaType extends Schema.
|
|
151
|
-
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType
|
|
150
|
+
export const jsonb = <SchemaType extends Schema.Top>(schema: SchemaType) =>
|
|
151
|
+
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>>, {
|
|
152
152
|
dbType: postgresDatatypes.jsonb(),
|
|
153
153
|
nullable: false,
|
|
154
154
|
hasDefault: false,
|
package/src/postgres/executor.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect"
|
|
2
|
-
import * as SqlClient from "
|
|
2
|
+
import * as SqlClient from "effect/unstable/sql/SqlClient"
|
|
3
3
|
import * as Stream from "effect/Stream"
|
|
4
4
|
|
|
5
5
|
import * as CoreExecutor from "../internal/executor.js"
|
|
@@ -140,10 +140,10 @@ const fromDriver = <
|
|
|
140
140
|
stream(plan) {
|
|
141
141
|
const rendered = renderer.render(plan)
|
|
142
142
|
return Stream.mapError(
|
|
143
|
-
Stream.
|
|
143
|
+
Stream.mapArrayEffect(
|
|
144
144
|
sqlDriver.stream(rendered),
|
|
145
145
|
(rows) => Effect.try({
|
|
146
|
-
try: () => CoreExecutor.
|
|
146
|
+
try: () => CoreExecutor.decodeRows(rendered, plan, rows, { driverMode, valueMappings }) as never,
|
|
147
147
|
catch: (error) => error as RowDecodeError
|
|
148
148
|
})
|
|
149
149
|
),
|
|
@@ -173,7 +173,7 @@ const sqlClientDriver = (): Driver<any, SqlClient.SqlClient> =>
|
|
|
173
173
|
* Creates the standard Postgres executor pipeline.
|
|
174
174
|
*
|
|
175
175
|
* By default this uses the built-in Postgres renderer plus the ambient
|
|
176
|
-
*
|
|
176
|
+
* `effect/unstable/sql` `SqlClient`. Advanced callers can override the renderer,
|
|
177
177
|
* driver, or both.
|
|
178
178
|
*/
|
|
179
179
|
export function make(): QueryExecutor<SqlClient.SqlClient>
|
|
@@ -39,7 +39,7 @@ const makeTemporal = <
|
|
|
39
39
|
>(
|
|
40
40
|
name: Name,
|
|
41
41
|
dbType: Db,
|
|
42
|
-
runtimeSchema: Schema.Schema<Runtime
|
|
42
|
+
runtimeSchema: Schema.Schema<Runtime>
|
|
43
43
|
): TemporalExpression<Runtime, Db, Name> =>
|
|
44
44
|
makeExpression({
|
|
45
45
|
runtime: undefined as unknown as Runtime,
|
|
@@ -80,10 +80,8 @@ import {
|
|
|
80
80
|
type TableDialectOf,
|
|
81
81
|
type StatementOfPlan,
|
|
82
82
|
type MutationInputOf,
|
|
83
|
-
type MutationTargetLike,
|
|
84
83
|
type MutationTargetOfPlan,
|
|
85
84
|
type MergeCapabilities,
|
|
86
|
-
type MutationTargetInput,
|
|
87
85
|
type MutationValuesInput,
|
|
88
86
|
type SourceDialectOf,
|
|
89
87
|
type SourceLike,
|
|
@@ -100,7 +98,6 @@ import {
|
|
|
100
98
|
type TableLike,
|
|
101
99
|
type UpdateInputOfTarget,
|
|
102
100
|
type MutationTargetNamesOf,
|
|
103
|
-
type MutationTargetTuple,
|
|
104
101
|
type TupleDependencies,
|
|
105
102
|
type TupleDialect,
|
|
106
103
|
type ResultRow
|
|
@@ -138,6 +135,10 @@ import * as ProjectionAlias from "../../internal/projection-alias.js"
|
|
|
138
135
|
import * as QueryAst from "../../internal/query-ast.js"
|
|
139
136
|
import { normalizeColumnList } from "../../internal/table-options.js"
|
|
140
137
|
|
|
138
|
+
type MutationTargetLike = Table.AnyTable<Dialect>
|
|
139
|
+
type MutationTargetTuple = readonly [MutationTargetLike, MutationTargetLike, ...MutationTargetLike[]]
|
|
140
|
+
type MutationTargetInput = MutationTargetLike | MutationTargetTuple
|
|
141
|
+
|
|
141
142
|
/**
|
|
142
143
|
* Dialect-specific DB type profile used to specialize the shared query
|
|
143
144
|
* operator surface.
|
|
@@ -1512,11 +1513,11 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
|
|
|
1512
1513
|
|
|
1513
1514
|
const literalSchemaOf = <Value extends LiteralValue>(
|
|
1514
1515
|
value: Value
|
|
1515
|
-
): Schema.
|
|
1516
|
+
): Schema.Top | undefined => {
|
|
1516
1517
|
if (value === null || value instanceof Date) {
|
|
1517
1518
|
return undefined
|
|
1518
1519
|
}
|
|
1519
|
-
return Schema.Literal(value) as unknown as Schema.
|
|
1520
|
+
return Schema.Literal(value) as unknown as Schema.Top
|
|
1520
1521
|
}
|
|
1521
1522
|
|
|
1522
1523
|
const literal = <const Value extends LiteralValue>(
|
|
@@ -5065,6 +5066,11 @@ type MutationTargetTupleDialectConstraint<
|
|
|
5065
5066
|
Dialect extends string
|
|
5066
5067
|
> = Exclude<TableDialectOf<Targets[number]>, Dialect> extends never ? unknown : never
|
|
5067
5068
|
|
|
5069
|
+
type TableDialectConstraint<
|
|
5070
|
+
Target extends TableLike,
|
|
5071
|
+
Dialect extends string
|
|
5072
|
+
> = Exclude<TableDialectOf<Target>, Dialect> extends never ? unknown : never
|
|
5073
|
+
|
|
5068
5074
|
type MutationRequiredFromValues<Values extends Record<string, unknown>> = {
|
|
5069
5075
|
[K in keyof Values]: Values[K] extends Expression.Any ? RequiredFromDependencies<DependenciesOf<Values[K]>> : never
|
|
5070
5076
|
}[keyof Values]
|
|
@@ -6220,7 +6226,7 @@ type AsCurriedResult<
|
|
|
6220
6226
|
|
|
6221
6227
|
export interface InsertApi {
|
|
6222
6228
|
<Target extends MutationTargetLike>(
|
|
6223
|
-
target: Target
|
|
6229
|
+
target: Target & TableDialectConstraint<Target, Dialect>
|
|
6224
6230
|
): QueryPlan<
|
|
6225
6231
|
{},
|
|
6226
6232
|
never,
|
|
@@ -6237,7 +6243,7 @@ type AsCurriedResult<
|
|
|
6237
6243
|
EmptyFacts
|
|
6238
6244
|
>
|
|
6239
6245
|
<Target extends MutationTargetLike, Values extends Record<string, unknown>>(
|
|
6240
|
-
target: Target,
|
|
6246
|
+
target: Target & TableDialectConstraint<Target, Dialect>,
|
|
6241
6247
|
values: MutationValuesInput<"insert", Target, Values> & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
6242
6248
|
): QueryPlan<
|
|
6243
6249
|
{},
|
|
@@ -6309,7 +6315,7 @@ type AsCurriedResult<
|
|
|
6309
6315
|
EmptyFacts
|
|
6310
6316
|
>
|
|
6311
6317
|
<Target extends MutationTargetLike, Values extends Record<string, unknown>>(
|
|
6312
|
-
target: Target,
|
|
6318
|
+
target: Target & TableDialectConstraint<Target, Dialect>,
|
|
6313
6319
|
values: MutationValuesInput<"update", Target, Values> & UpdateValuesNonEmptyConstraint<Values> & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
6314
6320
|
): QueryPlan<
|
|
6315
6321
|
{},
|
|
@@ -6334,7 +6340,7 @@ type AsCurriedResult<
|
|
|
6334
6340
|
const Columns extends DdlColumnInput,
|
|
6335
6341
|
UpdateValues extends MutationInputOf<Table.UpdateOf<Target>> | undefined = undefined
|
|
6336
6342
|
>(
|
|
6337
|
-
target: Target,
|
|
6343
|
+
target: Target & TableDialectConstraint<Target, Dialect>,
|
|
6338
6344
|
values: Values & MutationValuesDialectConstraint<Values, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>,
|
|
6339
6345
|
conflictColumns: ValidateTargetColumnInput<Target, Columns>,
|
|
6340
6346
|
updateValues?: UpdateValues & UpdateValuesNonEmptyConstraint<Exclude<UpdateValues, undefined>> & MutationValuesDialectConstraint<Exclude<UpdateValues, undefined>, Dialect, TextDb, NumericDb, BoolDb, TimestampDb, NullDb>
|
|
@@ -6358,7 +6364,7 @@ type AsCurriedResult<
|
|
|
6358
6364
|
|
|
6359
6365
|
interface DeleteApi {
|
|
6360
6366
|
<Target extends MutationTargetLike>(
|
|
6361
|
-
target: Target
|
|
6367
|
+
target: Target & TableDialectConstraint<Target, Dialect>
|
|
6362
6368
|
): QueryPlan<
|
|
6363
6369
|
{},
|
|
6364
6370
|
never,
|
|
@@ -6394,7 +6400,7 @@ type AsCurriedResult<
|
|
|
6394
6400
|
}
|
|
6395
6401
|
|
|
6396
6402
|
type TruncateApi = <Target extends MutationTargetLike>(
|
|
6397
|
-
target: Target,
|
|
6403
|
+
target: Target & TableDialectConstraint<Target, Dialect>,
|
|
6398
6404
|
options?: TruncateOptions
|
|
6399
6405
|
) => QueryPlan<
|
|
6400
6406
|
{},
|
|
@@ -6421,10 +6427,10 @@ type AsCurriedResult<
|
|
|
6421
6427
|
MatchedPredicate extends PredicateInput | undefined = undefined,
|
|
6422
6428
|
NotMatchedPredicate extends PredicateInput | undefined = undefined
|
|
6423
6429
|
>(
|
|
6424
|
-
target: Target,
|
|
6430
|
+
target: Target & TableDialectConstraint<Target, Dialect>,
|
|
6425
6431
|
source: Source & (
|
|
6426
6432
|
SourceRequiredOf<Source> extends never ? unknown : SourceRequirementError<Source>
|
|
6427
|
-
) & MergeSourceNameConstraint<Target, Source>,
|
|
6433
|
+
) & MergeSourceNameConstraint<Target, Source> & SourceDialectConstraint<Source, Dialect>,
|
|
6428
6434
|
on: On,
|
|
6429
6435
|
options: MergeOptions<Target, MatchedValues, InsertValues, MatchedPredicate, NotMatchedPredicate>
|
|
6430
6436
|
) => QueryPlan<
|
|
@@ -6626,7 +6632,7 @@ type AsCurriedResult<
|
|
|
6626
6632
|
>
|
|
6627
6633
|
|
|
6628
6634
|
type CreateTableApi = <Target extends SchemaTableLike>(
|
|
6629
|
-
target: Target,
|
|
6635
|
+
target: Target & TableDialectConstraint<Target, Dialect>,
|
|
6630
6636
|
options?: CreateTableOptions
|
|
6631
6637
|
) => QueryPlan<
|
|
6632
6638
|
{},
|
|
@@ -6642,7 +6648,7 @@ type AsCurriedResult<
|
|
|
6642
6648
|
>
|
|
6643
6649
|
|
|
6644
6650
|
type DropTableApi = <Target extends SchemaTableLike>(
|
|
6645
|
-
target: Target,
|
|
6651
|
+
target: Target & TableDialectConstraint<Target, Dialect>,
|
|
6646
6652
|
options?: DropTableOptions
|
|
6647
6653
|
) => QueryPlan<
|
|
6648
6654
|
{},
|
|
@@ -6658,7 +6664,7 @@ type AsCurriedResult<
|
|
|
6658
6664
|
>
|
|
6659
6665
|
|
|
6660
6666
|
type CreateIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
|
|
6661
|
-
target: Target,
|
|
6667
|
+
target: Target & TableDialectConstraint<Target, Dialect>,
|
|
6662
6668
|
columns: Columns & ValidateDdlColumnInput<Target, Columns>,
|
|
6663
6669
|
options?: CreateIndexOptions
|
|
6664
6670
|
) => QueryPlan<
|
|
@@ -6675,7 +6681,7 @@ type AsCurriedResult<
|
|
|
6675
6681
|
>
|
|
6676
6682
|
|
|
6677
6683
|
type DropIndexApi = <Target extends SchemaTableLike, const Columns extends DdlColumnInput>(
|
|
6678
|
-
target: Target,
|
|
6684
|
+
target: Target & TableDialectConstraint<Target, Dialect>,
|
|
6679
6685
|
columns: Columns & ValidateDdlColumnInput<Target, Columns>,
|
|
6680
6686
|
options?: DropIndexOptions
|
|
6681
6687
|
) => QueryPlan<
|
|
@@ -137,9 +137,8 @@ const EnumProto = {
|
|
|
137
137
|
}
|
|
138
138
|
},
|
|
139
139
|
column(this: EnumDefinition) {
|
|
140
|
-
const values = this.values.map((value) => Schema.Literal(value)) as unknown as readonly [Schema.Schema.Any, ...Schema.Schema.Any[]]
|
|
141
140
|
return makeColumnDefinition(
|
|
142
|
-
|
|
141
|
+
Schema.Literals(this.values),
|
|
143
142
|
{
|
|
144
143
|
dbType: this.type(),
|
|
145
144
|
nullable: false,
|
package/src/postgres/table.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type * as Schema from "effect/Schema"
|
|
2
|
-
|
|
3
1
|
import type * as Expression from "../internal/scalar.js"
|
|
4
2
|
import { ColumnTypeId, type AnyColumnDefinition } from "../internal/column-state.js"
|
|
5
3
|
import * as BaseTable from "../internal/table.js"
|
|
@@ -34,27 +32,17 @@ export type TableClassStatic<
|
|
|
34
32
|
SchemaName extends string | undefined = "public"
|
|
35
33
|
> = BaseTable.TableClassStatic<Name, Fields, PrimaryKeyColumns, SchemaName>
|
|
36
34
|
|
|
37
|
-
export type AnyTable = BaseTable.AnyTable
|
|
35
|
+
export type AnyTable = BaseTable.AnyTable<Dialect>
|
|
38
36
|
|
|
39
|
-
type FieldsOfTable<Table> = Table
|
|
37
|
+
type FieldsOfTable<Table extends BaseTable.AnyTable> = Table[typeof BaseTable.TypeId]["fields"] extends infer Fields extends DialectFieldMap
|
|
40
38
|
? Fields
|
|
41
|
-
:
|
|
42
|
-
? Fields
|
|
43
|
-
: never
|
|
39
|
+
: never
|
|
44
40
|
|
|
45
|
-
type ColumnNamesOfTable<Table> = Extract<keyof FieldsOfTable<Table>, string>
|
|
41
|
+
type ColumnNamesOfTable<Table extends BaseTable.AnyTable> = Extract<keyof FieldsOfTable<Table>, string>
|
|
46
42
|
|
|
47
|
-
type PrimaryKeyOfTable<Table> = Table
|
|
48
|
-
? PrimaryKeyColumns
|
|
49
|
-
: Table extends BaseTable.TableClassStatic<any, any, infer PrimaryKeyColumns extends string, any>
|
|
50
|
-
? PrimaryKeyColumns
|
|
51
|
-
: never
|
|
43
|
+
type PrimaryKeyOfTable<Table extends BaseTable.AnyTable> = Table[typeof BaseTable.TypeId]["primaryKey"][number]
|
|
52
44
|
|
|
53
|
-
type SchemaNameOfTable<Table> = Table
|
|
54
|
-
? SchemaName
|
|
55
|
-
: Table extends BaseTable.TableClassStatic<any, any, any, infer SchemaName>
|
|
56
|
-
? SchemaName
|
|
57
|
-
: never
|
|
45
|
+
type SchemaNameOfTable<Table extends BaseTable.AnyTable> = Table[typeof BaseTable.TypeId]["schemaName"]
|
|
58
46
|
|
|
59
47
|
type ApplySchemaTableOptions<
|
|
60
48
|
Name extends string,
|
|
@@ -562,6 +550,10 @@ export const check: {
|
|
|
562
550
|
})
|
|
563
551
|
})()) as never
|
|
564
552
|
|
|
565
|
-
export
|
|
566
|
-
export
|
|
567
|
-
export
|
|
553
|
+
export const selectSchema = BaseTable.selectSchema
|
|
554
|
+
export const insertSchema = BaseTable.insertSchema
|
|
555
|
+
export const updateSchema = BaseTable.updateSchema
|
|
556
|
+
|
|
557
|
+
export type SelectOf<Table extends AnyTable> = BaseTable.SelectOf<Table>
|
|
558
|
+
export type InsertOf<Table extends AnyTable> = BaseTable.InsertOf<Table>
|
|
559
|
+
export type UpdateOf<Table extends AnyTable> = BaseTable.UpdateOf<Table>
|