effect-qb 0.17.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 +11 -1
- package/dist/index.js +9376 -0
- package/dist/mysql.js +4092 -2671
- package/dist/postgres/metadata.js +2589 -1402
- package/dist/postgres.js +3953 -3583
- package/dist/sqlite.js +5527 -4088
- package/dist/standard.js +9330 -0
- package/package.json +9 -4
- package/src/casing.ts +71 -0
- package/src/index.ts +2 -0
- package/src/internal/casing.ts +89 -0
- package/src/internal/coercion/rules.ts +13 -1
- package/src/internal/column-state.d.ts +3 -3
- package/src/internal/column-state.ts +24 -18
- package/src/internal/column.ts +52 -15
- package/src/internal/datatypes/define.ts +7 -1
- package/src/internal/datatypes/enrich.ts +23 -0
- package/src/internal/datatypes/lookup.ts +81 -25
- package/src/internal/datatypes/matrix.ts +903 -0
- package/src/internal/datatypes/shape.ts +2 -0
- package/src/internal/derived-table.ts +4 -36
- package/src/{mysql/internal/sql-expression-renderer.ts → internal/dialect-renderers/mysql.ts} +552 -361
- package/src/{postgres/internal/sql-expression-renderer.ts → internal/dialect-renderers/postgres.ts} +657 -400
- package/src/{sqlite/internal/sql-expression-renderer.ts → internal/dialect-renderers/sqlite.ts} +505 -347
- package/src/internal/dialect.ts +36 -1
- package/src/internal/dsl-mutation-runtime.ts +12 -162
- package/src/internal/dsl-plan-runtime.ts +10 -138
- package/src/internal/dsl-query-runtime.ts +5 -79
- package/src/internal/dsl-transaction-ddl-runtime.ts +41 -65
- package/src/internal/executor.ts +66 -49
- package/src/internal/grouping-key.ts +87 -20
- package/src/internal/implication-runtime.ts +1 -1
- package/src/internal/json/path-access.ts +351 -0
- package/src/internal/predicate/runtime.ts +3 -0
- package/src/internal/query.d.ts +39 -12
- package/src/internal/query.ts +65 -26
- package/src/internal/renderer.ts +26 -14
- package/src/internal/runtime/driver-value-mapping.ts +3 -3
- package/src/internal/runtime/normalize.ts +12 -5
- 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 +8 -2
- package/src/internal/schema-derivation.d.ts +12 -61
- package/src/internal/schema-derivation.ts +95 -43
- package/src/internal/schema-expression.ts +2 -2
- package/src/internal/sql-expression-renderer.ts +19 -0
- package/src/internal/standard-dsl.ts +6978 -0
- package/src/internal/table-options.ts +126 -66
- package/src/internal/table.ts +819 -237
- package/src/mysql/column-extension.ts +3 -0
- package/src/mysql/column.ts +14 -15
- package/src/mysql/datatypes/index.ts +4 -2
- package/src/mysql/datatypes/spec.ts +6 -176
- package/src/mysql/errors/normalize.ts +0 -1
- package/src/mysql/executor.ts +11 -11
- package/src/mysql/function/temporal.ts +1 -1
- package/src/mysql/internal/dialect.ts +9 -4
- package/src/mysql/internal/dsl.ts +334 -170
- package/src/mysql/internal/renderer.ts +6 -2
- package/src/mysql/json.ts +7 -2
- package/src/mysql/query-extension.ts +16 -0
- package/src/mysql/renderer.ts +37 -3
- package/src/mysql/type.ts +60 -0
- package/src/mysql.ts +7 -13
- package/src/postgres/check.ts +1 -0
- package/src/postgres/column-extension.ts +28 -0
- package/src/postgres/column.ts +13 -19
- package/src/postgres/datatypes/index.d.ts +2 -1
- package/src/postgres/datatypes/index.ts +4 -2
- package/src/postgres/datatypes/spec.ts +6 -260
- package/src/postgres/errors/normalize.ts +0 -1
- package/src/postgres/executor.ts +11 -11
- package/src/postgres/foreign-key.ts +24 -0
- package/src/postgres/function/core.ts +1 -3
- package/src/postgres/function/index.ts +1 -17
- package/src/postgres/function/temporal.ts +1 -1
- package/src/postgres/index.ts +1 -0
- package/src/postgres/internal/dialect.ts +9 -4
- package/src/postgres/internal/dsl.ts +328 -179
- package/src/postgres/internal/renderer.ts +6 -2
- package/src/postgres/internal/schema-ddl.ts +22 -10
- package/src/postgres/internal/schema-model.ts +238 -7
- package/src/postgres/json-extension.ts +7 -0
- package/src/postgres/json.ts +762 -173
- package/src/postgres/jsonb.ts +37 -0
- package/src/postgres/primary-key.ts +24 -0
- package/src/postgres/query-extension.ts +2 -0
- package/src/postgres/renderer.ts +37 -3
- package/src/postgres/schema-management.ts +13 -13
- package/src/postgres/schema.ts +106 -15
- package/src/postgres/table.ts +205 -538
- package/src/postgres/type.ts +93 -10
- package/src/postgres/unique.ts +32 -0
- package/src/postgres.ts +20 -16
- package/src/sqlite/column-extension.ts +3 -0
- package/src/sqlite/column.ts +14 -15
- package/src/sqlite/datatypes/index.ts +4 -2
- package/src/sqlite/datatypes/spec.ts +6 -94
- package/src/sqlite/errors/normalize.ts +0 -1
- package/src/sqlite/executor.ts +11 -11
- package/src/sqlite/function/temporal.ts +1 -1
- package/src/sqlite/internal/dialect.ts +9 -4
- package/src/sqlite/internal/dsl.ts +307 -159
- package/src/sqlite/internal/renderer.ts +6 -2
- package/src/sqlite/json.ts +8 -2
- package/src/sqlite/query-extension.ts +2 -0
- package/src/sqlite/renderer.ts +37 -3
- package/src/sqlite/type.ts +40 -0
- package/src/sqlite.ts +7 -13
- package/src/standard/cast.ts +113 -0
- package/src/standard/check.ts +17 -0
- package/src/standard/column.ts +163 -0
- package/src/standard/datatypes/index.ts +83 -0
- package/src/standard/datatypes/spec.ts +12 -0
- package/src/standard/dialect.ts +40 -0
- package/src/standard/foreign-key.ts +37 -0
- package/src/standard/function/aggregate.ts +2 -0
- package/src/standard/function/core.ts +2 -0
- package/src/standard/function/index.ts +18 -0
- package/src/standard/function/string.ts +2 -0
- package/src/standard/function/temporal.ts +78 -0
- package/src/standard/function/window.ts +2 -0
- package/src/standard/index.ts +17 -0
- package/src/standard/internal/renderer.ts +45 -0
- package/src/standard/json.ts +883 -0
- package/src/standard/primary-key.ts +17 -0
- package/src/standard/query.ts +152 -0
- package/src/standard/renderer.ts +49 -0
- package/src/standard/table.ts +151 -0
- package/src/standard/unique.ts +17 -0
- package/src/standard.ts +32 -0
- package/src/internal/aggregation-validation.ts +0 -57
- package/src/internal/table.d.ts +0 -173
- package/src/mysql/table.ts +0 -183
- package/src/postgres/cast.ts +0 -45
- package/src/sqlite/table.ts +0 -183
package/src/mysql/column.ts
CHANGED
|
@@ -3,6 +3,8 @@ import * as Schema from "effect/Schema"
|
|
|
3
3
|
import * as BaseColumn from "../internal/column.js"
|
|
4
4
|
import { makeColumnDefinition, type AnyColumnDefinition, type ColumnDefinition } from "../internal/column-state.js"
|
|
5
5
|
import type * as Expression from "../internal/scalar.js"
|
|
6
|
+
import type { NonEmptyStringInput } from "../internal/table-options.js"
|
|
7
|
+
import { enrichDbType } from "../internal/datatypes/enrich.js"
|
|
6
8
|
import {
|
|
7
9
|
DecimalStringSchema,
|
|
8
10
|
LocalDateStringSchema,
|
|
@@ -13,15 +15,8 @@ import {
|
|
|
13
15
|
} from "../internal/runtime/value.js"
|
|
14
16
|
import { mysqlDatatypes } from "./datatypes/index.js"
|
|
15
17
|
|
|
16
|
-
const enrichDbType = <Db extends Expression.DbType.Any>(dbType: Db): Db => {
|
|
17
|
-
const candidate = (mysqlDatatypes as unknown as Record<string, (() => Expression.DbType.Any) | undefined>)[dbType.kind]
|
|
18
|
-
return typeof candidate === "function"
|
|
19
|
-
? { ...candidate(), ...dbType } as Db
|
|
20
|
-
: dbType
|
|
21
|
-
}
|
|
22
|
-
|
|
23
18
|
const primitive = <Type, Db extends Expression.DbType.Any>(
|
|
24
|
-
schema: Schema.Schema<Type
|
|
19
|
+
schema: Schema.Schema<Type>,
|
|
25
20
|
dbType: Db
|
|
26
21
|
): ColumnDefinition<Type, Type, Type, Db, false, false, false, false, false, undefined> =>
|
|
27
22
|
makeColumnDefinition(schema as Schema.Schema<NonNullable<Type>>, {
|
|
@@ -46,12 +41,12 @@ const renderNumericDdlType = (
|
|
|
46
41
|
: `${kind}(${options.precision},${options.scale})`
|
|
47
42
|
}
|
|
48
43
|
|
|
49
|
-
export const custom = <SchemaType extends Schema.
|
|
44
|
+
export const custom = <SchemaType extends Schema.Top, Db extends Expression.DbType.Any>(
|
|
50
45
|
schema: SchemaType,
|
|
51
46
|
dbType: Db
|
|
52
47
|
) =>
|
|
53
|
-
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType
|
|
54
|
-
dbType: enrichDbType(dbType),
|
|
48
|
+
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>>, {
|
|
49
|
+
dbType: enrichDbType(mysqlDatatypes, dbType),
|
|
55
50
|
nullable: false,
|
|
56
51
|
hasDefault: false,
|
|
57
52
|
generated: false,
|
|
@@ -62,7 +57,7 @@ export const custom = <SchemaType extends Schema.Schema.Any, Db extends Expressi
|
|
|
62
57
|
identity: undefined
|
|
63
58
|
})
|
|
64
59
|
|
|
65
|
-
export const uuid = () => primitive(Schema.
|
|
60
|
+
export const uuid = () => primitive(Schema.String.check(Schema.isUUID()), mysqlDatatypes.uuid())
|
|
66
61
|
export const text = () => primitive(Schema.String, mysqlDatatypes.text())
|
|
67
62
|
export const int = () => primitive(Schema.Int, mysqlDatatypes.int())
|
|
68
63
|
export const number = (options?: BaseColumn.NumericOptions) =>
|
|
@@ -81,8 +76,8 @@ export const boolean = () => primitive(Schema.Boolean, mysqlDatatypes.boolean())
|
|
|
81
76
|
export const date = () => primitive(LocalDateStringSchema, mysqlDatatypes.date())
|
|
82
77
|
export const datetime = () => primitive(LocalDateTimeStringSchema, mysqlDatatypes.datetime())
|
|
83
78
|
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
|
|
79
|
+
export const json = <SchemaType extends Schema.Top>(schema: SchemaType) =>
|
|
80
|
+
makeColumnDefinition(schema as unknown as Schema.Schema<NonNullable<Schema.Schema.Type<SchemaType>>>, {
|
|
86
81
|
dbType: { ...mysqlDatatypes.json(), variant: "json" } as Expression.DbType.Json<"mysql", "json">,
|
|
87
82
|
nullable: false,
|
|
88
83
|
hasDefault: false,
|
|
@@ -106,10 +101,14 @@ type MysqlUniqueOptions = {
|
|
|
106
101
|
readonly initiallyDeferred?: never
|
|
107
102
|
}
|
|
108
103
|
|
|
104
|
+
type NonEmptyOptionNameInput<Options> = Options extends { readonly name: infer Name extends string }
|
|
105
|
+
? NonEmptyStringInput<Name> extends never ? never : unknown
|
|
106
|
+
: unknown
|
|
107
|
+
|
|
109
108
|
type UniqueModifier = {
|
|
110
109
|
<Column extends AnyColumnDefinition>(column: Column): UniqueColumn<Column>
|
|
111
110
|
readonly options: <const Options extends MysqlUniqueOptions>(
|
|
112
|
-
options: Options
|
|
111
|
+
options: Options & NonEmptyOptionNameInput<Options>
|
|
113
112
|
) => <Column extends AnyColumnDefinition>(column: Column) => UniqueColumn<Column>
|
|
114
113
|
}
|
|
115
114
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DatatypeModule } from "../../internal/datatypes/define.js"
|
|
2
2
|
import type * as Expression from "../../internal/scalar.js"
|
|
3
|
+
import type { NonEmptyStringInput } from "../../internal/table-options.js"
|
|
3
4
|
import { mysqlDatatypeFamilies, mysqlDatatypeKinds } from "./spec.js"
|
|
4
5
|
|
|
5
6
|
const withMetadata = <Kind extends keyof typeof mysqlDatatypeKinds & string>(
|
|
@@ -14,14 +15,15 @@ const withMetadata = <Kind extends keyof typeof mysqlDatatypeKinds & string>(
|
|
|
14
15
|
runtime: kindSpec.runtime,
|
|
15
16
|
compareGroup: familySpec?.compareGroup,
|
|
16
17
|
castTargets: familySpec?.castTargets,
|
|
18
|
+
implicitTargets: (familySpec as { readonly implicitTargets?: readonly string[] }).implicitTargets,
|
|
17
19
|
traits: familySpec?.traits
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
const mysqlDatatypeModule = {
|
|
22
|
-
custom: (kind:
|
|
24
|
+
custom: <Kind extends string>(kind: NonEmptyStringInput<Kind>) => ({
|
|
23
25
|
dialect: "mysql",
|
|
24
|
-
kind
|
|
26
|
+
kind: kind as Kind
|
|
25
27
|
}),
|
|
26
28
|
uuid: () => ({
|
|
27
29
|
dialect: "mysql",
|
|
@@ -1,180 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
mysqlDatatypeFamilies as matrixMysqlDatatypeFamilies,
|
|
3
|
+
mysqlDatatypeKinds as matrixMysqlDatatypeKinds
|
|
4
|
+
} from "../../internal/datatypes/matrix.js"
|
|
2
5
|
|
|
3
|
-
export const mysqlDatatypeFamilies =
|
|
4
|
-
|
|
5
|
-
compareGroup: "text",
|
|
6
|
-
castTargets: [
|
|
7
|
-
"text",
|
|
8
|
-
"numeric",
|
|
9
|
-
"boolean",
|
|
10
|
-
"date",
|
|
11
|
-
"time",
|
|
12
|
-
"datetime",
|
|
13
|
-
"timestamp",
|
|
14
|
-
"year",
|
|
15
|
-
"binary",
|
|
16
|
-
"json",
|
|
17
|
-
"bit",
|
|
18
|
-
"enum",
|
|
19
|
-
"set",
|
|
20
|
-
"null"
|
|
21
|
-
],
|
|
22
|
-
traits: {
|
|
23
|
-
textual: true,
|
|
24
|
-
ordered: true
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
numeric: {
|
|
28
|
-
compareGroup: "numeric",
|
|
29
|
-
castTargets: ["numeric", "text", "boolean", "date", "time", "datetime", "timestamp", "year", "bit"],
|
|
30
|
-
traits: {
|
|
31
|
-
ordered: true
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
boolean: {
|
|
35
|
-
compareGroup: "boolean",
|
|
36
|
-
castTargets: ["boolean", "text", "numeric"],
|
|
37
|
-
traits: {}
|
|
38
|
-
},
|
|
39
|
-
bit: {
|
|
40
|
-
compareGroup: "bit",
|
|
41
|
-
castTargets: ["bit", "text", "numeric"],
|
|
42
|
-
traits: {}
|
|
43
|
-
},
|
|
44
|
-
date: {
|
|
45
|
-
compareGroup: "date",
|
|
46
|
-
castTargets: ["date", "datetime", "timestamp", "text"],
|
|
47
|
-
traits: {
|
|
48
|
-
ordered: true
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
time: {
|
|
52
|
-
compareGroup: "time",
|
|
53
|
-
castTargets: ["time", "datetime", "timestamp", "text"],
|
|
54
|
-
traits: {
|
|
55
|
-
ordered: true
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
datetime: {
|
|
59
|
-
compareGroup: "datetime",
|
|
60
|
-
castTargets: ["datetime", "timestamp", "date", "text"],
|
|
61
|
-
traits: {
|
|
62
|
-
ordered: true
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
timestamp: {
|
|
66
|
-
compareGroup: "timestamp",
|
|
67
|
-
castTargets: ["timestamp", "datetime", "date", "text"],
|
|
68
|
-
traits: {
|
|
69
|
-
ordered: true
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
year: {
|
|
73
|
-
compareGroup: "year",
|
|
74
|
-
castTargets: ["year", "text", "numeric"],
|
|
75
|
-
traits: {
|
|
76
|
-
ordered: true
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
binary: {
|
|
80
|
-
compareGroup: "binary",
|
|
81
|
-
castTargets: ["binary", "text"],
|
|
82
|
-
traits: {}
|
|
83
|
-
},
|
|
84
|
-
json: {
|
|
85
|
-
compareGroup: "json",
|
|
86
|
-
castTargets: ["json", "text"],
|
|
87
|
-
traits: {}
|
|
88
|
-
},
|
|
89
|
-
spatial: {
|
|
90
|
-
compareGroup: "spatial",
|
|
91
|
-
castTargets: ["spatial", "text"],
|
|
92
|
-
traits: {}
|
|
93
|
-
},
|
|
94
|
-
enum: {
|
|
95
|
-
compareGroup: "enum",
|
|
96
|
-
castTargets: ["enum", "text"],
|
|
97
|
-
traits: {
|
|
98
|
-
textual: true,
|
|
99
|
-
ordered: true
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
set: {
|
|
103
|
-
compareGroup: "set",
|
|
104
|
-
castTargets: ["set", "text"],
|
|
105
|
-
traits: {
|
|
106
|
-
textual: true
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
null: {
|
|
110
|
-
compareGroup: "null",
|
|
111
|
-
castTargets: [
|
|
112
|
-
"text",
|
|
113
|
-
"numeric",
|
|
114
|
-
"boolean",
|
|
115
|
-
"bit",
|
|
116
|
-
"date",
|
|
117
|
-
"time",
|
|
118
|
-
"datetime",
|
|
119
|
-
"timestamp",
|
|
120
|
-
"year",
|
|
121
|
-
"binary",
|
|
122
|
-
"json",
|
|
123
|
-
"spatial",
|
|
124
|
-
"enum",
|
|
125
|
-
"set",
|
|
126
|
-
"null"
|
|
127
|
-
],
|
|
128
|
-
traits: {}
|
|
129
|
-
}
|
|
130
|
-
} as const satisfies Record<string, DatatypeFamilySpec>
|
|
131
|
-
|
|
132
|
-
export const mysqlDatatypeKinds = {
|
|
133
|
-
char: { family: "text", runtime: "string" },
|
|
134
|
-
varchar: { family: "text", runtime: "string" },
|
|
135
|
-
tinytext: { family: "text", runtime: "string" },
|
|
136
|
-
text: { family: "text", runtime: "string" },
|
|
137
|
-
mediumtext: { family: "text", runtime: "string" },
|
|
138
|
-
longtext: { family: "text", runtime: "string" },
|
|
139
|
-
tinyint: { family: "numeric", runtime: "number" },
|
|
140
|
-
smallint: { family: "numeric", runtime: "number" },
|
|
141
|
-
mediumint: { family: "numeric", runtime: "number" },
|
|
142
|
-
int: { family: "numeric", runtime: "number" },
|
|
143
|
-
integer: { family: "numeric", runtime: "number" },
|
|
144
|
-
bigint: { family: "numeric", runtime: "bigintString" },
|
|
145
|
-
decimal: { family: "numeric", runtime: "decimalString" },
|
|
146
|
-
dec: { family: "numeric", runtime: "decimalString" },
|
|
147
|
-
numeric: { family: "numeric", runtime: "decimalString" },
|
|
148
|
-
fixed: { family: "numeric", runtime: "decimalString" },
|
|
149
|
-
float: { family: "numeric", runtime: "number" },
|
|
150
|
-
double: { family: "numeric", runtime: "number" },
|
|
151
|
-
real: { family: "numeric", runtime: "number" },
|
|
152
|
-
bool: { family: "boolean", runtime: "boolean" },
|
|
153
|
-
boolean: { family: "boolean", runtime: "boolean" },
|
|
154
|
-
bit: { family: "bit", runtime: "string" },
|
|
155
|
-
date: { family: "date", runtime: "localDate" },
|
|
156
|
-
time: { family: "time", runtime: "localTime" },
|
|
157
|
-
datetime: { family: "datetime", runtime: "localDateTime" },
|
|
158
|
-
timestamp: { family: "timestamp", runtime: "localDateTime" },
|
|
159
|
-
year: { family: "year", runtime: "year" },
|
|
160
|
-
binary: { family: "binary", runtime: "bytes" },
|
|
161
|
-
varbinary: { family: "binary", runtime: "bytes" },
|
|
162
|
-
tinyblob: { family: "binary", runtime: "bytes" },
|
|
163
|
-
blob: { family: "binary", runtime: "bytes" },
|
|
164
|
-
mediumblob: { family: "binary", runtime: "bytes" },
|
|
165
|
-
longblob: { family: "binary", runtime: "bytes" },
|
|
166
|
-
json: { family: "json", runtime: "json" },
|
|
167
|
-
geometry: { family: "spatial", runtime: "unknown" },
|
|
168
|
-
point: { family: "spatial", runtime: "unknown" },
|
|
169
|
-
linestring: { family: "spatial", runtime: "unknown" },
|
|
170
|
-
polygon: { family: "spatial", runtime: "unknown" },
|
|
171
|
-
multipoint: { family: "spatial", runtime: "unknown" },
|
|
172
|
-
multilinestring: { family: "spatial", runtime: "unknown" },
|
|
173
|
-
multipolygon: { family: "spatial", runtime: "unknown" },
|
|
174
|
-
geometrycollection: { family: "spatial", runtime: "unknown" },
|
|
175
|
-
enum: { family: "enum", runtime: "string" },
|
|
176
|
-
set: { family: "set", runtime: "string" }
|
|
177
|
-
} as const satisfies Record<string, DatatypeKindSpec>
|
|
6
|
+
export const mysqlDatatypeFamilies = matrixMysqlDatatypeFamilies
|
|
7
|
+
export const mysqlDatatypeKinds = matrixMysqlDatatypeKinds
|
|
178
8
|
|
|
179
9
|
export type MysqlDatatypeFamily = keyof typeof mysqlDatatypeFamilies
|
|
180
10
|
export type MysqlDatatypeKind = keyof typeof mysqlDatatypeKinds
|
package/src/mysql/executor.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
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"
|
|
6
6
|
import * as CoreQuery from "../internal/query.js"
|
|
7
7
|
import * as CoreRenderer from "../internal/renderer.js"
|
|
8
8
|
import type * as Expression from "../internal/scalar.js"
|
|
9
|
+
import type { MysqlDatatypeFamily, MysqlDatatypeKind } from "./datatypes/spec.js"
|
|
9
10
|
import { renderMysqlPlan } from "./internal/renderer.js"
|
|
10
11
|
import {
|
|
11
12
|
narrowMysqlDriverErrorForReadQuery,
|
|
@@ -24,12 +25,13 @@ export type Driver<Error = never, Context = never> = CoreExecutor.Driver<"mysql"
|
|
|
24
25
|
export type Executor<Error = never, Context = never> = CoreExecutor.Executor<"mysql", Error, Context>
|
|
25
26
|
/** MySQL-specialized renderer contract. */
|
|
26
27
|
export type Renderer = CoreRenderer.Renderer<"mysql">
|
|
28
|
+
export type ValueMappings = Expression.DriverValueMappingsFor<MysqlDatatypeKind | "uuid", MysqlDatatypeFamily | "uuid">
|
|
27
29
|
/** Optional renderer / driver overrides for the standard MySQL executor pipeline. */
|
|
28
30
|
export interface MakeOptions<Error = never, Context = never> {
|
|
29
31
|
readonly renderer?: Renderer
|
|
30
32
|
readonly driver?: Driver<Error, Context>
|
|
31
33
|
readonly driverMode?: CoreExecutor.DriverMode
|
|
32
|
-
readonly valueMappings?:
|
|
34
|
+
readonly valueMappings?: ValueMappings
|
|
33
35
|
}
|
|
34
36
|
/** Standard composed error shape for MySQL executors. */
|
|
35
37
|
export type MysqlExecutorError = MysqlDriverError | RowDecodeError
|
|
@@ -39,8 +41,6 @@ export type MysqlQueryError<PlanValue extends CoreQuery.QueryPlan<any, any, any,
|
|
|
39
41
|
|
|
40
42
|
/** Runs an effect within the ambient MySQL SQL transaction service. */
|
|
41
43
|
export const withTransaction = CoreExecutor.withTransaction
|
|
42
|
-
/** Runs an effect in a nested MySQL SQL transaction scope. */
|
|
43
|
-
export const withSavepoint = CoreExecutor.withSavepoint
|
|
44
44
|
|
|
45
45
|
/** MySQL executor whose error channel narrows based on the query plan. */
|
|
46
46
|
export interface QueryExecutor<Context = never> {
|
|
@@ -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>
|
|
@@ -172,7 +172,7 @@ export function make(
|
|
|
172
172
|
options: {
|
|
173
173
|
readonly renderer?: Renderer
|
|
174
174
|
readonly driverMode?: CoreExecutor.DriverMode
|
|
175
|
-
readonly valueMappings?:
|
|
175
|
+
readonly valueMappings?: ValueMappings
|
|
176
176
|
}
|
|
177
177
|
): QueryExecutor<SqlClient.SqlClient>
|
|
178
178
|
export function make<Error = never, Context = never>(
|
|
@@ -180,7 +180,7 @@ export function make<Error = never, Context = never>(
|
|
|
180
180
|
readonly renderer?: Renderer
|
|
181
181
|
readonly driver: Driver<Error, Context>
|
|
182
182
|
readonly driverMode?: CoreExecutor.DriverMode
|
|
183
|
-
readonly valueMappings?:
|
|
183
|
+
readonly valueMappings?: ValueMappings
|
|
184
184
|
}
|
|
185
185
|
): QueryExecutor<Context>
|
|
186
186
|
export function make<Error = never, Context = never>(
|
|
@@ -188,14 +188,14 @@ export function make<Error = never, Context = never>(
|
|
|
188
188
|
): QueryExecutor<any> {
|
|
189
189
|
if (options.driver) {
|
|
190
190
|
return fromDriver(
|
|
191
|
-
options.renderer ?? CoreRenderer.
|
|
191
|
+
options.renderer ?? CoreRenderer.makeTrusted("mysql", (plan) => renderMysqlPlan(plan, { valueMappings: options.valueMappings })),
|
|
192
192
|
options.driver,
|
|
193
193
|
options.driverMode,
|
|
194
194
|
options.valueMappings
|
|
195
195
|
)
|
|
196
196
|
}
|
|
197
197
|
return fromDriver(
|
|
198
|
-
options.renderer ?? CoreRenderer.
|
|
198
|
+
options.renderer ?? CoreRenderer.makeTrusted("mysql", (plan) => renderMysqlPlan(plan, { valueMappings: options.valueMappings })),
|
|
199
199
|
sqlClientDriver(),
|
|
200
200
|
options.driverMode,
|
|
201
201
|
options.valueMappings
|
|
@@ -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,
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { quoteBacktickIdentifier, type RenderState, type RenderValueContext, type SqlDialect } from "../../internal/dialect.js"
|
|
2
|
+
import { renderExpression, renderQueryAst } from "../../internal/dialect-renderers/mysql.js"
|
|
2
3
|
import { toDriverValue } from "../../internal/runtime/driver-value-mapping.js"
|
|
4
|
+
import { standardDialect } from "../../standard/dialect.js"
|
|
3
5
|
|
|
4
|
-
const quoteIdentifier =
|
|
6
|
+
const quoteIdentifier = quoteBacktickIdentifier
|
|
5
7
|
|
|
6
8
|
const renderLiteral = (value: unknown, state: RenderState, context: RenderValueContext = {}): string => {
|
|
7
9
|
const driverValue = toDriverValue(value, {
|
|
@@ -28,11 +30,12 @@ const renderLiteral = (value: unknown, state: RenderState, context: RenderValueC
|
|
|
28
30
|
* grows.
|
|
29
31
|
*/
|
|
30
32
|
export const mysqlDialect: SqlDialect<"mysql"> = {
|
|
33
|
+
...standardDialect,
|
|
31
34
|
name: "mysql",
|
|
32
35
|
quoteIdentifier,
|
|
33
36
|
renderLiteral,
|
|
34
37
|
renderTableReference(tableName, baseTableName, schemaName) {
|
|
35
|
-
const renderedBase = schemaName
|
|
38
|
+
const renderedBase = schemaName && schemaName !== "public"
|
|
36
39
|
? `${quoteIdentifier(schemaName)}.${quoteIdentifier(baseTableName)}`
|
|
37
40
|
: quoteIdentifier(baseTableName)
|
|
38
41
|
return tableName === baseTableName
|
|
@@ -41,5 +44,7 @@ export const mysqlDialect: SqlDialect<"mysql"> = {
|
|
|
41
44
|
},
|
|
42
45
|
renderConcat(values) {
|
|
43
46
|
return `concat(${values.join(", ")})`
|
|
44
|
-
}
|
|
47
|
+
},
|
|
48
|
+
renderQueryAst,
|
|
49
|
+
renderExpression
|
|
45
50
|
}
|