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
|
@@ -1,34 +1,30 @@
|
|
|
1
|
-
import * as Expression from "
|
|
2
|
-
import type { JsonPathUsageError } from "
|
|
3
|
-
import * as JsonPath from "
|
|
1
|
+
import * as Expression from "../internal/scalar.js"
|
|
2
|
+
import type { JsonPathUsageError } from "../internal/json/errors.js"
|
|
3
|
+
import * as JsonPath from "../internal/json/path.js"
|
|
4
4
|
import type {
|
|
5
5
|
JsonDeleteAtPath,
|
|
6
6
|
JsonInsertAtPath,
|
|
7
7
|
JsonSetAtPath,
|
|
8
8
|
JsonValueAtPath
|
|
9
|
-
} from "
|
|
10
|
-
import {
|
|
9
|
+
} from "../internal/json/types.js"
|
|
10
|
+
import { json as postgresJson, jsonb as postgresJsonb } from "./internal/dsl.js"
|
|
11
11
|
|
|
12
|
-
type PostgresJsonExpression<Runtime = unknown> = Expression.
|
|
12
|
+
type PostgresJsonExpression<Runtime = unknown> = Expression.Scalar<
|
|
13
13
|
Runtime,
|
|
14
14
|
Expression.DbType.Json<"postgres", "json" | "jsonb">,
|
|
15
15
|
Expression.Nullability,
|
|
16
16
|
string,
|
|
17
|
-
Expression.
|
|
18
|
-
|
|
19
|
-
Expression.SourceDependencies,
|
|
20
|
-
Expression.SourceNullabilityMode
|
|
17
|
+
Expression.ScalarKind,
|
|
18
|
+
Expression.BindingId
|
|
21
19
|
>
|
|
22
20
|
|
|
23
|
-
type PostgresJsonbExpression<Runtime = unknown> = Expression.
|
|
21
|
+
type PostgresJsonbExpression<Runtime = unknown> = Expression.Scalar<
|
|
24
22
|
Runtime,
|
|
25
23
|
Expression.DbType.Json<"postgres", "jsonb">,
|
|
26
24
|
Expression.Nullability,
|
|
27
25
|
string,
|
|
28
|
-
Expression.
|
|
29
|
-
|
|
30
|
-
Expression.SourceDependencies,
|
|
31
|
-
Expression.SourceNullabilityMode
|
|
26
|
+
Expression.ScalarKind,
|
|
27
|
+
Expression.BindingId
|
|
32
28
|
>
|
|
33
29
|
|
|
34
30
|
type ExactJsonPathInput = JsonPath.ExactSegment | JsonPath.Path<any>
|
|
@@ -36,7 +32,7 @@ type ExactJsonPathInput = JsonPath.ExactSegment | JsonPath.Path<any>
|
|
|
36
32
|
type ExactJsonPathUsageError<Target> = {
|
|
37
33
|
readonly __effect_qb_error__: "effect-qb: postgres json helpers only accept exact key/index paths"
|
|
38
34
|
readonly __effect_qb_json_path__: Target
|
|
39
|
-
readonly __effect_qb_hint__: "Use Postgres.
|
|
35
|
+
readonly __effect_qb_hint__: "Use Postgres.Json.jsonb.path(...) when you need wildcard(), slice(), or descend() segments"
|
|
40
36
|
}
|
|
41
37
|
|
|
42
38
|
type ExactJsonPathGuard<Target> = Target extends JsonPath.Path<any>
|
|
@@ -133,7 +129,7 @@ type JsonbOnlyUsageError<
|
|
|
133
129
|
readonly __effect_qb_error__: "effect-qb: postgres jsonb helpers require a jsonb expression"
|
|
134
130
|
readonly __effect_qb_json_operation__: Operation
|
|
135
131
|
readonly __effect_qb_received_kind__: Expression.DbTypeOf<Value>["kind"]
|
|
136
|
-
readonly __effect_qb_hint__: "Use Column.jsonb(...), Cast.to(..., Type.jsonb()), or Postgres.
|
|
132
|
+
readonly __effect_qb_hint__: "Use Column.jsonb(...), Cast.to(..., Type.jsonb()), or Postgres.Json.jsonb.toJsonb(...)"
|
|
137
133
|
}
|
|
138
134
|
|
|
139
135
|
type JsonbBaseGuard<
|
|
@@ -151,15 +147,13 @@ type JsonNullabilityOf<Output> =
|
|
|
151
147
|
type JsonResultExpression<
|
|
152
148
|
Runtime,
|
|
153
149
|
Db extends Expression.DbType.Json<any, any>
|
|
154
|
-
> = Expression.
|
|
150
|
+
> = Expression.Scalar<
|
|
155
151
|
Runtime,
|
|
156
152
|
Db,
|
|
157
153
|
JsonNullabilityOf<Runtime>,
|
|
158
154
|
string,
|
|
159
|
-
Expression.
|
|
160
|
-
|
|
161
|
-
Expression.SourceDependencies,
|
|
162
|
-
Expression.SourceNullabilityMode
|
|
155
|
+
Expression.ScalarKind,
|
|
156
|
+
Expression.BindingId
|
|
163
157
|
>
|
|
164
158
|
|
|
165
159
|
type JsonDbOf<Base extends PostgresJsonExpression<any>> =
|
|
@@ -186,15 +180,13 @@ type JsonTextRuntime<
|
|
|
186
180
|
type JsonTextResultExpression<
|
|
187
181
|
Base extends PostgresJsonExpression<any>,
|
|
188
182
|
Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment
|
|
189
|
-
> = Expression.
|
|
183
|
+
> = Expression.Scalar<
|
|
190
184
|
JsonTextRuntime<Base, Target>,
|
|
191
|
-
Expression.DbType.
|
|
185
|
+
Expression.DbType.Base<"postgres", "text">,
|
|
192
186
|
JsonNullabilityOf<JsonTextRuntime<Base, Target>>,
|
|
193
187
|
string,
|
|
194
|
-
Expression.
|
|
195
|
-
|
|
196
|
-
Expression.SourceDependencies,
|
|
197
|
-
Expression.SourceNullabilityMode
|
|
188
|
+
Expression.ScalarKind,
|
|
189
|
+
Expression.BindingId
|
|
198
190
|
>
|
|
199
191
|
|
|
200
192
|
const exactPath = <Segments extends readonly JsonPath.CanonicalSegment[]>(
|
|
@@ -208,7 +200,7 @@ const jsonGetDirect = <
|
|
|
208
200
|
base: Base,
|
|
209
201
|
target: Target & ExactJsonPathGuard<Target>
|
|
210
202
|
): JsonGetResultExpression<Base, Target, "json.get"> =>
|
|
211
|
-
|
|
203
|
+
postgresJson.get(base as never, target as never) as unknown as JsonGetResultExpression<Base, Target, "json.get">
|
|
212
204
|
|
|
213
205
|
const jsonTextDirect = <
|
|
214
206
|
Base extends PostgresJsonExpression<any>,
|
|
@@ -217,11 +209,11 @@ const jsonTextDirect = <
|
|
|
217
209
|
base: Base,
|
|
218
210
|
target: Target & ExactJsonPathGuard<Target>
|
|
219
211
|
): JsonTextResultExpression<Base, Target> =>
|
|
220
|
-
|
|
212
|
+
postgresJson.text(base as never, target as never) as unknown as JsonTextResultExpression<Base, Target>
|
|
221
213
|
|
|
222
214
|
const json = {
|
|
223
|
-
key:
|
|
224
|
-
index:
|
|
215
|
+
key: postgresJson.key,
|
|
216
|
+
index: postgresJson.index,
|
|
225
217
|
path: exactPath,
|
|
226
218
|
get: ((...args: [PostgresJsonExpression<any>, ExactJsonPathInput] | [ExactJsonPathInput]) =>
|
|
227
219
|
args.length === 1
|
|
@@ -238,14 +230,14 @@ const json = {
|
|
|
238
230
|
>(
|
|
239
231
|
base: Base,
|
|
240
232
|
target: Target & ExactJsonPathGuard<Target> & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.access">
|
|
241
|
-
) =>
|
|
233
|
+
) => postgresJson.access(base, target),
|
|
242
234
|
traverse: <
|
|
243
235
|
Base extends PostgresJsonExpression<any>,
|
|
244
236
|
Target extends ExactJsonPathInput
|
|
245
237
|
>(
|
|
246
238
|
base: Base,
|
|
247
239
|
target: Target & ExactJsonPathGuard<Target> & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.traverse">
|
|
248
|
-
) =>
|
|
240
|
+
) => postgresJson.traverse(base, target),
|
|
249
241
|
text: ((...args: [PostgresJsonExpression<any>, ExactJsonPathInput] | [ExactJsonPathInput]) =>
|
|
250
242
|
args.length === 1
|
|
251
243
|
? ((base: PostgresJsonExpression<any>) => jsonTextDirect(base as never, args[0] as never))
|
|
@@ -261,21 +253,21 @@ const json = {
|
|
|
261
253
|
>(
|
|
262
254
|
base: Base,
|
|
263
255
|
target: Target & ExactJsonPathGuard<Target> & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.accessText">
|
|
264
|
-
) =>
|
|
256
|
+
) => postgresJson.accessText(base, target),
|
|
265
257
|
traverseText: <
|
|
266
258
|
Base extends PostgresJsonExpression<any>,
|
|
267
259
|
Target extends ExactJsonPathInput
|
|
268
260
|
>(
|
|
269
261
|
base: Base,
|
|
270
262
|
target: Target & ExactJsonPathGuard<Target> & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.traverseText">
|
|
271
|
-
) =>
|
|
272
|
-
buildObject:
|
|
273
|
-
buildArray:
|
|
274
|
-
toJson:
|
|
275
|
-
typeOf:
|
|
276
|
-
length:
|
|
277
|
-
keys:
|
|
278
|
-
stripNulls:
|
|
263
|
+
) => postgresJson.traverseText(base, target),
|
|
264
|
+
buildObject: postgresJson.buildObject,
|
|
265
|
+
buildArray: postgresJson.buildArray,
|
|
266
|
+
toJson: postgresJson.toJson,
|
|
267
|
+
typeOf: postgresJson.typeOf,
|
|
268
|
+
length: postgresJson.length,
|
|
269
|
+
keys: postgresJson.keys,
|
|
270
|
+
stripNulls: postgresJson.stripNulls,
|
|
279
271
|
delete: <
|
|
280
272
|
Base extends PostgresJsonExpression<any>,
|
|
281
273
|
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
|
|
@@ -285,7 +277,7 @@ const json = {
|
|
|
285
277
|
): JsonResultExpression<
|
|
286
278
|
JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.delete">,
|
|
287
279
|
Expression.DbTypeOf<Base>
|
|
288
|
-
> =>
|
|
280
|
+
> => postgresJson.delete(base as any, target as any) as unknown as JsonResultExpression<
|
|
289
281
|
JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.delete">,
|
|
290
282
|
Expression.DbTypeOf<Base>
|
|
291
283
|
>,
|
|
@@ -298,103 +290,103 @@ const json = {
|
|
|
298
290
|
): JsonResultExpression<
|
|
299
291
|
JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.remove">,
|
|
300
292
|
Expression.DbTypeOf<Base>
|
|
301
|
-
> =>
|
|
293
|
+
> => postgresJson.remove(base as any, target as any) as unknown as JsonResultExpression<
|
|
302
294
|
JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.remove">,
|
|
303
295
|
Expression.DbTypeOf<Base>
|
|
304
296
|
>
|
|
305
297
|
}
|
|
306
298
|
|
|
307
299
|
const jsonb = {
|
|
308
|
-
key:
|
|
309
|
-
index:
|
|
310
|
-
wildcard:
|
|
311
|
-
slice:
|
|
312
|
-
descend:
|
|
313
|
-
path:
|
|
300
|
+
key: postgresJsonb.key,
|
|
301
|
+
index: postgresJsonb.index,
|
|
302
|
+
wildcard: postgresJsonb.wildcard,
|
|
303
|
+
slice: postgresJsonb.slice,
|
|
304
|
+
descend: postgresJsonb.descend,
|
|
305
|
+
path: postgresJsonb.path,
|
|
314
306
|
get: <
|
|
315
307
|
Base extends PostgresJsonExpression<any>,
|
|
316
308
|
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
|
|
317
309
|
>(
|
|
318
310
|
base: Base & JsonbBaseGuard<Base, "jsonb.get">,
|
|
319
311
|
target: Target & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.get">
|
|
320
|
-
) =>
|
|
312
|
+
) => postgresJsonb.get(base as Base, target),
|
|
321
313
|
access: <
|
|
322
314
|
Base extends PostgresJsonExpression<any>,
|
|
323
315
|
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
|
|
324
316
|
>(
|
|
325
317
|
base: Base & JsonbBaseGuard<Base, "jsonb.access">,
|
|
326
318
|
target: Target & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.access">
|
|
327
|
-
) =>
|
|
319
|
+
) => postgresJsonb.access(base as Base, target),
|
|
328
320
|
traverse: <
|
|
329
321
|
Base extends PostgresJsonExpression<any>,
|
|
330
322
|
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
|
|
331
323
|
>(
|
|
332
324
|
base: Base & JsonbBaseGuard<Base, "jsonb.traverse">,
|
|
333
325
|
target: Target & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.traverse">
|
|
334
|
-
) =>
|
|
326
|
+
) => postgresJsonb.traverse(base as Base, target),
|
|
335
327
|
text: <
|
|
336
328
|
Base extends PostgresJsonExpression<any>,
|
|
337
329
|
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
|
|
338
330
|
>(
|
|
339
331
|
base: Base & JsonbBaseGuard<Base, "jsonb.text">,
|
|
340
332
|
target: Target & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.text">
|
|
341
|
-
) =>
|
|
333
|
+
) => postgresJsonb.text(base as Base, target),
|
|
342
334
|
accessText: <
|
|
343
335
|
Base extends PostgresJsonExpression<any>,
|
|
344
336
|
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
|
|
345
337
|
>(
|
|
346
338
|
base: Base & JsonbBaseGuard<Base, "jsonb.accessText">,
|
|
347
339
|
target: Target & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.accessText">
|
|
348
|
-
) =>
|
|
340
|
+
) => postgresJsonb.accessText(base as Base, target),
|
|
349
341
|
traverseText: <
|
|
350
342
|
Base extends PostgresJsonExpression<any>,
|
|
351
343
|
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
|
|
352
344
|
>(
|
|
353
345
|
base: Base & JsonbBaseGuard<Base, "jsonb.traverseText">,
|
|
354
346
|
target: Target & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.traverseText">
|
|
355
|
-
) =>
|
|
347
|
+
) => postgresJsonb.traverseText(base as Base, target),
|
|
356
348
|
contains: <
|
|
357
349
|
Left extends PostgresJsonExpression<any>,
|
|
358
|
-
Right extends Parameters<typeof
|
|
350
|
+
Right extends Parameters<typeof postgresJsonb.contains>[1]
|
|
359
351
|
>(
|
|
360
352
|
left: Left & JsonbBaseGuard<Left, "jsonb.contains">,
|
|
361
353
|
right: Right
|
|
362
|
-
) =>
|
|
354
|
+
) => postgresJsonb.contains(left as Left, right),
|
|
363
355
|
containedBy: <
|
|
364
356
|
Left extends PostgresJsonExpression<any>,
|
|
365
|
-
Right extends Parameters<typeof
|
|
357
|
+
Right extends Parameters<typeof postgresJsonb.containedBy>[1]
|
|
366
358
|
>(
|
|
367
359
|
left: Left & JsonbBaseGuard<Left, "jsonb.containedBy">,
|
|
368
360
|
right: Right
|
|
369
|
-
) =>
|
|
361
|
+
) => postgresJsonb.containedBy(left as Left, right),
|
|
370
362
|
hasKey: <
|
|
371
363
|
Base extends PostgresJsonExpression<any>,
|
|
372
364
|
Key extends string
|
|
373
365
|
>(
|
|
374
366
|
base: Base & JsonbBaseGuard<Base, "jsonb.hasKey">,
|
|
375
367
|
key: Key
|
|
376
|
-
) =>
|
|
368
|
+
) => postgresJsonb.hasKey(base as Base, key),
|
|
377
369
|
keyExists: <
|
|
378
370
|
Base extends PostgresJsonExpression<any>,
|
|
379
371
|
Key extends string
|
|
380
372
|
>(
|
|
381
373
|
base: Base & JsonbBaseGuard<Base, "jsonb.keyExists">,
|
|
382
374
|
key: Key
|
|
383
|
-
) =>
|
|
375
|
+
) => postgresJsonb.keyExists(base as Base, key),
|
|
384
376
|
hasAnyKeys: <
|
|
385
377
|
Base extends PostgresJsonExpression<any>,
|
|
386
378
|
Keys extends readonly [string, ...string[]]
|
|
387
379
|
>(
|
|
388
380
|
base: Base & JsonbBaseGuard<Base, "jsonb.hasAnyKeys">,
|
|
389
381
|
...keys: Keys
|
|
390
|
-
) =>
|
|
382
|
+
) => postgresJsonb.hasAnyKeys(base as Base, ...keys),
|
|
391
383
|
hasAllKeys: <
|
|
392
384
|
Base extends PostgresJsonExpression<any>,
|
|
393
385
|
Keys extends readonly [string, ...string[]]
|
|
394
386
|
>(
|
|
395
387
|
base: Base & JsonbBaseGuard<Base, "jsonb.hasAllKeys">,
|
|
396
388
|
...keys: Keys
|
|
397
|
-
) =>
|
|
389
|
+
) => postgresJsonb.hasAllKeys(base as Base, ...keys),
|
|
398
390
|
delete: <
|
|
399
391
|
Base extends PostgresJsonExpression<any>,
|
|
400
392
|
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
|
|
@@ -404,7 +396,7 @@ const jsonb = {
|
|
|
404
396
|
): JsonResultExpression<
|
|
405
397
|
JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.delete">,
|
|
406
398
|
Expression.DbTypeOf<Base>
|
|
407
|
-
> =>
|
|
399
|
+
> => postgresJsonb.delete(base as any, target as any) as unknown as JsonResultExpression<
|
|
408
400
|
JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.delete">,
|
|
409
401
|
Expression.DbTypeOf<Base>
|
|
410
402
|
>,
|
|
@@ -417,30 +409,30 @@ const jsonb = {
|
|
|
417
409
|
): JsonResultExpression<
|
|
418
410
|
JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.remove">,
|
|
419
411
|
Expression.DbTypeOf<Base>
|
|
420
|
-
> =>
|
|
412
|
+
> => postgresJsonb.remove(base as any, target as any) as unknown as JsonResultExpression<
|
|
421
413
|
JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.remove">,
|
|
422
414
|
Expression.DbTypeOf<Base>
|
|
423
415
|
>,
|
|
424
416
|
set: <
|
|
425
417
|
Base extends PostgresJsonExpression<any>,
|
|
426
418
|
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>,
|
|
427
|
-
Next extends Parameters<typeof
|
|
419
|
+
Next extends Parameters<typeof postgresJsonb.set>[2]
|
|
428
420
|
>(
|
|
429
421
|
base: Base & JsonbBaseGuard<Base, "jsonb.set">,
|
|
430
422
|
target: Target & JsonSetPathGuard<Expression.RuntimeOf<Base>, Target, Next, "json.set">,
|
|
431
423
|
next: Next,
|
|
432
|
-
options?: Parameters<typeof
|
|
424
|
+
options?: Parameters<typeof postgresJsonb.set>[3]
|
|
433
425
|
): JsonResultExpression<
|
|
434
426
|
JsonSetOutputOf<Expression.RuntimeOf<Base>, Target, Next, "json.set">,
|
|
435
427
|
Expression.DbTypeOf<Base>
|
|
436
|
-
> =>
|
|
428
|
+
> => postgresJsonb.set(base as any, target as any, next, options) as unknown as JsonResultExpression<
|
|
437
429
|
JsonSetOutputOf<Expression.RuntimeOf<Base>, Target, Next, "json.set">,
|
|
438
430
|
Expression.DbTypeOf<Base>
|
|
439
431
|
>,
|
|
440
432
|
insert: <
|
|
441
433
|
Base extends PostgresJsonExpression<any>,
|
|
442
434
|
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>,
|
|
443
|
-
Next extends Parameters<typeof
|
|
435
|
+
Next extends Parameters<typeof postgresJsonb.insert>[2],
|
|
444
436
|
InsertAfter extends boolean = false
|
|
445
437
|
>(
|
|
446
438
|
base: Base & JsonbBaseGuard<Base, "jsonb.insert">,
|
|
@@ -452,47 +444,47 @@ const jsonb = {
|
|
|
452
444
|
): JsonResultExpression<
|
|
453
445
|
JsonInsertOutputOf<Expression.RuntimeOf<Base>, Target, Next, InsertAfter, "json.insert">,
|
|
454
446
|
Expression.DbTypeOf<Base>
|
|
455
|
-
> =>
|
|
447
|
+
> => postgresJsonb.insert(base as any, target as any, next, options) as unknown as JsonResultExpression<
|
|
456
448
|
JsonInsertOutputOf<Expression.RuntimeOf<Base>, Target, Next, InsertAfter, "json.insert">,
|
|
457
449
|
Expression.DbTypeOf<Base>
|
|
458
450
|
>,
|
|
459
|
-
concat:
|
|
460
|
-
merge:
|
|
461
|
-
buildObject:
|
|
462
|
-
buildArray:
|
|
463
|
-
toJsonb:
|
|
451
|
+
concat: postgresJsonb.concat,
|
|
452
|
+
merge: postgresJsonb.merge,
|
|
453
|
+
buildObject: postgresJsonb.buildObject,
|
|
454
|
+
buildArray: postgresJsonb.buildArray,
|
|
455
|
+
toJsonb: postgresJsonb.toJsonb,
|
|
464
456
|
typeOf: <
|
|
465
457
|
Base extends PostgresJsonExpression<any>
|
|
466
458
|
>(
|
|
467
459
|
base: Base & JsonbBaseGuard<Base, "jsonb.typeOf">
|
|
468
|
-
) =>
|
|
460
|
+
) => postgresJsonb.typeOf(base as Base),
|
|
469
461
|
length: <
|
|
470
462
|
Base extends PostgresJsonExpression<any>
|
|
471
463
|
>(
|
|
472
464
|
base: Base & JsonbBaseGuard<Base, "jsonb.length">
|
|
473
|
-
) =>
|
|
465
|
+
) => postgresJsonb.length(base as Base),
|
|
474
466
|
keys: <
|
|
475
467
|
Base extends PostgresJsonExpression<any>
|
|
476
468
|
>(
|
|
477
469
|
base: Base & JsonbBaseGuard<Base, "jsonb.keys">
|
|
478
|
-
) =>
|
|
470
|
+
) => postgresJsonb.keys(base as Base),
|
|
479
471
|
stripNulls: <
|
|
480
472
|
Base extends PostgresJsonExpression<any>
|
|
481
473
|
>(
|
|
482
474
|
base: Base & JsonbBaseGuard<Base, "jsonb.stripNulls">
|
|
483
|
-
) =>
|
|
475
|
+
) => postgresJsonb.stripNulls(base as Base),
|
|
484
476
|
pathExists: <
|
|
485
477
|
Base extends PostgresJsonExpression<any>
|
|
486
478
|
>(
|
|
487
479
|
base: Base & JsonbBaseGuard<Base, "jsonb.pathExists">,
|
|
488
|
-
query: Parameters<typeof
|
|
489
|
-
) =>
|
|
480
|
+
query: Parameters<typeof postgresJsonb.pathExists>[1]
|
|
481
|
+
) => postgresJsonb.pathExists(base as Base, query),
|
|
490
482
|
pathMatch: <
|
|
491
483
|
Base extends PostgresJsonExpression<any>
|
|
492
484
|
>(
|
|
493
485
|
base: Base & JsonbBaseGuard<Base, "jsonb.pathMatch">,
|
|
494
|
-
query: Parameters<typeof
|
|
495
|
-
) =>
|
|
486
|
+
query: Parameters<typeof postgresJsonb.pathMatch>[1]
|
|
487
|
+
) => postgresJsonb.pathMatch(base as Base, query)
|
|
496
488
|
}
|
|
497
489
|
|
|
498
490
|
/** Postgres shared JSON helpers for exact paths and functions that work on both json and jsonb. */
|
package/src/postgres/metadata.ts
CHANGED
|
@@ -10,7 +10,7 @@ export {
|
|
|
10
10
|
type EnumModel,
|
|
11
11
|
type SchemaModel,
|
|
12
12
|
type TableModel
|
|
13
|
-
} from "
|
|
13
|
+
} from "./internal/schema-model.js"
|
|
14
14
|
|
|
15
15
|
export {
|
|
16
16
|
EnumTypeId,
|
|
@@ -28,4 +28,4 @@ export type {
|
|
|
28
28
|
export {
|
|
29
29
|
normalizeDdlExpressionSql,
|
|
30
30
|
renderDdlExpressionSql
|
|
31
|
-
} from "
|
|
31
|
+
} from "./internal/schema-ddl.js"
|
package/src/postgres/query.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { postgresQuery } from "./private/query.js"
|
|
2
1
|
import {
|
|
2
|
+
type AnyTableFunctionSource,
|
|
3
|
+
type AnyUnnestSource,
|
|
4
|
+
type AnyValuesSource,
|
|
3
5
|
type CapabilitiesOfPlan,
|
|
4
6
|
type CompletePlan,
|
|
5
7
|
type DialectCompatiblePlan,
|
|
@@ -36,95 +38,117 @@ import {
|
|
|
36
38
|
type StatementOfPlan,
|
|
37
39
|
type StringExpressionInput
|
|
38
40
|
} from "../internal/query.js"
|
|
41
|
+
import {
|
|
42
|
+
type PublicNonStructuredFromApi,
|
|
43
|
+
type PublicGenerateSeriesApi,
|
|
44
|
+
type PublicStructuredFromConstraint,
|
|
45
|
+
type PublicStructuredFromResult,
|
|
46
|
+
type as postgresType,
|
|
47
|
+
values,
|
|
48
|
+
unnest,
|
|
49
|
+
select,
|
|
50
|
+
insert,
|
|
51
|
+
generateSeries as dslGenerateSeries,
|
|
52
|
+
from as dslFrom
|
|
53
|
+
} from "./internal/dsl.js"
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
literal,
|
|
57
|
+
column,
|
|
58
|
+
eq,
|
|
59
|
+
neq,
|
|
60
|
+
lt,
|
|
61
|
+
lte,
|
|
62
|
+
gt,
|
|
63
|
+
gte,
|
|
64
|
+
isNull,
|
|
65
|
+
isNotNull,
|
|
66
|
+
like,
|
|
67
|
+
ilike,
|
|
68
|
+
collate,
|
|
69
|
+
regexMatch,
|
|
70
|
+
regexIMatch,
|
|
71
|
+
regexNotMatch,
|
|
72
|
+
regexNotIMatch,
|
|
73
|
+
and,
|
|
74
|
+
or,
|
|
75
|
+
not,
|
|
76
|
+
all,
|
|
77
|
+
any,
|
|
78
|
+
case_ as case,
|
|
79
|
+
match,
|
|
80
|
+
in_ as in,
|
|
81
|
+
notIn,
|
|
82
|
+
between,
|
|
83
|
+
contains,
|
|
84
|
+
containedBy,
|
|
85
|
+
overlaps,
|
|
86
|
+
exists,
|
|
87
|
+
isDistinctFrom,
|
|
88
|
+
isNotDistinctFrom,
|
|
89
|
+
excluded,
|
|
90
|
+
as,
|
|
91
|
+
with_ as with,
|
|
92
|
+
withRecursive,
|
|
93
|
+
lateral,
|
|
94
|
+
scalar,
|
|
95
|
+
inSubquery,
|
|
96
|
+
compareAny,
|
|
97
|
+
compareAll,
|
|
98
|
+
values,
|
|
99
|
+
unnest,
|
|
100
|
+
select,
|
|
101
|
+
returning,
|
|
102
|
+
onConflict,
|
|
103
|
+
insert,
|
|
104
|
+
update,
|
|
105
|
+
upsert,
|
|
106
|
+
delete_ as delete,
|
|
107
|
+
truncate,
|
|
108
|
+
merge,
|
|
109
|
+
transaction,
|
|
110
|
+
commit,
|
|
111
|
+
rollback,
|
|
112
|
+
savepoint,
|
|
113
|
+
rollbackTo,
|
|
114
|
+
releaseSavepoint,
|
|
115
|
+
createTable,
|
|
116
|
+
dropTable,
|
|
117
|
+
createIndex,
|
|
118
|
+
dropIndex,
|
|
119
|
+
union,
|
|
120
|
+
unionAll,
|
|
121
|
+
intersect,
|
|
122
|
+
intersectAll,
|
|
123
|
+
except,
|
|
124
|
+
exceptAll,
|
|
125
|
+
where,
|
|
126
|
+
having,
|
|
127
|
+
innerJoin,
|
|
128
|
+
leftJoin,
|
|
129
|
+
rightJoin,
|
|
130
|
+
fullJoin,
|
|
131
|
+
crossJoin,
|
|
132
|
+
distinct,
|
|
133
|
+
distinctOn,
|
|
134
|
+
limit,
|
|
135
|
+
offset,
|
|
136
|
+
lock,
|
|
137
|
+
orderBy,
|
|
138
|
+
groupBy
|
|
139
|
+
} from "./internal/dsl.js"
|
|
140
|
+
export { postgresType as type }
|
|
141
|
+
export const generateSeries: PublicGenerateSeriesApi = dslGenerateSeries as PublicGenerateSeriesApi
|
|
142
|
+
|
|
143
|
+
type StructuredSource = AnyValuesSource | AnyUnnestSource | AnyTableFunctionSource
|
|
144
|
+
|
|
145
|
+
type StructuredFromApi = <CurrentSource extends StructuredSource>(
|
|
146
|
+
source: CurrentSource
|
|
147
|
+
) => <PlanValue extends QueryPlan<any, any, any, any, any, any, any, any, any, any>>(
|
|
148
|
+
plan: PlanValue & PublicStructuredFromConstraint<PlanValue, CurrentSource, "postgres">
|
|
149
|
+
) => PublicStructuredFromResult<PlanValue, CurrentSource, "postgres">
|
|
39
150
|
|
|
40
|
-
export const
|
|
41
|
-
export const column = postgresQuery.column
|
|
42
|
-
export const eq = postgresQuery.eq
|
|
43
|
-
export const neq = postgresQuery.neq
|
|
44
|
-
export const lt = postgresQuery.lt
|
|
45
|
-
export const lte = postgresQuery.lte
|
|
46
|
-
export const gt = postgresQuery.gt
|
|
47
|
-
export const gte = postgresQuery.gte
|
|
48
|
-
export const isNull = postgresQuery.isNull
|
|
49
|
-
export const isNotNull = postgresQuery.isNotNull
|
|
50
|
-
export const like = postgresQuery.like
|
|
51
|
-
export const ilike = postgresQuery.ilike
|
|
52
|
-
export const regexMatch = postgresQuery.regexMatch
|
|
53
|
-
export const regexIMatch = postgresQuery.regexIMatch
|
|
54
|
-
export const regexNotMatch = postgresQuery.regexNotMatch
|
|
55
|
-
export const regexNotIMatch = postgresQuery.regexNotIMatch
|
|
56
|
-
export const and = postgresQuery.and
|
|
57
|
-
export const or = postgresQuery.or
|
|
58
|
-
export const not = postgresQuery.not
|
|
59
|
-
export const all = postgresQuery.all
|
|
60
|
-
export const any = postgresQuery.any
|
|
61
|
-
const case_ = postgresQuery.case
|
|
62
|
-
export const match = postgresQuery.match
|
|
63
|
-
export const in_ = postgresQuery.in
|
|
64
|
-
export const notIn = postgresQuery.notIn
|
|
65
|
-
export const between = postgresQuery.between
|
|
66
|
-
export const contains = postgresQuery.contains
|
|
67
|
-
export const containedBy = postgresQuery.containedBy
|
|
68
|
-
export const overlaps = postgresQuery.overlaps
|
|
69
|
-
export const exists = postgresQuery.exists
|
|
70
|
-
export const isDistinctFrom = postgresQuery.isDistinctFrom
|
|
71
|
-
export const isNotDistinctFrom = postgresQuery.isNotDistinctFrom
|
|
72
|
-
export const excluded = postgresQuery.excluded
|
|
73
|
-
export const as = postgresQuery.as
|
|
74
|
-
export const with_ = postgresQuery.with
|
|
75
|
-
export const withRecursive = postgresQuery.withRecursive
|
|
76
|
-
export const lateral = postgresQuery.lateral
|
|
77
|
-
export const scalar = postgresQuery.scalar
|
|
78
|
-
export const inSubquery = postgresQuery.inSubquery
|
|
79
|
-
export const compareAny = postgresQuery.compareAny
|
|
80
|
-
export const compareAll = postgresQuery.compareAll
|
|
81
|
-
export const values = postgresQuery.values
|
|
82
|
-
export const unnest = postgresQuery.unnest
|
|
83
|
-
export const generateSeries = postgresQuery.generateSeries
|
|
84
|
-
export const returning = postgresQuery.returning
|
|
85
|
-
export const onConflict = postgresQuery.onConflict
|
|
86
|
-
export const insert = postgresQuery.insert
|
|
87
|
-
export const update = postgresQuery.update
|
|
88
|
-
export const upsert = postgresQuery.upsert
|
|
89
|
-
export const delete_ = postgresQuery.delete
|
|
90
|
-
export const truncate = postgresQuery.truncate
|
|
91
|
-
export const merge = postgresQuery.merge
|
|
92
|
-
export const transaction = postgresQuery.transaction
|
|
93
|
-
export const commit = postgresQuery.commit
|
|
94
|
-
export const rollback = postgresQuery.rollback
|
|
95
|
-
export const savepoint = postgresQuery.savepoint
|
|
96
|
-
export const rollbackTo = postgresQuery.rollbackTo
|
|
97
|
-
export const releaseSavepoint = postgresQuery.releaseSavepoint
|
|
98
|
-
export const createTable = postgresQuery.createTable
|
|
99
|
-
export const dropTable = postgresQuery.dropTable
|
|
100
|
-
export const createIndex = postgresQuery.createIndex
|
|
101
|
-
export const dropIndex = postgresQuery.dropIndex
|
|
102
|
-
export const union = postgresQuery.union
|
|
103
|
-
export const unionAll = postgresQuery.unionAll
|
|
104
|
-
export const intersect = postgresQuery.intersect
|
|
105
|
-
export const intersectAll = postgresQuery.intersectAll
|
|
106
|
-
export const except = postgresQuery.except
|
|
107
|
-
export const exceptAll = postgresQuery.exceptAll
|
|
108
|
-
export const select = postgresQuery.select
|
|
109
|
-
export const where = postgresQuery.where
|
|
110
|
-
export const having = postgresQuery.having
|
|
111
|
-
export const from = postgresQuery.from
|
|
112
|
-
export const innerJoin = postgresQuery.innerJoin
|
|
113
|
-
export const leftJoin = postgresQuery.leftJoin
|
|
114
|
-
export const rightJoin = postgresQuery.rightJoin
|
|
115
|
-
export const fullJoin = postgresQuery.fullJoin
|
|
116
|
-
export const crossJoin = postgresQuery.crossJoin
|
|
117
|
-
export const distinct = postgresQuery.distinct
|
|
118
|
-
export const distinctOn = postgresQuery.distinctOn
|
|
119
|
-
export const limit = postgresQuery.limit
|
|
120
|
-
export const offset = postgresQuery.offset
|
|
121
|
-
export const lock = postgresQuery.lock
|
|
122
|
-
export const orderBy = postgresQuery.orderBy
|
|
123
|
-
export const groupBy = postgresQuery.groupBy
|
|
124
|
-
export { case_ as case }
|
|
125
|
-
export { in_ as in }
|
|
126
|
-
export { with_ as with }
|
|
127
|
-
export { delete_ as delete }
|
|
151
|
+
export const from: StructuredFromApi & PublicNonStructuredFromApi = dslFrom as StructuredFromApi & PublicNonStructuredFromApi
|
|
128
152
|
|
|
129
153
|
export type {
|
|
130
154
|
CapabilitiesOfPlan,
|
package/src/postgres/renderer.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as CoreRenderer from "../internal/renderer.js"
|
|
2
|
+
import { renderPostgresPlan } from "./internal/renderer.js"
|
|
2
3
|
|
|
3
4
|
/** Postgres-specialized rendered query shape. */
|
|
4
5
|
export type RenderedQuery<Row> = CoreRenderer.RenderedQuery<Row, "postgres">
|
|
@@ -11,19 +12,8 @@ export { TypeId } from "../internal/renderer.js"
|
|
|
11
12
|
export type { Projection } from "../internal/renderer.js"
|
|
12
13
|
|
|
13
14
|
/** Creates the built-in Postgres renderer. */
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
export function make(
|
|
17
|
-
dialect: "postgres",
|
|
18
|
-
render: Parameters<typeof CoreRenderer.make>[1]
|
|
19
|
-
): Renderer
|
|
20
|
-
export function make(
|
|
21
|
-
dialectOrRender?: "postgres" | Parameters<typeof CoreRenderer.make>[1],
|
|
22
|
-
render?: Parameters<typeof CoreRenderer.make>[1]
|
|
23
|
-
): Renderer {
|
|
24
|
-
const customRender = typeof dialectOrRender === "function" ? dialectOrRender : render
|
|
25
|
-
return customRender ? CoreRenderer.make("postgres", customRender as any) : CoreRenderer.make("postgres")
|
|
26
|
-
}
|
|
15
|
+
export const make = (): Renderer =>
|
|
16
|
+
CoreRenderer.make("postgres", renderPostgresPlan)
|
|
27
17
|
|
|
28
18
|
/** Shared built-in Postgres renderer instance. */
|
|
29
19
|
export const postgres = make()
|