effect-qb 0.13.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/README.md +6 -1431
- package/dist/mysql.js +61945 -3611
- package/dist/postgres/metadata.js +2818 -0
- package/dist/postgres.js +9942 -5591
- package/package.json +21 -10
- 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 +119 -56
- package/src/internal/column.ts +387 -149
- package/src/internal/datatypes/define.d.ts +17 -0
- package/src/internal/datatypes/define.ts +18 -34
- 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 +173 -38
- package/src/internal/expression-ast.ts +19 -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 +171 -0
- 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} +13 -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} +111 -32
- package/src/internal/predicate/formula.d.ts +35 -0
- package/src/internal/{predicate-formula.ts → predicate/formula.ts} +32 -20
- 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 +273 -0
- package/src/internal/predicate/runtime.d.ts +31 -0
- package/src/internal/predicate/runtime.ts +679 -0
- 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 +767 -275
- package/src/internal/renderer.ts +7 -21
- package/src/internal/row-set.d.ts +53 -0
- package/src/internal/{plan.ts → row-set.ts} +23 -11
- package/src/internal/{runtime-normalize.ts → runtime/normalize.ts} +9 -31
- package/src/internal/{runtime-schema.ts → runtime/schema.ts} +84 -55
- 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-derivation.ts +93 -21
- package/src/internal/schema-expression.d.ts +18 -0
- package/src/internal/schema-expression.ts +75 -0
- package/src/internal/table-options.d.ts +94 -0
- package/src/internal/table-options.ts +94 -8
- package/src/internal/table.d.ts +173 -0
- package/src/internal/table.ts +135 -54
- package/src/mysql/column.ts +95 -18
- package/src/mysql/datatypes/index.ts +58 -3
- 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 -3
- package/src/mysql/function/index.ts +1 -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/mysql/internal/dsl.ts +6115 -0
- 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 -86
- 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 +30 -0
- package/src/postgres/column.ts +178 -20
- package/src/postgres/datatypes/index.d.ts +515 -0
- package/src/postgres/datatypes/index.ts +49 -5
- 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 +20 -2
- package/src/postgres/function/index.ts +1 -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/query-factory.ts → postgres/internal/dsl.ts} +1568 -2120
- package/src/{internal/postgres-renderer.ts → postgres/internal/renderer.ts} +6 -6
- package/src/postgres/internal/schema-ddl.ts +108 -0
- package/src/postgres/internal/schema-model.ts +150 -0
- package/src/{internal → postgres/internal}/sql-expression-renderer.ts +112 -46
- package/src/postgres/json.ts +493 -0
- package/src/postgres/metadata.ts +31 -0
- package/src/postgres/query.ts +113 -86
- package/src/postgres/renderer.ts +3 -13
- package/src/postgres/schema-expression.ts +17 -0
- package/src/postgres/schema-management.ts +204 -0
- package/src/postgres/schema.ts +35 -0
- package/src/postgres/table.ts +316 -42
- package/src/postgres/type.ts +31 -0
- package/src/postgres.ts +20 -4
- package/CHANGELOG.md +0 -134
- package/src/internal/expression.ts +0 -327
- package/src/internal/predicate-normalize.ts +0 -202
- package/src/mysql/function/json.ts +0 -4
- package/src/mysql/private/query.ts +0 -13
- package/src/postgres/function/json.ts +0 -4
- package/src/postgres/private/query.ts +0 -13
- /package/src/internal/{predicate-atom.ts → predicate/atom.ts} +0 -0
|
@@ -8,14 +8,35 @@ import {
|
|
|
8
8
|
type PostgresErrorTag,
|
|
9
9
|
type PostgresSqlStateCode
|
|
10
10
|
} from "./catalog.js"
|
|
11
|
+
import {
|
|
12
|
+
postgresKnownErrorClassesByCode,
|
|
13
|
+
type KnownPostgresErrorByCode as ExactKnownPostgresErrorByCode
|
|
14
|
+
} from "./generated.js"
|
|
11
15
|
import type {
|
|
12
16
|
PostgresErrorFields,
|
|
13
17
|
PostgresQueryContext
|
|
14
18
|
} from "./fields.js"
|
|
19
|
+
import type {
|
|
20
|
+
PostgresErrorLike,
|
|
21
|
+
PostgresKnownErrorBase
|
|
22
|
+
} from "./types.js"
|
|
15
23
|
|
|
16
24
|
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
17
25
|
typeof value === "object" && value !== null
|
|
18
26
|
|
|
27
|
+
const unwrapPostgresDriverCause = (cause: unknown): unknown => {
|
|
28
|
+
let current = cause
|
|
29
|
+
while (
|
|
30
|
+
isRecord(current) &&
|
|
31
|
+
"_tag" in current &&
|
|
32
|
+
current._tag === "SqlError" &&
|
|
33
|
+
"cause" in current
|
|
34
|
+
) {
|
|
35
|
+
current = current.cause
|
|
36
|
+
}
|
|
37
|
+
return current
|
|
38
|
+
}
|
|
39
|
+
|
|
19
40
|
const asString = (value: unknown): string | undefined =>
|
|
20
41
|
typeof value === "string" ? value : undefined
|
|
21
42
|
|
|
@@ -51,49 +72,14 @@ const normalizeFields = (error: Record<string, unknown>): PostgresErrorFields =>
|
|
|
51
72
|
|
|
52
73
|
const sqlStatePattern = /^[0-9A-Z]{5}$/
|
|
53
74
|
|
|
54
|
-
|
|
55
|
-
export interface PostgresErrorLike {
|
|
56
|
-
readonly code?: string
|
|
57
|
-
readonly message?: string
|
|
58
|
-
readonly messagePrimary?: string
|
|
59
|
-
readonly schema?: string
|
|
60
|
-
readonly table?: string
|
|
61
|
-
readonly column?: string
|
|
62
|
-
readonly dataType?: string
|
|
63
|
-
readonly constraint?: string
|
|
64
|
-
readonly severity?: string
|
|
65
|
-
readonly severityNonLocalized?: string
|
|
66
|
-
readonly detail?: string
|
|
67
|
-
readonly hint?: string
|
|
68
|
-
readonly position?: string | number
|
|
69
|
-
readonly internalPosition?: string | number
|
|
70
|
-
readonly internalQuery?: string
|
|
71
|
-
readonly where?: string
|
|
72
|
-
readonly file?: string
|
|
73
|
-
readonly line?: string | number
|
|
74
|
-
readonly routine?: string
|
|
75
|
-
}
|
|
75
|
+
export type { PostgresErrorLike } from "./types.js"
|
|
76
76
|
|
|
77
77
|
/** Structured known Postgres SQLSTATE error derived from the catalog. */
|
|
78
|
-
export type KnownPostgresError<Code extends PostgresSqlStateCode = PostgresSqlStateCode> =
|
|
79
|
-
|
|
80
|
-
readonly _tag: PostgresErrorTag<Current>
|
|
81
|
-
readonly code: Current
|
|
82
|
-
readonly condition: PostgresErrorDescriptor<Current>["condition"]
|
|
83
|
-
readonly classCode: PostgresErrorDescriptor<Current>["classCode"]
|
|
84
|
-
readonly className: PostgresErrorDescriptor<Current>["className"]
|
|
85
|
-
readonly message: string
|
|
86
|
-
readonly primaryFields: PostgresErrorDescriptor<Current>["primaryFields"]
|
|
87
|
-
readonly query?: PostgresQueryContext
|
|
88
|
-
readonly raw: PostgresErrorLike
|
|
89
|
-
} & PostgresErrorFields>
|
|
90
|
-
}[Code]
|
|
78
|
+
export type KnownPostgresError<Code extends PostgresSqlStateCode = PostgresSqlStateCode> =
|
|
79
|
+
ExactKnownPostgresErrorByCode<Code>
|
|
91
80
|
|
|
92
81
|
/** Extracts the known Postgres error variant for a specific SQLSTATE code. */
|
|
93
|
-
export type KnownPostgresErrorByCode<Code extends PostgresSqlStateCode> =
|
|
94
|
-
KnownPostgresError,
|
|
95
|
-
{ readonly code: Code }
|
|
96
|
-
>
|
|
82
|
+
export type KnownPostgresErrorByCode<Code extends PostgresSqlStateCode> = ExactKnownPostgresErrorByCode<Code>
|
|
97
83
|
|
|
98
84
|
/** Postgres-like error whose SQLSTATE is well-formed but not in the current catalog. */
|
|
99
85
|
export type UnknownPostgresSqlStateError = Readonly<{
|
|
@@ -133,24 +119,19 @@ export const isPostgresErrorLike = (value: unknown): value is PostgresErrorLike
|
|
|
133
119
|
const errorMessageOf = (error: PostgresErrorLike): string =>
|
|
134
120
|
error.message ?? error.messagePrimary ?? "Postgres driver error"
|
|
135
121
|
|
|
136
|
-
const makeKnownPostgresError =
|
|
137
|
-
code:
|
|
122
|
+
const makeKnownPostgresError = (
|
|
123
|
+
code: PostgresSqlStateCode,
|
|
138
124
|
raw: PostgresErrorLike,
|
|
139
125
|
query?: PostgresQueryContext
|
|
140
|
-
): KnownPostgresError
|
|
126
|
+
): KnownPostgresError => {
|
|
141
127
|
const descriptor = getPostgresErrorDescriptor(code)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
code,
|
|
145
|
-
condition: descriptor.condition,
|
|
146
|
-
classCode: descriptor.classCode,
|
|
147
|
-
className: descriptor.className,
|
|
128
|
+
const ErrorClass = postgresKnownErrorClassesByCode[code]
|
|
129
|
+
return new ErrorClass({
|
|
148
130
|
message: errorMessageOf(raw),
|
|
149
|
-
primaryFields: descriptor.primaryFields,
|
|
150
131
|
query,
|
|
151
132
|
raw,
|
|
152
133
|
...normalizeFields(raw as Record<string, unknown>)
|
|
153
|
-
} as KnownPostgresError
|
|
134
|
+
}) as KnownPostgresError
|
|
154
135
|
}
|
|
155
136
|
|
|
156
137
|
/** Normalizes an unknown failure into a structured Postgres driver error. */
|
|
@@ -158,44 +139,45 @@ export const normalizePostgresDriverError = (
|
|
|
158
139
|
cause: unknown,
|
|
159
140
|
query?: PostgresQueryContext | Renderer.RenderedQuery<any, "postgres">
|
|
160
141
|
): PostgresDriverError => {
|
|
142
|
+
const normalizedCause = unwrapPostgresDriverCause(cause)
|
|
161
143
|
const context = query === undefined
|
|
162
144
|
? undefined
|
|
163
145
|
: "sql" in query
|
|
164
146
|
? { sql: query.sql, params: query.params }
|
|
165
147
|
: query
|
|
166
148
|
|
|
167
|
-
if (!isPostgresErrorLike(
|
|
149
|
+
if (!isPostgresErrorLike(normalizedCause)) {
|
|
168
150
|
return {
|
|
169
151
|
_tag: "@postgres/unknown/driver",
|
|
170
|
-
message:
|
|
152
|
+
message: normalizedCause instanceof Error ? normalizedCause.message : "Unknown Postgres driver failure",
|
|
171
153
|
query: context,
|
|
172
154
|
cause
|
|
173
155
|
} as UnknownPostgresDriverError
|
|
174
156
|
}
|
|
175
157
|
|
|
176
|
-
if (
|
|
177
|
-
return makeKnownPostgresError(
|
|
158
|
+
if (normalizedCause.code && isPostgresSqlStateCode(normalizedCause.code)) {
|
|
159
|
+
return makeKnownPostgresError(normalizedCause.code, normalizedCause, context)
|
|
178
160
|
}
|
|
179
161
|
|
|
180
|
-
if (typeof
|
|
181
|
-
const classCode =
|
|
162
|
+
if (typeof normalizedCause.code === "string" && sqlStatePattern.test(normalizedCause.code)) {
|
|
163
|
+
const classCode = normalizedCause.code.slice(0, 2)
|
|
182
164
|
return {
|
|
183
165
|
_tag: "@postgres/unknown/sqlstate",
|
|
184
|
-
code:
|
|
166
|
+
code: normalizedCause.code,
|
|
185
167
|
classCode,
|
|
186
168
|
className: classCode in postgresErrorClasses
|
|
187
169
|
? postgresErrorClasses[classCode as PostgresErrorClassCode]
|
|
188
170
|
: undefined,
|
|
189
|
-
message: errorMessageOf(
|
|
171
|
+
message: errorMessageOf(normalizedCause),
|
|
190
172
|
query: context,
|
|
191
|
-
raw:
|
|
192
|
-
...normalizeFields(
|
|
173
|
+
raw: normalizedCause,
|
|
174
|
+
...normalizeFields(normalizedCause as Record<string, unknown>)
|
|
193
175
|
} as UnknownPostgresSqlStateError
|
|
194
176
|
}
|
|
195
177
|
|
|
196
178
|
return {
|
|
197
179
|
_tag: "@postgres/unknown/driver",
|
|
198
|
-
message: errorMessageOf(
|
|
180
|
+
message: errorMessageOf(normalizedCause),
|
|
199
181
|
query: context,
|
|
200
182
|
cause
|
|
201
183
|
} as UnknownPostgresDriverError
|
|
@@ -206,4 +188,7 @@ export const hasSqlState = <Code extends PostgresSqlStateCode>(
|
|
|
206
188
|
error: PostgresDriverError | { readonly code?: string },
|
|
207
189
|
code: Code
|
|
208
190
|
): error is KnownPostgresErrorByCode<Code> =>
|
|
209
|
-
|
|
191
|
+
(typeof error === "object" &&
|
|
192
|
+
error !== null &&
|
|
193
|
+
error instanceof postgresKnownErrorClassesByCode[code]) ||
|
|
194
|
+
("code" in error && error.code === code)
|
|
@@ -1,38 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
| "schema"
|
|
4
|
-
| "table"
|
|
5
|
-
| "column"
|
|
6
|
-
| "constraint"
|
|
7
|
-
| "dataType"
|
|
8
|
-
| "position"
|
|
9
|
-
| "internalPosition"
|
|
10
|
-
| "internalQuery"
|
|
11
|
-
| "file"
|
|
12
|
-
| "line"
|
|
13
|
-
| "routine"
|
|
1
|
+
import type { PostgresErrorTag, PostgresSqlStateCode } from "./catalog.js"
|
|
2
|
+
import type { PostgresErrorFields, PostgresQueryContext } from "./fields.js"
|
|
14
3
|
|
|
15
|
-
/**
|
|
16
|
-
export interface
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
readonly
|
|
21
|
-
readonly
|
|
22
|
-
readonly
|
|
4
|
+
/** Raw Postgres-like error object as commonly exposed by client libraries. */
|
|
5
|
+
export interface PostgresErrorLike {
|
|
6
|
+
readonly code?: string
|
|
7
|
+
readonly message?: string
|
|
8
|
+
readonly messagePrimary?: string
|
|
9
|
+
readonly schema?: string
|
|
10
|
+
readonly table?: string
|
|
11
|
+
readonly column?: string
|
|
12
|
+
readonly dataType?: string
|
|
13
|
+
readonly constraint?: string
|
|
14
|
+
readonly severity?: string
|
|
15
|
+
readonly severityNonLocalized?: string
|
|
16
|
+
readonly detail?: string
|
|
17
|
+
readonly hint?: string
|
|
18
|
+
readonly position?: string | number
|
|
19
|
+
readonly internalPosition?: string | number
|
|
20
|
+
readonly internalQuery?: string
|
|
21
|
+
readonly where?: string
|
|
22
|
+
readonly file?: string
|
|
23
|
+
readonly line?: string | number
|
|
24
|
+
readonly routine?: string
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
/**
|
|
26
|
-
export interface
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
readonly
|
|
33
|
-
readonly
|
|
34
|
-
readonly
|
|
35
|
-
readonly
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
/** Broad known-Postgres error surface used by the normalizer return type. */
|
|
28
|
+
export interface PostgresKnownErrorBase extends Error, PostgresErrorFields {
|
|
29
|
+
readonly _tag: PostgresErrorTag<PostgresSqlStateCode>
|
|
30
|
+
readonly code: PostgresSqlStateCode
|
|
31
|
+
readonly condition: string
|
|
32
|
+
readonly classCode: string
|
|
33
|
+
readonly className: string
|
|
34
|
+
readonly message: string
|
|
35
|
+
readonly primaryFields: readonly string[]
|
|
36
|
+
readonly query?: PostgresQueryContext
|
|
37
|
+
readonly raw: PostgresErrorLike
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Shared constructor payload for generated Postgres error classes. */
|
|
41
|
+
export type PostgresKnownErrorArgs = Readonly<{
|
|
42
|
+
readonly message: string
|
|
43
|
+
readonly query?: PostgresQueryContext
|
|
44
|
+
readonly raw: PostgresErrorLike
|
|
45
|
+
} & PostgresErrorFields>
|
|
46
|
+
|
|
47
|
+
/** Runtime base class shared by generated Postgres error classes. */
|
|
48
|
+
export abstract class PostgresKnownErrorClass extends Error implements PostgresKnownErrorBase {
|
|
49
|
+
abstract readonly _tag: PostgresErrorTag<PostgresSqlStateCode>
|
|
50
|
+
abstract readonly code: PostgresSqlStateCode
|
|
51
|
+
abstract readonly condition: string
|
|
52
|
+
abstract readonly classCode: string
|
|
53
|
+
abstract readonly className: string
|
|
54
|
+
abstract readonly primaryFields: readonly string[]
|
|
55
|
+
readonly severity?
|
|
56
|
+
readonly severityNonLocalized?
|
|
57
|
+
readonly detail?
|
|
58
|
+
readonly hint?
|
|
59
|
+
readonly position?
|
|
60
|
+
readonly internalPosition?
|
|
61
|
+
readonly internalQuery?
|
|
62
|
+
readonly where?
|
|
63
|
+
readonly schemaName?
|
|
64
|
+
readonly tableName?
|
|
65
|
+
readonly columnName?
|
|
66
|
+
readonly dataTypeName?
|
|
67
|
+
readonly constraintName?
|
|
68
|
+
readonly file?
|
|
69
|
+
readonly line?
|
|
70
|
+
readonly routine?
|
|
71
|
+
readonly query?
|
|
72
|
+
readonly raw
|
|
73
|
+
|
|
74
|
+
constructor(args: PostgresKnownErrorArgs) {
|
|
75
|
+
super(args.message)
|
|
76
|
+
this.name = new.target.name
|
|
77
|
+
this.severity = args.severity
|
|
78
|
+
this.severityNonLocalized = args.severityNonLocalized
|
|
79
|
+
this.detail = args.detail
|
|
80
|
+
this.hint = args.hint
|
|
81
|
+
this.position = args.position
|
|
82
|
+
this.internalPosition = args.internalPosition
|
|
83
|
+
this.internalQuery = args.internalQuery
|
|
84
|
+
this.where = args.where
|
|
85
|
+
this.schemaName = args.schemaName
|
|
86
|
+
this.tableName = args.tableName
|
|
87
|
+
this.columnName = args.columnName
|
|
88
|
+
this.dataTypeName = args.dataTypeName
|
|
89
|
+
this.constraintName = args.constraintName
|
|
90
|
+
this.file = args.file
|
|
91
|
+
this.line = args.line
|
|
92
|
+
this.routine = args.routine
|
|
93
|
+
this.query = args.query
|
|
94
|
+
this.raw = args.raw
|
|
95
|
+
}
|
|
38
96
|
}
|
package/src/postgres/executor.ts
CHANGED
|
@@ -1,9 +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"
|
|
8
|
+
import { renderPostgresPlan } from "./internal/renderer.js"
|
|
7
9
|
import {
|
|
8
10
|
narrowPostgresDriverErrorForReadQuery,
|
|
9
11
|
normalizePostgresDriverError,
|
|
@@ -44,6 +46,11 @@ export interface QueryExecutor<Context = never> {
|
|
|
44
46
|
execute<PlanValue extends CoreQuery.QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
45
47
|
plan: CoreQuery.DialectCompatiblePlan<PlanValue, "postgres">
|
|
46
48
|
): Effect.Effect<CoreQuery.ResultRows<PlanValue>, PostgresQueryError<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, "postgres">
|
|
52
|
+
: never
|
|
53
|
+
): Stream.Stream<CoreQuery.ResultRow<PlanValue>, PostgresQueryError<PlanValue>, Context>
|
|
47
54
|
}
|
|
48
55
|
|
|
49
56
|
/** Constructs a Postgres-specialized SQL driver. */
|
|
@@ -83,13 +90,38 @@ const fromDriver = <
|
|
|
83
90
|
: narrowPostgresDriverErrorForReadQuery(normalized)
|
|
84
91
|
}
|
|
85
92
|
) as Effect.Effect<any, any, Context>
|
|
93
|
+
},
|
|
94
|
+
stream(plan) {
|
|
95
|
+
const rendered = renderer.render(plan)
|
|
96
|
+
return Stream.mapError(
|
|
97
|
+
Stream.mapChunksEffect(
|
|
98
|
+
sqlDriver.stream(rendered),
|
|
99
|
+
(rows) => Effect.try({
|
|
100
|
+
try: () => CoreExecutor.decodeChunk(rendered, plan, rows, { driverMode }),
|
|
101
|
+
catch: (error) => error as RowDecodeError
|
|
102
|
+
})
|
|
103
|
+
),
|
|
104
|
+
(error) => {
|
|
105
|
+
if (typeof error === "object" && error !== null && "_tag" in error && error._tag === "RowDecodeError") {
|
|
106
|
+
return error as RowDecodeError
|
|
107
|
+
}
|
|
108
|
+
const normalized = normalizePostgresDriverError(error, rendered)
|
|
109
|
+
return CoreExecutor.hasWriteCapability(plan)
|
|
110
|
+
? normalized
|
|
111
|
+
: narrowPostgresDriverErrorForReadQuery(normalized)
|
|
112
|
+
}
|
|
113
|
+
) as Stream.Stream<any, any, Context>
|
|
86
114
|
}
|
|
87
115
|
})
|
|
88
116
|
|
|
89
117
|
const sqlClientDriver = (): Driver<any, SqlClient.SqlClient> =>
|
|
90
|
-
driver(
|
|
91
|
-
|
|
92
|
-
|
|
118
|
+
driver({
|
|
119
|
+
execute: (query: CoreRenderer.RenderedQuery<any, "postgres">) =>
|
|
120
|
+
Effect.flatMap(SqlClient.SqlClient, (sql) =>
|
|
121
|
+
sql.unsafe<FlatRow>(query.sql, [...query.params])),
|
|
122
|
+
stream: (query: CoreRenderer.RenderedQuery<any, "postgres">) =>
|
|
123
|
+
CoreExecutor.streamFromSqlClient(query)
|
|
124
|
+
})
|
|
93
125
|
|
|
94
126
|
/**
|
|
95
127
|
* Creates the standard Postgres executor pipeline.
|
|
@@ -116,9 +148,9 @@ export function make<Error = never, Context = never>(
|
|
|
116
148
|
options: MakeOptions<Error, Context> = {}
|
|
117
149
|
): QueryExecutor<any> {
|
|
118
150
|
if (options.driver) {
|
|
119
|
-
return fromDriver(options.renderer ?? CoreRenderer.make("postgres"), options.driver, options.driverMode)
|
|
151
|
+
return fromDriver(options.renderer ?? CoreRenderer.make("postgres", renderPostgresPlan), options.driver, options.driverMode)
|
|
120
152
|
}
|
|
121
|
-
return fromDriver(options.renderer ?? CoreRenderer.make("postgres"), sqlClientDriver(), options.driverMode)
|
|
153
|
+
return fromDriver(options.renderer ?? CoreRenderer.make("postgres", renderPostgresPlan), sqlClientDriver(), options.driverMode)
|
|
122
154
|
}
|
|
123
155
|
|
|
124
156
|
/** Creates a Postgres-specialized executor from a typed implementation callback. */
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import { postgresQuery } from "../private/query.js"
|
|
2
|
-
|
|
3
1
|
/** Postgres aggregate functions. */
|
|
4
|
-
export
|
|
5
|
-
export const max = postgresQuery.max
|
|
6
|
-
export const min = postgresQuery.min
|
|
2
|
+
export { count, max, min } from "../internal/dsl.js"
|
|
@@ -1,4 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ExpressionInput } from "../query.js"
|
|
2
|
+
import {
|
|
3
|
+
call,
|
|
4
|
+
cast,
|
|
5
|
+
coalesce,
|
|
6
|
+
literal,
|
|
7
|
+
nextVal as nextValInternal,
|
|
8
|
+
type as postgresType,
|
|
9
|
+
uuidGenerateV4
|
|
10
|
+
} from "../internal/dsl.js"
|
|
11
|
+
import { isSequenceDefinition, type SequenceDefinition } from "../schema-management.js"
|
|
2
12
|
|
|
3
13
|
/** Postgres scalar core functions. */
|
|
4
|
-
export
|
|
14
|
+
export { coalesce, call, uuidGenerateV4 }
|
|
15
|
+
export const nextVal = (
|
|
16
|
+
value: ExpressionInput | SequenceDefinition<string, string | undefined>
|
|
17
|
+
) =>
|
|
18
|
+
nextValInternal(
|
|
19
|
+
isSequenceDefinition(value)
|
|
20
|
+
? cast(literal(value.qualifiedName()), postgresType.regclass())
|
|
21
|
+
: value
|
|
22
|
+
)
|
|
@@ -2,10 +2,10 @@ 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"
|
|
8
|
+
export { call, uuidGenerateV4, nextVal } from "./core.js"
|
|
9
9
|
export { lower, upper, concat } from "./string.js"
|
|
10
10
|
export { count, max, min } from "./aggregate.js"
|
|
11
11
|
export { over, rowNumber, rank, denseRank } from "./window.js"
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import { postgresQuery } from "../private/query.js"
|
|
2
|
-
|
|
3
1
|
/** Postgres string functions. */
|
|
4
|
-
export
|
|
5
|
-
export const upper = postgresQuery.upper
|
|
6
|
-
export const concat = postgresQuery.concat
|
|
2
|
+
export { lower, upper, concat } from "../internal/dsl.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 { postgresDatatypes } from "../datatypes/index.js"
|
|
6
7
|
import {
|
|
7
8
|
InstantStringSchema,
|
|
8
9
|
LocalDateStringSchema,
|
|
@@ -14,21 +15,19 @@ import {
|
|
|
14
15
|
type LocalDateTimeString,
|
|
15
16
|
type LocalTimeString,
|
|
16
17
|
type OffsetTimeString
|
|
17
|
-
} from "../../internal/runtime
|
|
18
|
+
} from "../../internal/runtime/value.js"
|
|
18
19
|
|
|
19
20
|
type TemporalExpression<
|
|
20
21
|
Runtime,
|
|
21
22
|
Db extends Expression.DbType.Any,
|
|
22
23
|
Name extends string
|
|
23
|
-
> = Expression.
|
|
24
|
+
> = Expression.Scalar<
|
|
24
25
|
Runtime,
|
|
25
26
|
Db,
|
|
26
27
|
"never",
|
|
27
28
|
"postgres",
|
|
28
29
|
"scalar",
|
|
29
|
-
never
|
|
30
|
-
{},
|
|
31
|
-
"resolved"
|
|
30
|
+
never
|
|
32
31
|
> & {
|
|
33
32
|
readonly [ExpressionAst.TypeId]: ExpressionAst.FunctionCallNode<Name, readonly []>
|
|
34
33
|
}
|
|
@@ -48,10 +47,8 @@ const makeTemporal = <
|
|
|
48
47
|
runtimeSchema,
|
|
49
48
|
nullability: "never",
|
|
50
49
|
dialect: "postgres",
|
|
51
|
-
|
|
52
|
-
source: undefined as never,
|
|
50
|
+
kind: "scalar",
|
|
53
51
|
dependencies: {},
|
|
54
|
-
sourceNullability: "resolved"
|
|
55
52
|
}, {
|
|
56
53
|
kind: "function",
|
|
57
54
|
name,
|
|
@@ -62,7 +59,7 @@ const makeTemporal = <
|
|
|
62
59
|
export const now = () =>
|
|
63
60
|
makeTemporal(
|
|
64
61
|
"now",
|
|
65
|
-
|
|
62
|
+
postgresDatatypes.timestamptz(),
|
|
66
63
|
InstantStringSchema
|
|
67
64
|
)
|
|
68
65
|
|
|
@@ -70,7 +67,7 @@ export const now = () =>
|
|
|
70
67
|
export const currentDate = () =>
|
|
71
68
|
makeTemporal(
|
|
72
69
|
"current_date",
|
|
73
|
-
|
|
70
|
+
postgresDatatypes.date(),
|
|
74
71
|
LocalDateStringSchema
|
|
75
72
|
)
|
|
76
73
|
|
|
@@ -78,7 +75,7 @@ export const currentDate = () =>
|
|
|
78
75
|
export const currentTime = () =>
|
|
79
76
|
makeTemporal(
|
|
80
77
|
"current_time",
|
|
81
|
-
|
|
78
|
+
postgresDatatypes.timetz(),
|
|
82
79
|
OffsetTimeStringSchema
|
|
83
80
|
)
|
|
84
81
|
|
|
@@ -86,7 +83,7 @@ export const currentTime = () =>
|
|
|
86
83
|
export const currentTimestamp = () =>
|
|
87
84
|
makeTemporal(
|
|
88
85
|
"current_timestamp",
|
|
89
|
-
|
|
86
|
+
postgresDatatypes.timestamptz(),
|
|
90
87
|
InstantStringSchema
|
|
91
88
|
)
|
|
92
89
|
|
|
@@ -94,7 +91,7 @@ export const currentTimestamp = () =>
|
|
|
94
91
|
export const localTime = () =>
|
|
95
92
|
makeTemporal(
|
|
96
93
|
"localtime",
|
|
97
|
-
|
|
94
|
+
postgresDatatypes.time(),
|
|
98
95
|
LocalTimeStringSchema
|
|
99
96
|
)
|
|
100
97
|
|
|
@@ -102,6 +99,6 @@ export const localTime = () =>
|
|
|
102
99
|
export const localTimestamp = () =>
|
|
103
100
|
makeTemporal(
|
|
104
101
|
"localtimestamp",
|
|
105
|
-
|
|
102
|
+
postgresDatatypes.timestamp(),
|
|
106
103
|
LocalDateTimeStringSchema
|
|
107
104
|
)
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import { postgresQuery } from "../private/query.js"
|
|
2
|
-
|
|
3
1
|
/** Postgres window functions. */
|
|
4
|
-
export
|
|
5
|
-
export const rowNumber = postgresQuery.rowNumber
|
|
6
|
-
export const rank = postgresQuery.rank
|
|
7
|
-
export const denseRank = postgresQuery.denseRank
|
|
2
|
+
export { over, rowNumber, rank, denseRank } from "../internal/dsl.js"
|