effect-qb 0.14.0 → 0.15.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/dist/mysql.js +61270 -4259
- package/dist/postgres/metadata.js +176 -82
- package/dist/postgres.js +5903 -3316
- package/package.json +14 -1
- package/src/internal/aggregation-validation.ts +3 -3
- package/src/internal/case-analysis.d.ts +18 -0
- package/src/internal/case-analysis.ts +4 -4
- package/src/internal/coercion/analysis.d.ts +7 -0
- package/src/internal/{coercion-analysis.ts → coercion/analysis.ts} +3 -3
- package/src/internal/coercion/errors.d.ts +17 -0
- package/src/internal/{coercion-errors.ts → coercion/errors.ts} +1 -1
- package/src/internal/coercion/kind.d.ts +4 -0
- package/src/internal/{coercion-kind.ts → coercion/kind.ts} +2 -2
- package/src/internal/{coercion-normalize.ts → coercion/normalize.ts} +1 -1
- package/src/internal/coercion/rules.d.ts +6 -0
- package/src/internal/{coercion-rules.ts → coercion/rules.ts} +2 -2
- package/src/internal/column-state.d.ts +190 -0
- package/src/internal/column-state.ts +36 -47
- package/src/internal/column.ts +21 -305
- package/src/internal/datatypes/define.d.ts +17 -0
- package/src/internal/datatypes/define.ts +18 -4
- package/src/internal/datatypes/lookup.d.ts +44 -0
- package/src/internal/datatypes/lookup.ts +61 -152
- package/src/internal/datatypes/shape.d.ts +16 -0
- package/src/internal/datatypes/shape.ts +1 -1
- package/src/internal/derived-table.d.ts +4 -0
- package/src/internal/derived-table.ts +21 -16
- package/src/internal/dsl-mutation-runtime.ts +378 -0
- package/src/internal/dsl-plan-runtime.ts +387 -0
- package/src/internal/dsl-query-runtime.ts +160 -0
- package/src/internal/dsl-transaction-ddl-runtime.ts +263 -0
- package/src/internal/executor.ts +132 -31
- package/src/internal/expression-ast.ts +15 -5
- package/src/internal/grouping-key.d.ts +3 -0
- package/src/internal/grouping-key.ts +1 -1
- package/src/internal/implication-runtime.d.ts +15 -0
- package/src/internal/implication-runtime.ts +4 -4
- package/src/internal/json/ast.d.ts +30 -0
- package/src/internal/json/ast.ts +1 -1
- package/src/internal/json/errors.d.ts +8 -0
- package/src/internal/json/path.d.ts +75 -0
- package/src/internal/json/path.ts +1 -1
- package/src/internal/json/types.d.ts +62 -0
- package/src/internal/predicate/analysis.d.ts +20 -0
- package/src/internal/{predicate-analysis.ts → predicate/analysis.ts} +3 -3
- package/src/internal/predicate/atom.d.ts +28 -0
- package/src/internal/{predicate-branches.ts → predicate/branches.ts} +2 -2
- package/src/internal/predicate/context.d.ts +67 -0
- package/src/internal/{predicate-context.ts → predicate/context.ts} +8 -5
- package/src/internal/predicate/formula.d.ts +35 -0
- package/src/internal/{predicate-formula.ts → predicate/formula.ts} +1 -1
- package/src/internal/predicate/key.d.ts +11 -0
- package/src/internal/{predicate-key.ts → predicate/key.ts} +2 -2
- package/src/internal/{predicate-nnf.ts → predicate/nnf.ts} +2 -2
- package/src/internal/predicate/normalize.d.ts +53 -0
- package/src/internal/{predicate-normalize.ts → predicate/normalize.ts} +19 -19
- package/src/internal/predicate/runtime.d.ts +31 -0
- package/src/internal/{predicate-runtime.ts → predicate/runtime.ts} +9 -6
- package/src/internal/projection-alias.d.ts +13 -0
- package/src/internal/projections.d.ts +31 -0
- package/src/internal/projections.ts +1 -1
- package/src/internal/query-ast.d.ts +217 -0
- package/src/internal/query-ast.ts +1 -1
- package/src/internal/query-requirements.d.ts +20 -0
- package/src/internal/query.d.ts +775 -0
- package/src/internal/query.ts +389 -313
- package/src/internal/renderer.ts +7 -21
- package/src/internal/row-set.d.ts +53 -0
- package/src/internal/{plan.ts → row-set.ts} +11 -9
- package/src/internal/{runtime-normalize.ts → runtime/normalize.ts} +9 -31
- package/src/internal/{runtime-schema.ts → runtime/schema.ts} +13 -38
- package/src/internal/runtime/value.d.ts +22 -0
- package/src/internal/{runtime-value.ts → runtime/value.ts} +2 -2
- package/src/internal/scalar.d.ts +107 -0
- package/src/internal/scalar.ts +191 -0
- package/src/internal/schema-derivation.d.ts +105 -0
- package/src/internal/schema-expression.d.ts +18 -0
- package/src/internal/schema-expression.ts +38 -7
- package/src/internal/table-options.d.ts +94 -0
- package/src/internal/table-options.ts +8 -2
- package/src/internal/table.d.ts +173 -0
- package/src/internal/table.ts +32 -14
- package/src/mysql/column.ts +94 -18
- package/src/mysql/datatypes/index.ts +47 -7
- package/src/mysql/errors/generated.ts +57336 -0
- package/src/mysql/errors/index.ts +1 -0
- package/src/mysql/errors/normalize.ts +55 -53
- package/src/mysql/errors/types.ts +74 -0
- package/src/mysql/executor.ts +69 -7
- package/src/mysql/function/aggregate.ts +1 -5
- package/src/mysql/function/core.ts +1 -4
- package/src/mysql/function/index.ts +0 -1
- package/src/mysql/function/string.ts +1 -5
- package/src/mysql/function/temporal.ts +12 -15
- package/src/mysql/function/window.ts +1 -6
- package/src/{internal/mysql-dialect.ts → mysql/internal/dialect.ts} +1 -1
- package/src/{internal/mysql-query.ts → mysql/internal/dsl.ts} +1024 -2082
- package/src/{internal/mysql-renderer.ts → mysql/internal/renderer.ts} +6 -6
- package/src/mysql/internal/sql-expression-renderer.ts +1455 -0
- package/src/mysql/json.ts +2 -0
- package/src/mysql/query.ts +111 -91
- package/src/mysql/renderer.ts +1 -1
- package/src/mysql/table.ts +1 -1
- package/src/mysql.ts +6 -4
- package/src/postgres/cast.ts +11 -12
- package/src/postgres/column.ts +178 -46
- package/src/postgres/datatypes/index.d.ts +515 -0
- package/src/postgres/datatypes/index.ts +22 -13
- package/src/postgres/datatypes/spec.d.ts +412 -0
- package/src/postgres/errors/generated.ts +2636 -0
- package/src/postgres/errors/index.ts +1 -0
- package/src/postgres/errors/normalize.ts +47 -62
- package/src/postgres/errors/types.ts +92 -34
- package/src/postgres/executor.ts +37 -5
- package/src/postgres/function/aggregate.ts +1 -5
- package/src/postgres/function/core.ts +12 -6
- package/src/postgres/function/index.ts +0 -1
- package/src/postgres/function/string.ts +1 -5
- package/src/postgres/function/temporal.ts +12 -15
- package/src/postgres/function/window.ts +1 -6
- package/src/{internal/postgres-dialect.ts → postgres/internal/dialect.ts} +1 -1
- package/src/{internal/postgres-query.ts → postgres/internal/dsl.ts} +1085 -2089
- package/src/{internal/postgres-renderer.ts → postgres/internal/renderer.ts} +6 -6
- package/src/postgres/internal/schema-ddl.ts +108 -0
- package/src/{internal/postgres-schema-model.ts → postgres/internal/schema-model.ts} +12 -6
- package/src/{internal → postgres/internal}/sql-expression-renderer.ts +19 -17
- package/src/postgres/{function/json.ts → json.ts} +77 -85
- package/src/postgres/metadata.ts +2 -2
- package/src/postgres/query.ts +113 -89
- package/src/postgres/renderer.ts +3 -13
- package/src/postgres/schema-expression.ts +2 -1
- package/src/postgres/schema-management.ts +1 -1
- package/src/postgres/table.ts +12 -4
- package/src/postgres/type.ts +29 -2
- package/src/postgres.ts +6 -4
- package/src/internal/expression.ts +0 -327
- package/src/internal/schema-ddl.ts +0 -55
- package/src/mysql/function/json.ts +0 -4
- package/src/mysql/private/query.ts +0 -1
- package/src/postgres/private/query.ts +0 -1
- /package/src/internal/{predicate-atom.ts → predicate/atom.ts} +0 -0
|
@@ -9,14 +9,35 @@ import {
|
|
|
9
9
|
type MysqlErrorSymbol,
|
|
10
10
|
type MysqlErrorTag
|
|
11
11
|
} from "./catalog.js"
|
|
12
|
+
import {
|
|
13
|
+
mysqlKnownErrorClassesBySymbol,
|
|
14
|
+
type KnownMysqlErrorBySymbol as ExactKnownMysqlErrorBySymbol
|
|
15
|
+
} from "./generated.js"
|
|
12
16
|
import type {
|
|
13
17
|
MysqlErrorFields,
|
|
14
18
|
MysqlQueryContext
|
|
15
19
|
} from "./fields.js"
|
|
20
|
+
import type {
|
|
21
|
+
MysqlErrorLike,
|
|
22
|
+
MysqlKnownErrorBase
|
|
23
|
+
} from "./types.js"
|
|
16
24
|
|
|
17
25
|
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
18
26
|
typeof value === "object" && value !== null
|
|
19
27
|
|
|
28
|
+
const unwrapMysqlDriverCause = (cause: unknown): unknown => {
|
|
29
|
+
let current = cause
|
|
30
|
+
while (
|
|
31
|
+
isRecord(current) &&
|
|
32
|
+
"_tag" in current &&
|
|
33
|
+
current._tag === "SqlError" &&
|
|
34
|
+
"cause" in current
|
|
35
|
+
) {
|
|
36
|
+
current = current.cause
|
|
37
|
+
}
|
|
38
|
+
return current
|
|
39
|
+
}
|
|
40
|
+
|
|
20
41
|
const asString = (value: unknown): string | undefined =>
|
|
21
42
|
typeof value === "string" ? value : undefined
|
|
22
43
|
|
|
@@ -46,36 +67,16 @@ const normalizeFields = (error: Record<string, unknown>): MysqlErrorFields => ({
|
|
|
46
67
|
hostname: asString(error.hostname)
|
|
47
68
|
})
|
|
48
69
|
|
|
49
|
-
|
|
50
|
-
export interface MysqlErrorLike {
|
|
51
|
-
readonly code?: string
|
|
52
|
-
readonly errno?: string | number
|
|
53
|
-
readonly sqlState?: string
|
|
54
|
-
readonly sqlMessage?: string
|
|
55
|
-
readonly message?: string
|
|
56
|
-
readonly fatal?: boolean
|
|
57
|
-
readonly sql?: string
|
|
58
|
-
readonly syscall?: string
|
|
59
|
-
readonly address?: string
|
|
60
|
-
readonly port?: string | number
|
|
61
|
-
readonly hostname?: string
|
|
62
|
-
}
|
|
70
|
+
export type { MysqlErrorLike } from "./types.js"
|
|
63
71
|
|
|
64
72
|
/** Structured known MySQL error derived from the generated official catalog. */
|
|
65
|
-
export type KnownMysqlError<Symbol extends MysqlErrorSymbol = MysqlErrorSymbol> =
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
readonly symbol: Symbol
|
|
70
|
-
readonly documentedSqlState: MysqlErrorDescriptor<Symbol>["sqlState"]
|
|
71
|
-
readonly messageTemplate: MysqlErrorDescriptor<Symbol>["messageTemplate"]
|
|
72
|
-
readonly message: string
|
|
73
|
-
readonly query?: MysqlQueryContext
|
|
74
|
-
readonly raw: MysqlErrorLike
|
|
75
|
-
} & MysqlErrorFields>
|
|
73
|
+
export type KnownMysqlError<Symbol extends MysqlErrorSymbol = MysqlErrorSymbol> =
|
|
74
|
+
[MysqlErrorSymbol] extends [Symbol]
|
|
75
|
+
? MysqlKnownErrorBase
|
|
76
|
+
: ExactKnownMysqlErrorBySymbol<Symbol>
|
|
76
77
|
|
|
77
78
|
/** Extracts the normalized MySQL error variant for a specific symbol. */
|
|
78
|
-
export type KnownMysqlErrorBySymbol<Symbol extends MysqlErrorSymbol> =
|
|
79
|
+
export type KnownMysqlErrorBySymbol<Symbol extends MysqlErrorSymbol> = ExactKnownMysqlErrorBySymbol<Symbol>
|
|
79
80
|
|
|
80
81
|
/** MySQL-like error whose symbol or number is not in the current catalog. */
|
|
81
82
|
export type UnknownMysqlCodeError = Readonly<{
|
|
@@ -153,64 +154,62 @@ const findDescriptor = (error: MysqlErrorLike): MysqlErrorDescriptor | undefined
|
|
|
153
154
|
return undefined
|
|
154
155
|
}
|
|
155
156
|
|
|
156
|
-
const makeKnownMysqlError =
|
|
157
|
-
descriptor: MysqlErrorDescriptor
|
|
157
|
+
const makeKnownMysqlError = (
|
|
158
|
+
descriptor: MysqlErrorDescriptor,
|
|
158
159
|
raw: MysqlErrorLike,
|
|
159
160
|
query?: MysqlQueryContext
|
|
160
|
-
):
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
...normalizeFields(raw as Record<string, unknown>),
|
|
171
|
-
sqlState: asString(raw.sqlState) ?? descriptor.sqlState
|
|
172
|
-
}) as KnownMysqlError<Symbol>
|
|
161
|
+
): MysqlKnownErrorBase => {
|
|
162
|
+
const ErrorClass = mysqlKnownErrorClassesBySymbol[descriptor.symbol]
|
|
163
|
+
return new ErrorClass({
|
|
164
|
+
message: errorMessageOf(raw),
|
|
165
|
+
query,
|
|
166
|
+
raw,
|
|
167
|
+
...normalizeFields(raw as Record<string, unknown>),
|
|
168
|
+
sqlState: asString(raw.sqlState) ?? descriptor.sqlState
|
|
169
|
+
}) as MysqlKnownErrorBase
|
|
170
|
+
}
|
|
173
171
|
|
|
174
172
|
/** Normalizes an unknown failure into a structured MySQL driver error. */
|
|
175
173
|
export const normalizeMysqlDriverError = (
|
|
176
174
|
cause: unknown,
|
|
177
175
|
query?: MysqlQueryContext | Renderer.RenderedQuery<any, "mysql">
|
|
178
176
|
): MysqlDriverError => {
|
|
177
|
+
const normalizedCause = unwrapMysqlDriverCause(cause)
|
|
179
178
|
const context = query === undefined
|
|
180
179
|
? undefined
|
|
181
180
|
: "sql" in query
|
|
182
181
|
? { sql: query.sql, params: query.params }
|
|
183
182
|
: query
|
|
184
183
|
|
|
185
|
-
if (!isMysqlErrorLike(
|
|
184
|
+
if (!isMysqlErrorLike(normalizedCause)) {
|
|
186
185
|
return {
|
|
187
186
|
_tag: "@mysql/unknown/driver",
|
|
188
|
-
message:
|
|
187
|
+
message: normalizedCause instanceof Error ? normalizedCause.message : "Unknown MySQL driver failure",
|
|
189
188
|
query: context,
|
|
190
189
|
cause
|
|
191
190
|
} as UnknownMysqlDriverError
|
|
192
191
|
}
|
|
193
192
|
|
|
194
|
-
const descriptor = findDescriptor(
|
|
193
|
+
const descriptor = findDescriptor(normalizedCause)
|
|
195
194
|
if (descriptor !== undefined) {
|
|
196
|
-
return makeKnownMysqlError(descriptor,
|
|
195
|
+
return makeKnownMysqlError(descriptor, normalizedCause, context)
|
|
197
196
|
}
|
|
198
197
|
|
|
199
|
-
if (typeof
|
|
198
|
+
if (typeof normalizedCause.code === "string" || numberOf(normalizedCause) !== undefined) {
|
|
200
199
|
return {
|
|
201
200
|
_tag: "@mysql/unknown/code",
|
|
202
|
-
code: asString(
|
|
203
|
-
errno:
|
|
204
|
-
message: errorMessageOf(
|
|
201
|
+
code: asString(normalizedCause.code),
|
|
202
|
+
errno: normalizedCause.errno,
|
|
203
|
+
message: errorMessageOf(normalizedCause),
|
|
205
204
|
query: context,
|
|
206
|
-
raw:
|
|
207
|
-
...normalizeFields(
|
|
205
|
+
raw: normalizedCause,
|
|
206
|
+
...normalizeFields(normalizedCause as Record<string, unknown>)
|
|
208
207
|
} as UnknownMysqlCodeError
|
|
209
208
|
}
|
|
210
209
|
|
|
211
210
|
return {
|
|
212
211
|
_tag: "@mysql/unknown/driver",
|
|
213
|
-
message: errorMessageOf(
|
|
212
|
+
message: errorMessageOf(normalizedCause),
|
|
214
213
|
query: context,
|
|
215
214
|
cause
|
|
216
215
|
} as UnknownMysqlDriverError
|
|
@@ -221,7 +220,10 @@ export const hasSymbol = <Symbol extends MysqlErrorSymbol>(
|
|
|
221
220
|
error: MysqlDriverError | { readonly symbol?: string },
|
|
222
221
|
symbol: Symbol
|
|
223
222
|
): error is KnownMysqlErrorBySymbol<Symbol> =>
|
|
224
|
-
|
|
223
|
+
(typeof error === "object" &&
|
|
224
|
+
error !== null &&
|
|
225
|
+
error instanceof mysqlKnownErrorClassesBySymbol[symbol]) ||
|
|
226
|
+
("symbol" in error && error.symbol === symbol)
|
|
225
227
|
|
|
226
228
|
/** Type guard for a specific documented MySQL error number. */
|
|
227
229
|
export const hasNumber = <Number extends MysqlErrorNumber>(
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { MysqlErrorNumber, MysqlErrorSymbol, MysqlErrorTag } from "./catalog.js"
|
|
2
|
+
import type { MysqlErrorFields, MysqlQueryContext } from "./fields.js"
|
|
3
|
+
|
|
4
|
+
/** Raw MySQL-like error shape as commonly exposed by client libraries. */
|
|
5
|
+
export interface MysqlErrorLike {
|
|
6
|
+
readonly code?: string
|
|
7
|
+
readonly errno?: string | number
|
|
8
|
+
readonly sqlState?: string
|
|
9
|
+
readonly sqlMessage?: string
|
|
10
|
+
readonly message?: string
|
|
11
|
+
readonly fatal?: boolean
|
|
12
|
+
readonly sql?: string
|
|
13
|
+
readonly syscall?: string
|
|
14
|
+
readonly address?: string
|
|
15
|
+
readonly port?: string | number
|
|
16
|
+
readonly hostname?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Broad known-MySQL error surface used by the normalizer return type. */
|
|
20
|
+
export interface MysqlKnownErrorBase extends Error, MysqlErrorFields {
|
|
21
|
+
readonly _tag: MysqlErrorTag
|
|
22
|
+
readonly category: "server" | "client" | "global"
|
|
23
|
+
readonly number: MysqlErrorNumber
|
|
24
|
+
readonly symbol: MysqlErrorSymbol
|
|
25
|
+
readonly documentedSqlState?: string
|
|
26
|
+
readonly messageTemplate: string
|
|
27
|
+
readonly message: string
|
|
28
|
+
readonly query?: MysqlQueryContext
|
|
29
|
+
readonly raw: MysqlErrorLike
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Shared constructor payload for generated MySQL error classes. */
|
|
33
|
+
export type MysqlKnownErrorArgs = Readonly<{
|
|
34
|
+
readonly message: string
|
|
35
|
+
readonly query?: MysqlQueryContext
|
|
36
|
+
readonly raw: MysqlErrorLike
|
|
37
|
+
} & MysqlErrorFields>
|
|
38
|
+
|
|
39
|
+
/** Runtime base class shared by generated MySQL error classes. */
|
|
40
|
+
export abstract class MysqlKnownErrorClass extends Error implements MysqlKnownErrorBase {
|
|
41
|
+
abstract readonly _tag: MysqlErrorTag
|
|
42
|
+
abstract readonly category: "server" | "client" | "global"
|
|
43
|
+
abstract readonly number: MysqlErrorNumber
|
|
44
|
+
abstract readonly symbol: MysqlErrorSymbol
|
|
45
|
+
abstract readonly documentedSqlState?: string
|
|
46
|
+
abstract readonly messageTemplate: string
|
|
47
|
+
readonly errno?
|
|
48
|
+
readonly sqlState?
|
|
49
|
+
readonly sqlMessage?
|
|
50
|
+
readonly fatal?
|
|
51
|
+
readonly sql?
|
|
52
|
+
readonly syscall?
|
|
53
|
+
readonly address?
|
|
54
|
+
readonly port?
|
|
55
|
+
readonly hostname?
|
|
56
|
+
readonly query?
|
|
57
|
+
readonly raw
|
|
58
|
+
|
|
59
|
+
constructor(args: MysqlKnownErrorArgs) {
|
|
60
|
+
super(args.message)
|
|
61
|
+
this.name = new.target.name
|
|
62
|
+
this.errno = args.errno
|
|
63
|
+
this.sqlState = args.sqlState
|
|
64
|
+
this.sqlMessage = args.sqlMessage
|
|
65
|
+
this.fatal = args.fatal
|
|
66
|
+
this.sql = args.sql
|
|
67
|
+
this.syscall = args.syscall
|
|
68
|
+
this.address = args.address
|
|
69
|
+
this.port = args.port
|
|
70
|
+
this.hostname = args.hostname
|
|
71
|
+
this.query = args.query
|
|
72
|
+
this.raw = args.raw
|
|
73
|
+
}
|
|
74
|
+
}
|
package/src/mysql/executor.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect"
|
|
2
2
|
import * as SqlClient from "@effect/sql/SqlClient"
|
|
3
|
+
import * as Stream from "effect/Stream"
|
|
3
4
|
|
|
4
5
|
import * as CoreExecutor from "../internal/executor.js"
|
|
5
6
|
import * as CoreQuery from "../internal/query.js"
|
|
6
7
|
import * as CoreRenderer from "../internal/renderer.js"
|
|
7
|
-
import { renderMysqlPlan } from "
|
|
8
|
+
import { renderMysqlPlan } from "./internal/renderer.js"
|
|
8
9
|
import {
|
|
9
10
|
narrowMysqlDriverErrorForReadQuery,
|
|
10
11
|
normalizeMysqlDriverError,
|
|
@@ -45,18 +46,54 @@ export interface QueryExecutor<Context = never> {
|
|
|
45
46
|
execute<PlanValue extends CoreQuery.QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
46
47
|
plan: CoreQuery.DialectCompatiblePlan<PlanValue, "mysql">
|
|
47
48
|
): Effect.Effect<CoreQuery.ResultRows<PlanValue>, MysqlQueryError<PlanValue>, Context>
|
|
49
|
+
stream<PlanValue extends CoreQuery.QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
50
|
+
plan: Exclude<CoreQuery.CapabilitiesOfPlan<PlanValue>, "read" | "locking"> extends never
|
|
51
|
+
? CoreQuery.DialectCompatiblePlan<PlanValue, "mysql">
|
|
52
|
+
: never
|
|
53
|
+
): Stream.Stream<CoreQuery.ResultRow<PlanValue>, MysqlQueryError<PlanValue>, Context>
|
|
48
54
|
}
|
|
49
55
|
|
|
50
56
|
/** Constructs a MySQL-specialized SQL driver. */
|
|
51
|
-
export
|
|
57
|
+
export function driver<
|
|
52
58
|
Error = never,
|
|
53
59
|
Context = never
|
|
54
60
|
>(
|
|
55
61
|
execute: <Row>(
|
|
56
62
|
query: CoreRenderer.RenderedQuery<Row, "mysql">
|
|
57
63
|
) => Effect.Effect<ReadonlyArray<FlatRow>, Error, Context>
|
|
58
|
-
): Driver<Error, Context>
|
|
59
|
-
|
|
64
|
+
): Driver<Error, Context>
|
|
65
|
+
export function driver<
|
|
66
|
+
Error = never,
|
|
67
|
+
Context = never
|
|
68
|
+
>(
|
|
69
|
+
handlers: {
|
|
70
|
+
readonly execute: <Row>(
|
|
71
|
+
query: CoreRenderer.RenderedQuery<Row, "mysql">
|
|
72
|
+
) => Effect.Effect<ReadonlyArray<FlatRow>, Error, Context>
|
|
73
|
+
readonly stream: <Row>(
|
|
74
|
+
query: CoreRenderer.RenderedQuery<Row, "mysql">
|
|
75
|
+
) => Stream.Stream<FlatRow, Error, Context>
|
|
76
|
+
}
|
|
77
|
+
): Driver<Error, Context>
|
|
78
|
+
export function driver<
|
|
79
|
+
Error = never,
|
|
80
|
+
Context = never
|
|
81
|
+
>(
|
|
82
|
+
executeOrHandlers:
|
|
83
|
+
| (<Row>(
|
|
84
|
+
query: CoreRenderer.RenderedQuery<Row, "mysql">
|
|
85
|
+
) => Effect.Effect<ReadonlyArray<FlatRow>, Error, Context>)
|
|
86
|
+
| {
|
|
87
|
+
readonly execute: <Row>(
|
|
88
|
+
query: CoreRenderer.RenderedQuery<Row, "mysql">
|
|
89
|
+
) => Effect.Effect<ReadonlyArray<FlatRow>, Error, Context>
|
|
90
|
+
readonly stream: <Row>(
|
|
91
|
+
query: CoreRenderer.RenderedQuery<Row, "mysql">
|
|
92
|
+
) => Stream.Stream<FlatRow, Error, Context>
|
|
93
|
+
}
|
|
94
|
+
): Driver<Error, Context> {
|
|
95
|
+
return CoreExecutor.driver("mysql", executeOrHandlers as any)
|
|
96
|
+
}
|
|
60
97
|
|
|
61
98
|
const fromDriver = <
|
|
62
99
|
Error = never,
|
|
@@ -87,13 +124,38 @@ const fromDriver = <
|
|
|
87
124
|
: narrowMysqlDriverErrorForReadQuery(normalized)
|
|
88
125
|
}
|
|
89
126
|
) as Effect.Effect<any, any, Context>
|
|
127
|
+
},
|
|
128
|
+
stream(plan) {
|
|
129
|
+
const rendered = renderer.render(plan)
|
|
130
|
+
return Stream.mapError(
|
|
131
|
+
Stream.mapChunksEffect(
|
|
132
|
+
sqlDriver.stream(rendered),
|
|
133
|
+
(rows) => Effect.try({
|
|
134
|
+
try: () => CoreExecutor.decodeChunk(rendered, plan, rows, { driverMode }),
|
|
135
|
+
catch: (error) => error as RowDecodeError
|
|
136
|
+
})
|
|
137
|
+
),
|
|
138
|
+
(error) => {
|
|
139
|
+
if (typeof error === "object" && error !== null && "_tag" in error && error._tag === "RowDecodeError") {
|
|
140
|
+
return error as RowDecodeError
|
|
141
|
+
}
|
|
142
|
+
const normalized = normalizeMysqlDriverError(error, rendered)
|
|
143
|
+
return CoreExecutor.hasWriteCapability(plan)
|
|
144
|
+
? normalized
|
|
145
|
+
: narrowMysqlDriverErrorForReadQuery(normalized)
|
|
146
|
+
}
|
|
147
|
+
) as Stream.Stream<any, any, Context>
|
|
90
148
|
}
|
|
91
149
|
})
|
|
92
150
|
|
|
93
151
|
const sqlClientDriver = (): Driver<any, SqlClient.SqlClient> =>
|
|
94
|
-
driver(
|
|
95
|
-
|
|
96
|
-
|
|
152
|
+
driver({
|
|
153
|
+
execute: (query) =>
|
|
154
|
+
Effect.flatMap(SqlClient.SqlClient, (sql) =>
|
|
155
|
+
sql.unsafe<FlatRow>(query.sql, [...query.params])),
|
|
156
|
+
stream: (query) =>
|
|
157
|
+
CoreExecutor.streamFromSqlClient(query)
|
|
158
|
+
})
|
|
97
159
|
|
|
98
160
|
/**
|
|
99
161
|
* Creates the standard MySQL executor pipeline.
|
|
@@ -2,7 +2,6 @@ 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"
|
|
6
5
|
export * as temporal from "./temporal.js"
|
|
7
6
|
|
|
8
7
|
export { coalesce } from "./core.js"
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type * as Schema from "effect/Schema"
|
|
2
2
|
|
|
3
|
-
import type * as Expression from "../../internal/
|
|
3
|
+
import type * as Expression from "../../internal/scalar.js"
|
|
4
4
|
import type * as ExpressionAst from "../../internal/expression-ast.js"
|
|
5
5
|
import { makeExpression } from "../../internal/query.js"
|
|
6
|
+
import { mysqlDatatypes } from "../datatypes/index.js"
|
|
6
7
|
import {
|
|
7
8
|
LocalDateStringSchema,
|
|
8
9
|
LocalDateTimeStringSchema,
|
|
@@ -10,21 +11,19 @@ import {
|
|
|
10
11
|
type LocalDateString,
|
|
11
12
|
type LocalDateTimeString,
|
|
12
13
|
type LocalTimeString
|
|
13
|
-
} from "../../internal/runtime
|
|
14
|
+
} from "../../internal/runtime/value.js"
|
|
14
15
|
|
|
15
16
|
type TemporalExpression<
|
|
16
17
|
Runtime,
|
|
17
18
|
Db extends Expression.DbType.Any,
|
|
18
19
|
Name extends string
|
|
19
|
-
> = Expression.
|
|
20
|
+
> = Expression.Scalar<
|
|
20
21
|
Runtime,
|
|
21
22
|
Db,
|
|
22
23
|
"never",
|
|
23
24
|
"mysql",
|
|
24
25
|
"scalar",
|
|
25
|
-
never
|
|
26
|
-
{},
|
|
27
|
-
"resolved"
|
|
26
|
+
never
|
|
28
27
|
> & {
|
|
29
28
|
readonly [ExpressionAst.TypeId]: ExpressionAst.FunctionCallNode<Name, readonly []>
|
|
30
29
|
}
|
|
@@ -44,10 +43,8 @@ const makeTemporal = <
|
|
|
44
43
|
runtimeSchema,
|
|
45
44
|
nullability: "never",
|
|
46
45
|
dialect: "mysql",
|
|
47
|
-
|
|
48
|
-
source: undefined as never,
|
|
46
|
+
kind: "scalar",
|
|
49
47
|
dependencies: {},
|
|
50
|
-
sourceNullability: "resolved"
|
|
51
48
|
}, {
|
|
52
49
|
kind: "function",
|
|
53
50
|
name,
|
|
@@ -58,7 +55,7 @@ const makeTemporal = <
|
|
|
58
55
|
export const currentDate = () =>
|
|
59
56
|
makeTemporal(
|
|
60
57
|
"current_date",
|
|
61
|
-
|
|
58
|
+
mysqlDatatypes.date(),
|
|
62
59
|
LocalDateStringSchema
|
|
63
60
|
)
|
|
64
61
|
|
|
@@ -66,7 +63,7 @@ export const currentDate = () =>
|
|
|
66
63
|
export const currentTime = () =>
|
|
67
64
|
makeTemporal(
|
|
68
65
|
"current_time",
|
|
69
|
-
|
|
66
|
+
mysqlDatatypes.time(),
|
|
70
67
|
LocalTimeStringSchema
|
|
71
68
|
)
|
|
72
69
|
|
|
@@ -74,7 +71,7 @@ export const currentTime = () =>
|
|
|
74
71
|
export const currentTimestamp = () =>
|
|
75
72
|
makeTemporal(
|
|
76
73
|
"current_timestamp",
|
|
77
|
-
|
|
74
|
+
mysqlDatatypes.timestamp(),
|
|
78
75
|
LocalDateTimeStringSchema
|
|
79
76
|
)
|
|
80
77
|
|
|
@@ -82,7 +79,7 @@ export const currentTimestamp = () =>
|
|
|
82
79
|
export const localTime = () =>
|
|
83
80
|
makeTemporal(
|
|
84
81
|
"localtime",
|
|
85
|
-
|
|
82
|
+
mysqlDatatypes.time(),
|
|
86
83
|
LocalTimeStringSchema
|
|
87
84
|
)
|
|
88
85
|
|
|
@@ -90,7 +87,7 @@ export const localTime = () =>
|
|
|
90
87
|
export const localTimestamp = () =>
|
|
91
88
|
makeTemporal(
|
|
92
89
|
"localtimestamp",
|
|
93
|
-
|
|
90
|
+
mysqlDatatypes.timestamp(),
|
|
94
91
|
LocalDateTimeStringSchema
|
|
95
92
|
)
|
|
96
93
|
|
|
@@ -98,6 +95,6 @@ export const localTimestamp = () =>
|
|
|
98
95
|
export const now = () =>
|
|
99
96
|
makeTemporal(
|
|
100
97
|
"now",
|
|
101
|
-
|
|
98
|
+
mysqlDatatypes.timestamp(),
|
|
102
99
|
LocalDateTimeStringSchema
|
|
103
100
|
)
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import { mysqlQuery } from "../private/query.js"
|
|
2
|
-
|
|
3
1
|
/** MySQL window functions. */
|
|
4
|
-
export
|
|
5
|
-
export const rowNumber = mysqlQuery.rowNumber
|
|
6
|
-
export const rank = mysqlQuery.rank
|
|
7
|
-
export const denseRank = mysqlQuery.denseRank
|
|
2
|
+
export { over, rowNumber, rank, denseRank } from "../internal/dsl.js"
|