effect-qb 0.19.0 → 0.20.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 +7 -1
- package/dist/index.js +1990 -679
- package/dist/mysql.js +1490 -617
- package/dist/postgres/metadata.js +1334 -263
- package/dist/postgres.js +3376 -2307
- package/dist/sqlite.js +1573 -628
- package/dist/standard.js +1984 -673
- package/package.json +2 -4
- package/src/internal/coercion/rules.ts +13 -1
- package/src/internal/column-state.d.ts +3 -3
- package/src/internal/column-state.ts +13 -12
- package/src/internal/column.ts +8 -8
- package/src/internal/datatypes/define.ts +5 -0
- package/src/internal/datatypes/lookup.ts +67 -18
- package/src/internal/datatypes/matrix.ts +903 -0
- package/src/internal/datatypes/shape.ts +2 -0
- package/src/internal/dialect-renderers/mysql.ts +6 -4
- package/src/internal/dialect-renderers/postgres.ts +6 -4
- package/src/internal/dialect-renderers/sqlite.ts +6 -4
- package/src/internal/dialect.ts +1 -1
- package/src/internal/executor.ts +56 -43
- package/src/internal/json/path-access.ts +351 -0
- 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 +2 -1
- package/src/internal/schema-derivation.d.ts +7 -7
- package/src/internal/schema-derivation.ts +11 -11
- package/src/internal/standard-dsl.ts +121 -28
- package/src/internal/table.ts +451 -120
- package/src/mysql/column.ts +6 -6
- package/src/mysql/datatypes/index.ts +1 -0
- package/src/mysql/datatypes/spec.ts +6 -176
- package/src/mysql/errors/normalize.ts +0 -1
- package/src/mysql/executor.ts +4 -6
- package/src/mysql/function/temporal.ts +1 -1
- package/src/mysql/internal/dsl.ts +116 -16
- package/src/mysql/json.ts +1 -33
- package/src/mysql/renderer.ts +13 -6
- package/src/mysql/type.ts +60 -0
- package/src/mysql.ts +3 -1
- package/src/postgres/check.ts +1 -0
- package/src/postgres/column.ts +11 -11
- package/src/postgres/datatypes/index.ts +1 -0
- package/src/postgres/datatypes/spec.ts +6 -260
- package/src/postgres/errors/normalize.ts +0 -1
- package/src/postgres/executor.ts +4 -6
- package/src/postgres/foreign-key.ts +24 -0
- package/src/postgres/function/temporal.ts +1 -1
- package/src/postgres/index.ts +1 -0
- package/src/postgres/internal/dsl.ts +122 -21
- package/src/postgres/json-extension.ts +7 -0
- package/src/postgres/json.ts +726 -173
- package/src/postgres/jsonb.ts +0 -1
- package/src/postgres/primary-key.ts +24 -0
- package/src/postgres/renderer.ts +13 -6
- package/src/postgres/schema-management.ts +1 -6
- package/src/postgres/schema.ts +16 -8
- package/src/postgres/table.ts +111 -113
- package/src/postgres/type.ts +86 -4
- package/src/postgres/unique.ts +32 -0
- package/src/postgres.ts +12 -6
- package/src/sqlite/column.ts +6 -6
- package/src/sqlite/datatypes/index.ts +1 -0
- package/src/sqlite/datatypes/spec.ts +6 -94
- package/src/sqlite/errors/normalize.ts +0 -1
- package/src/sqlite/executor.ts +4 -6
- package/src/sqlite/function/temporal.ts +1 -1
- package/src/sqlite/internal/dsl.ts +100 -5
- package/src/sqlite/json.ts +1 -32
- package/src/sqlite/renderer.ts +13 -6
- package/src/sqlite/type.ts +40 -0
- package/src/sqlite.ts +3 -1
- package/src/standard/cast.ts +113 -0
- package/src/standard/check.ts +17 -0
- package/src/standard/column.ts +10 -10
- package/src/standard/datatypes/index.ts +2 -2
- package/src/standard/datatypes/spec.ts +10 -96
- package/src/standard/foreign-key.ts +37 -0
- package/src/standard/function/temporal.ts +1 -1
- package/src/standard/index.ts +17 -0
- package/src/standard/json.ts +883 -0
- package/src/standard/primary-key.ts +17 -0
- package/src/standard/renderer.ts +31 -3
- package/src/standard/table.ts +25 -21
- package/src/standard/unique.ts +17 -0
- package/src/standard.ts +14 -0
- package/src/internal/table.d.ts +0 -174
- package/src/postgres/cast.ts +0 -45
package/src/standard/column.ts
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
import { standardDatatypes } from "./datatypes/index.js"
|
|
21
21
|
|
|
22
22
|
const primitive = <Type, Db extends Expression.DbType.Any>(
|
|
23
|
-
schema: Schema.Schema<Type
|
|
23
|
+
schema: Schema.Schema<Type>,
|
|
24
24
|
dbType: Db
|
|
25
25
|
): ColumnDefinition<Type, Type, Type, Db, false, false, false, false, false, undefined> =>
|
|
26
26
|
makeColumnDefinition(schema as Schema.Schema<NonNullable<Type>>, {
|
|
@@ -48,15 +48,15 @@ const renderNumericDdlType = (
|
|
|
48
48
|
const boundedString = (length?: number): Schema.Schema<string> =>
|
|
49
49
|
length === undefined
|
|
50
50
|
? Schema.String
|
|
51
|
-
: Schema.String.
|
|
51
|
+
: Schema.String.check(Schema.isMaxLength(length))
|
|
52
52
|
|
|
53
|
-
const finiteNumber = Schema.Number.
|
|
53
|
+
const finiteNumber = Schema.Number.check(Schema.isFinite())
|
|
54
54
|
|
|
55
|
-
export const custom = <SchemaType extends Schema.
|
|
55
|
+
export const custom = <SchemaType extends Schema.Top, Db extends Expression.DbType.Any>(
|
|
56
56
|
schema: SchemaType,
|
|
57
57
|
dbType: Db
|
|
58
58
|
) =>
|
|
59
|
-
makeColumnDefinition(schema as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType
|
|
59
|
+
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>>, {
|
|
60
60
|
dbType: enrichDbType(standardDatatypes, dbType),
|
|
61
61
|
nullable: false,
|
|
62
62
|
hasDefault: false,
|
|
@@ -68,7 +68,7 @@ export const custom = <SchemaType extends Schema.Schema.Any, Db extends Expressi
|
|
|
68
68
|
identity: undefined
|
|
69
69
|
})
|
|
70
70
|
|
|
71
|
-
export const uuid = () => primitive(Schema.
|
|
71
|
+
export const uuid = () => primitive(Schema.String.check(Schema.isUUID()), standardDatatypes.uuid())
|
|
72
72
|
export const text = () => primitive(Schema.String, standardDatatypes.text())
|
|
73
73
|
export const varchar = (length?: number) =>
|
|
74
74
|
makeColumnDefinition(boundedString(length), {
|
|
@@ -79,7 +79,7 @@ export const varchar = (length?: number) =>
|
|
|
79
79
|
primaryKey: false,
|
|
80
80
|
unique: false,
|
|
81
81
|
references: undefined,
|
|
82
|
-
ddlType: length === undefined ?
|
|
82
|
+
ddlType: length === undefined ? undefined : `varchar(${length})`,
|
|
83
83
|
identity: undefined
|
|
84
84
|
})
|
|
85
85
|
export const char = (length = 1) =>
|
|
@@ -114,9 +114,9 @@ export const date = () => primitive(LocalDateStringSchema, standardDatatypes.dat
|
|
|
114
114
|
export const time = () => primitive(LocalTimeStringSchema, standardDatatypes.time())
|
|
115
115
|
export const datetime = () => primitive(LocalDateTimeStringSchema, standardDatatypes.datetime())
|
|
116
116
|
export const timestamp = () => primitive(LocalDateTimeStringSchema, standardDatatypes.timestamp())
|
|
117
|
-
export const blob = () => primitive(Schema.
|
|
118
|
-
export const json = <SchemaType extends Schema.
|
|
119
|
-
makeColumnDefinition(schema as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType
|
|
117
|
+
export const blob = () => primitive(Schema.Uint8Array, standardDatatypes.blob())
|
|
118
|
+
export const json = <SchemaType extends Schema.Top>(schema: SchemaType) =>
|
|
119
|
+
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>>, {
|
|
120
120
|
dbType: { ...standardDatatypes.json(), variant: "json" } as Expression.DbType.Json<"standard", "json">,
|
|
121
121
|
nullable: false,
|
|
122
122
|
hasDefault: false,
|
|
@@ -15,6 +15,7 @@ const withMetadata = <Kind extends keyof typeof standardDatatypeKinds & string>(
|
|
|
15
15
|
runtime: kindSpec.runtime,
|
|
16
16
|
compareGroup: familySpec?.compareGroup,
|
|
17
17
|
castTargets: familySpec?.castTargets,
|
|
18
|
+
implicitTargets: (familySpec as { readonly implicitTargets?: readonly string[] }).implicitTargets,
|
|
18
19
|
traits: familySpec?.traits
|
|
19
20
|
}
|
|
20
21
|
}
|
|
@@ -76,8 +77,7 @@ export const standardDatatypes = {
|
|
|
76
77
|
> & {
|
|
77
78
|
readonly uuid: () => StandardUuidWitness
|
|
78
79
|
readonly json: () => StandardJsonWitness
|
|
79
|
-
})
|
|
80
|
-
float8: () => withMetadata("real")
|
|
80
|
+
})
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
export type StandardDatatypeModule = typeof standardDatatypes
|
|
@@ -1,98 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
portableDatatypeFamilies,
|
|
3
|
+
portableDatatypeKinds,
|
|
4
|
+
type PortableDatatypeFamily,
|
|
5
|
+
type PortableDatatypeKind
|
|
6
|
+
} from "../../internal/datatypes/matrix.js"
|
|
2
7
|
|
|
3
|
-
export const standardDatatypeFamilies =
|
|
4
|
-
|
|
5
|
-
compareGroup: "text",
|
|
6
|
-
castTargets: ["text", "numeric", "integer", "real", "boolean", "date", "time", "datetime", "json", "blob", "null"],
|
|
7
|
-
traits: {
|
|
8
|
-
textual: true,
|
|
9
|
-
ordered: true
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
numeric: {
|
|
13
|
-
compareGroup: "numeric",
|
|
14
|
-
castTargets: ["numeric", "integer", "real", "text", "boolean", "date", "time", "datetime"],
|
|
15
|
-
traits: {
|
|
16
|
-
ordered: true
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
integer: {
|
|
20
|
-
compareGroup: "numeric",
|
|
21
|
-
castTargets: ["integer", "numeric", "real", "text", "boolean", "date", "time", "datetime"],
|
|
22
|
-
traits: {
|
|
23
|
-
ordered: true
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
real: {
|
|
27
|
-
compareGroup: "numeric",
|
|
28
|
-
castTargets: ["real", "numeric", "integer", "text", "boolean"],
|
|
29
|
-
traits: {
|
|
30
|
-
ordered: true
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
boolean: {
|
|
34
|
-
compareGroup: "boolean",
|
|
35
|
-
castTargets: ["boolean", "integer", "numeric", "text"],
|
|
36
|
-
traits: {}
|
|
37
|
-
},
|
|
38
|
-
date: {
|
|
39
|
-
compareGroup: "date",
|
|
40
|
-
castTargets: ["date", "time", "datetime", "text", "numeric", "integer"],
|
|
41
|
-
traits: {
|
|
42
|
-
ordered: true
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
time: {
|
|
46
|
-
compareGroup: "time",
|
|
47
|
-
castTargets: ["time", "date", "datetime", "text", "numeric", "integer"],
|
|
48
|
-
traits: {
|
|
49
|
-
ordered: true
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
datetime: {
|
|
53
|
-
compareGroup: "datetime",
|
|
54
|
-
castTargets: ["datetime", "date", "time", "text", "numeric", "integer"],
|
|
55
|
-
traits: {
|
|
56
|
-
ordered: true
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
json: {
|
|
60
|
-
compareGroup: "json",
|
|
61
|
-
castTargets: ["json", "text"],
|
|
62
|
-
traits: {}
|
|
63
|
-
},
|
|
64
|
-
blob: {
|
|
65
|
-
compareGroup: "blob",
|
|
66
|
-
castTargets: ["blob", "text"],
|
|
67
|
-
traits: {}
|
|
68
|
-
},
|
|
69
|
-
null: {
|
|
70
|
-
compareGroup: "null",
|
|
71
|
-
castTargets: ["text", "numeric", "integer", "real", "boolean", "date", "time", "datetime", "json", "blob", "null"],
|
|
72
|
-
traits: {}
|
|
73
|
-
}
|
|
74
|
-
} as const satisfies Record<string, DatatypeFamilySpec>
|
|
8
|
+
export const standardDatatypeFamilies = portableDatatypeFamilies
|
|
9
|
+
export const standardDatatypeKinds = portableDatatypeKinds
|
|
75
10
|
|
|
76
|
-
export
|
|
77
|
-
|
|
78
|
-
varchar: { family: "text", runtime: "string" },
|
|
79
|
-
char: { family: "text", runtime: "string" },
|
|
80
|
-
clob: { family: "text", runtime: "string" },
|
|
81
|
-
int: { family: "integer", runtime: "number" },
|
|
82
|
-
integer: { family: "integer", runtime: "number" },
|
|
83
|
-
bigint: { family: "integer", runtime: "bigintString" },
|
|
84
|
-
numeric: { family: "numeric", runtime: "decimalString" },
|
|
85
|
-
decimal: { family: "numeric", runtime: "decimalString" },
|
|
86
|
-
real: { family: "real", runtime: "number" },
|
|
87
|
-
double: { family: "real", runtime: "number" },
|
|
88
|
-
boolean: { family: "boolean", runtime: "boolean" },
|
|
89
|
-
date: { family: "date", runtime: "localDate" },
|
|
90
|
-
time: { family: "time", runtime: "localTime" },
|
|
91
|
-
datetime: { family: "datetime", runtime: "localDateTime" },
|
|
92
|
-
timestamp: { family: "datetime", runtime: "localDateTime" },
|
|
93
|
-
json: { family: "json", runtime: "json" },
|
|
94
|
-
blob: { family: "blob", runtime: "bytes" }
|
|
95
|
-
} as const satisfies Record<string, DatatypeKindSpec>
|
|
96
|
-
|
|
97
|
-
export type StandardDatatypeFamily = keyof typeof standardDatatypeFamilies
|
|
98
|
-
export type StandardDatatypeKind = keyof typeof standardDatatypeKinds
|
|
11
|
+
export type StandardDatatypeFamily = PortableDatatypeFamily
|
|
12
|
+
export type StandardDatatypeKind = PortableDatatypeKind
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as BaseTable from "../internal/table.js"
|
|
2
|
+
import type { TableOptionSpec } from "../internal/table-options.js"
|
|
3
|
+
|
|
4
|
+
type ForeignKeySpec = Extract<TableOptionSpec, { readonly kind: "foreignKey" }>
|
|
5
|
+
|
|
6
|
+
export type ReferentialAction = BaseTable.ReferentialAction
|
|
7
|
+
|
|
8
|
+
export const make = BaseTable.foreignKey
|
|
9
|
+
|
|
10
|
+
export const named = <const Name extends string>(
|
|
11
|
+
name: BaseTable.NonEmptyStringInput<Name>
|
|
12
|
+
) =>
|
|
13
|
+
<Spec extends ForeignKeySpec, TableContext extends BaseTable.TableDefinition<any, any, any, "schema", any>>(
|
|
14
|
+
option: BaseTable.TableOption<Spec, TableContext>
|
|
15
|
+
): BaseTable.TableOption<Spec & { readonly name: Name }, TableContext> =>
|
|
16
|
+
BaseTable.mapOption(option, (spec) => ({
|
|
17
|
+
...spec,
|
|
18
|
+
name
|
|
19
|
+
} as Spec & { readonly name: Name }))
|
|
20
|
+
|
|
21
|
+
export const onDelete = (action: BaseTable.ReferentialAction) =>
|
|
22
|
+
<Spec extends ForeignKeySpec, TableContext extends BaseTable.TableDefinition<any, any, any, "schema", any>>(
|
|
23
|
+
option: BaseTable.TableOption<Spec, TableContext>
|
|
24
|
+
): BaseTable.TableOption<Spec & { readonly onDelete: BaseTable.ReferentialAction }, TableContext> =>
|
|
25
|
+
BaseTable.mapOption(option, (spec) => ({
|
|
26
|
+
...spec,
|
|
27
|
+
onDelete: action
|
|
28
|
+
} as Spec & { readonly onDelete: BaseTable.ReferentialAction }))
|
|
29
|
+
|
|
30
|
+
export const onUpdate = (action: BaseTable.ReferentialAction) =>
|
|
31
|
+
<Spec extends ForeignKeySpec, TableContext extends BaseTable.TableDefinition<any, any, any, "schema", any>>(
|
|
32
|
+
option: BaseTable.TableOption<Spec, TableContext>
|
|
33
|
+
): BaseTable.TableOption<Spec & { readonly onUpdate: BaseTable.ReferentialAction }, TableContext> =>
|
|
34
|
+
BaseTable.mapOption(option, (spec) => ({
|
|
35
|
+
...spec,
|
|
36
|
+
onUpdate: action
|
|
37
|
+
} as Spec & { readonly onUpdate: BaseTable.ReferentialAction }))
|
|
@@ -37,7 +37,7 @@ const makeTemporal = <
|
|
|
37
37
|
>(
|
|
38
38
|
name: Name,
|
|
39
39
|
dbType: Db,
|
|
40
|
-
runtimeSchema: Schema.Schema<Runtime
|
|
40
|
+
runtimeSchema: Schema.Schema<Runtime>
|
|
41
41
|
): TemporalExpression<Runtime, Db, Name> =>
|
|
42
42
|
makeExpression({
|
|
43
43
|
runtime: undefined as unknown as Runtime,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as BaseTable from "../internal/table.js"
|
|
2
|
+
import type { TableOptionSpec } from "../internal/table-options.js"
|
|
3
|
+
|
|
4
|
+
type IndexSpec = Extract<TableOptionSpec, { readonly kind: "index" }>
|
|
5
|
+
|
|
6
|
+
export const make = BaseTable.index
|
|
7
|
+
|
|
8
|
+
export const named = <const Name extends string>(
|
|
9
|
+
name: BaseTable.NonEmptyStringInput<Name>
|
|
10
|
+
) =>
|
|
11
|
+
<Spec extends IndexSpec, TableContext extends BaseTable.TableDefinition<any, any, any, "schema", any>>(
|
|
12
|
+
option: BaseTable.TableOption<Spec, TableContext>
|
|
13
|
+
): BaseTable.TableOption<Spec & { readonly name: Name }, TableContext> =>
|
|
14
|
+
BaseTable.mapOption(option, (spec) => ({
|
|
15
|
+
...spec,
|
|
16
|
+
name
|
|
17
|
+
} as Spec & { readonly name: Name }))
|