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/sqlite/column.ts
CHANGED
|
@@ -23,7 +23,7 @@ const enrichDbType = <Db extends Expression.DbType.Any>(dbType: Db): Db => {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const primitive = <Type, Db extends Expression.DbType.Any>(
|
|
26
|
-
schema: Schema.Schema<Type
|
|
26
|
+
schema: Schema.Schema<Type>,
|
|
27
27
|
dbType: Db
|
|
28
28
|
): ColumnDefinition<Type, Type, Type, Db, false, false, false, false, false, undefined> =>
|
|
29
29
|
makeColumnDefinition(schema as Schema.Schema<NonNullable<Type>>, {
|
|
@@ -48,11 +48,11 @@ const renderNumericDdlType = (
|
|
|
48
48
|
: `${kind}(${options.precision},${options.scale})`
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
export const custom = <SchemaType extends Schema.
|
|
51
|
+
export const custom = <SchemaType extends Schema.Top, Db extends Expression.DbType.Any>(
|
|
52
52
|
schema: SchemaType,
|
|
53
53
|
dbType: Db
|
|
54
54
|
) =>
|
|
55
|
-
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType
|
|
55
|
+
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>>, {
|
|
56
56
|
dbType: enrichDbType(dbType),
|
|
57
57
|
nullable: false,
|
|
58
58
|
hasDefault: false,
|
|
@@ -64,7 +64,7 @@ export const custom = <SchemaType extends Schema.Schema.Any, Db extends Expressi
|
|
|
64
64
|
identity: undefined
|
|
65
65
|
})
|
|
66
66
|
|
|
67
|
-
export const uuid = () => primitive(Schema.
|
|
67
|
+
export const uuid = () => primitive(Schema.String.check(Schema.isUUID()), sqliteDatatypes.uuid())
|
|
68
68
|
export const text = () => primitive(Schema.String, sqliteDatatypes.text())
|
|
69
69
|
export const int = () => primitive(Schema.Int, sqliteDatatypes.int())
|
|
70
70
|
export const number = (options?: BaseColumn.NumericOptions) =>
|
|
@@ -84,8 +84,8 @@ export const date = () => primitive(LocalDateStringSchema, sqliteDatatypes.date(
|
|
|
84
84
|
export const time = () => primitive(LocalTimeStringSchema, sqliteDatatypes.time())
|
|
85
85
|
export const datetime = () => primitive(LocalDateTimeStringSchema, sqliteDatatypes.datetime())
|
|
86
86
|
export const timestamp = () => primitive(LocalDateTimeStringSchema, sqliteDatatypes.timestamp())
|
|
87
|
-
export const json = <SchemaType extends Schema.
|
|
88
|
-
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType
|
|
87
|
+
export const json = <SchemaType extends Schema.Top>(schema: SchemaType) =>
|
|
88
|
+
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>>, {
|
|
89
89
|
dbType: { ...sqliteDatatypes.json(), variant: "json" } as Expression.DbType.Json<"sqlite", "json">,
|
|
90
90
|
nullable: false,
|
|
91
91
|
hasDefault: false,
|
package/src/sqlite/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
|
),
|
|
@@ -179,7 +179,7 @@ const sqlClientDriver = (): Driver<any, SqlClient.SqlClient> =>
|
|
|
179
179
|
* Creates the standard SQLite executor pipeline.
|
|
180
180
|
*
|
|
181
181
|
* By default this uses the built-in SQLite renderer plus the ambient
|
|
182
|
-
*
|
|
182
|
+
* `effect/unstable/sql` `SqlClient`. Advanced callers can override the renderer,
|
|
183
183
|
* driver, or both.
|
|
184
184
|
*/
|
|
185
185
|
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.
|
|
@@ -1550,11 +1551,11 @@ const profile: QueryDialectProfile<Dialect, TextDb, NumericDb, BoolDb, Timestamp
|
|
|
1550
1551
|
|
|
1551
1552
|
const literalSchemaOf = <Value extends LiteralValue>(
|
|
1552
1553
|
value: Value
|
|
1553
|
-
): Schema.
|
|
1554
|
+
): Schema.Top | undefined => {
|
|
1554
1555
|
if (value === null || value instanceof Date) {
|
|
1555
1556
|
return undefined
|
|
1556
1557
|
}
|
|
1557
|
-
return Schema.Literal(value) as unknown as Schema.
|
|
1558
|
+
return Schema.Literal(value) as unknown as Schema.Top
|
|
1558
1559
|
}
|
|
1559
1560
|
|
|
1560
1561
|
const literal = <const Value extends LiteralValue>(
|
|
@@ -6422,7 +6423,7 @@ type AsCurriedResult<
|
|
|
6422
6423
|
target: Target,
|
|
6423
6424
|
source: Source & (
|
|
6424
6425
|
SourceRequiredOf<Source> extends never ? unknown : SourceRequirementError<Source>
|
|
6425
|
-
),
|
|
6426
|
+
) & SourceDialectConstraint<Source, Dialect>,
|
|
6426
6427
|
on: On,
|
|
6427
6428
|
options: MergeOptions<Target, MatchedValues, InsertValues, MatchedPredicate, NotMatchedPredicate>
|
|
6428
6429
|
) => QueryPlan<
|
package/src/sqlite/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,15 @@ 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
|
|
45
|
-
? PrimaryKeyColumns
|
|
46
|
-
: Table extends BaseTable.TableClassStatic<any, any, infer PrimaryKeyColumns extends string, any>
|
|
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 PrimaryKeyOfTable<Table extends BaseTable.AnyTable> = Table[typeof BaseTable.TypeId]["primaryKey"][number]
|
|
41
|
+
|
|
42
|
+
type SchemaNameOfTable<Table extends BaseTable.AnyTable> = Table[typeof BaseTable.TypeId]["schemaName"]
|
|
55
43
|
|
|
56
44
|
type ApplySchemaTableOptions<
|
|
57
45
|
Name extends string,
|
|
@@ -169,15 +157,19 @@ export const foreignKey = <
|
|
|
169
157
|
columns: LocalColumns & BaseTable.NonEmptyColumnInput<LocalColumns>,
|
|
170
158
|
target: () => TargetTable,
|
|
171
159
|
referencedColumns: TargetColumns & BaseTable.NonEmptyColumnInput<TargetColumns> & BaseTable.MatchingColumnArityInput<LocalColumns, TargetColumns>
|
|
172
|
-
)
|
|
173
|
-
BaseTable.foreignKey<LocalColumns,
|
|
160
|
+
) =>
|
|
161
|
+
BaseTable.foreignKey<LocalColumns, TargetTable, TargetColumns>(
|
|
174
162
|
columns as LocalColumns & BaseTable.NonEmptyColumnInput<LocalColumns>,
|
|
175
|
-
target
|
|
163
|
+
target,
|
|
176
164
|
referencedColumns as TargetColumns & BaseTable.NonEmptyColumnInput<TargetColumns> & BaseTable.MatchingColumnArityInput<LocalColumns, TargetColumns>
|
|
177
165
|
)
|
|
178
166
|
|
|
179
167
|
export const check = BaseTable.check
|
|
180
168
|
|
|
181
|
-
export
|
|
182
|
-
export
|
|
183
|
-
export
|
|
169
|
+
export const selectSchema = BaseTable.selectSchema
|
|
170
|
+
export const insertSchema = BaseTable.insertSchema
|
|
171
|
+
export const updateSchema = BaseTable.updateSchema
|
|
172
|
+
|
|
173
|
+
export type SelectOf<Table extends AnyTable> = BaseTable.SelectOf<Table>
|
|
174
|
+
export type InsertOf<Table extends AnyTable> = BaseTable.InsertOf<Table>
|
|
175
|
+
export type UpdateOf<Table extends AnyTable> = BaseTable.UpdateOf<Table>
|