effect-qb 0.12.3 → 0.14.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 -1283
- package/dist/mysql.js +6376 -4978
- package/dist/postgres/metadata.js +2724 -0
- package/dist/postgres.js +5475 -3636
- package/package.json +13 -8
- package/src/internal/column-state.ts +88 -6
- package/src/internal/column.ts +569 -34
- package/src/internal/datatypes/define.ts +0 -30
- package/src/internal/executor.ts +45 -11
- package/src/internal/expression-ast.ts +15 -0
- package/src/internal/expression.ts +3 -1
- package/src/internal/implication-runtime.ts +171 -0
- package/src/internal/mysql-query.ts +7173 -0
- package/src/internal/mysql-renderer.ts +2 -2
- package/src/internal/plan.ts +14 -4
- package/src/internal/{query-factory.ts → postgres-query.ts} +669 -230
- package/src/internal/postgres-renderer.ts +2 -2
- package/src/internal/postgres-schema-model.ts +144 -0
- package/src/internal/predicate-analysis.ts +10 -0
- package/src/internal/predicate-context.ts +112 -36
- package/src/internal/predicate-formula.ts +31 -19
- package/src/internal/predicate-normalize.ts +177 -106
- package/src/internal/predicate-runtime.ts +676 -0
- package/src/internal/query.ts +471 -41
- package/src/internal/renderer.ts +2 -2
- package/src/internal/runtime-schema.ts +74 -20
- package/src/internal/schema-ddl.ts +55 -0
- package/src/internal/schema-derivation.ts +93 -21
- package/src/internal/schema-expression.ts +44 -0
- package/src/internal/sql-expression-renderer.ts +123 -35
- package/src/internal/table-options.ts +88 -7
- package/src/internal/table.ts +106 -42
- package/src/mysql/column.ts +3 -1
- package/src/mysql/datatypes/index.ts +17 -2
- package/src/mysql/executor.ts +20 -17
- package/src/mysql/function/aggregate.ts +6 -0
- package/src/mysql/function/core.ts +5 -0
- package/src/mysql/function/index.ts +20 -0
- package/src/mysql/function/json.ts +4 -0
- package/src/mysql/function/string.ts +6 -0
- package/src/mysql/function/temporal.ts +103 -0
- package/src/mysql/function/window.ts +7 -0
- package/src/mysql/private/query.ts +1 -0
- package/src/mysql/query.ts +6 -26
- package/src/mysql.ts +2 -0
- package/src/postgres/cast.ts +31 -0
- package/src/postgres/column.ts +27 -1
- package/src/postgres/datatypes/index.ts +40 -5
- package/src/postgres/executor.ts +19 -17
- package/src/postgres/function/aggregate.ts +6 -0
- package/src/postgres/function/core.ts +16 -0
- package/src/postgres/function/index.ts +20 -0
- package/src/postgres/function/json.ts +501 -0
- package/src/postgres/function/string.ts +6 -0
- package/src/postgres/function/temporal.ts +107 -0
- package/src/postgres/function/window.ts +7 -0
- package/src/postgres/metadata.ts +31 -0
- package/src/postgres/private/query.ts +1 -0
- package/src/postgres/query.ts +6 -28
- package/src/postgres/schema-expression.ts +16 -0
- package/src/postgres/schema-management.ts +204 -0
- package/src/postgres/schema.ts +35 -0
- package/src/postgres/table.ts +307 -41
- package/src/postgres/type.ts +4 -0
- package/src/postgres.ts +16 -0
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
import * as Expression from "../../internal/expression.js"
|
|
2
|
+
import type { JsonPathUsageError } from "../../internal/json/errors.js"
|
|
3
|
+
import * as JsonPath from "../../internal/json/path.js"
|
|
4
|
+
import type {
|
|
5
|
+
JsonDeleteAtPath,
|
|
6
|
+
JsonInsertAtPath,
|
|
7
|
+
JsonSetAtPath,
|
|
8
|
+
JsonValueAtPath
|
|
9
|
+
} from "../../internal/json/types.js"
|
|
10
|
+
import { postgresQuery } from "../private/query.js"
|
|
11
|
+
|
|
12
|
+
type PostgresJsonExpression<Runtime = unknown> = Expression.Expression<
|
|
13
|
+
Runtime,
|
|
14
|
+
Expression.DbType.Json<"postgres", "json" | "jsonb">,
|
|
15
|
+
Expression.Nullability,
|
|
16
|
+
string,
|
|
17
|
+
Expression.AggregationKind,
|
|
18
|
+
any,
|
|
19
|
+
Expression.SourceDependencies,
|
|
20
|
+
Expression.SourceNullabilityMode
|
|
21
|
+
>
|
|
22
|
+
|
|
23
|
+
type PostgresJsonbExpression<Runtime = unknown> = Expression.Expression<
|
|
24
|
+
Runtime,
|
|
25
|
+
Expression.DbType.Json<"postgres", "jsonb">,
|
|
26
|
+
Expression.Nullability,
|
|
27
|
+
string,
|
|
28
|
+
Expression.AggregationKind,
|
|
29
|
+
any,
|
|
30
|
+
Expression.SourceDependencies,
|
|
31
|
+
Expression.SourceNullabilityMode
|
|
32
|
+
>
|
|
33
|
+
|
|
34
|
+
type ExactJsonPathInput = JsonPath.ExactSegment | JsonPath.Path<any>
|
|
35
|
+
|
|
36
|
+
type ExactJsonPathUsageError<Target> = {
|
|
37
|
+
readonly __effect_qb_error__: "effect-qb: postgres json helpers only accept exact key/index paths"
|
|
38
|
+
readonly __effect_qb_json_path__: Target
|
|
39
|
+
readonly __effect_qb_hint__: "Use Postgres.Function.jsonb.path(...) when you need wildcard(), slice(), or descend() segments"
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type ExactJsonPathGuard<Target> = Target extends JsonPath.Path<any>
|
|
43
|
+
? JsonPath.IsExactPath<Target> extends true ? unknown : ExactJsonPathUsageError<Target>
|
|
44
|
+
: Target extends JsonPath.ExactSegment
|
|
45
|
+
? unknown
|
|
46
|
+
: ExactJsonPathUsageError<Target>
|
|
47
|
+
|
|
48
|
+
type ExactJsonPathSegmentsGuard<Segments extends readonly JsonPath.CanonicalSegment[]> =
|
|
49
|
+
JsonPath.IsExactPath<JsonPath.Path<Segments>> extends true ? unknown : ExactJsonPathUsageError<JsonPath.Path<Segments>>
|
|
50
|
+
|
|
51
|
+
type JsonPathOutputOf<
|
|
52
|
+
Root,
|
|
53
|
+
Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment,
|
|
54
|
+
Operation extends string
|
|
55
|
+
> = Target extends JsonPath.Path<any>
|
|
56
|
+
? JsonValueAtPath<Root, Target, Operation>
|
|
57
|
+
: Target extends JsonPath.CanonicalSegment
|
|
58
|
+
? JsonValueAtPath<Root, JsonPath.Path<[Target]>, Operation>
|
|
59
|
+
: never
|
|
60
|
+
|
|
61
|
+
type JsonDeleteOutputOf<
|
|
62
|
+
Root,
|
|
63
|
+
Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment,
|
|
64
|
+
Operation extends string
|
|
65
|
+
> = Target extends JsonPath.Path<any>
|
|
66
|
+
? JsonDeleteAtPath<Root, Target, Operation>
|
|
67
|
+
: Target extends JsonPath.CanonicalSegment
|
|
68
|
+
? JsonDeleteAtPath<Root, JsonPath.Path<[Target]>, Operation>
|
|
69
|
+
: never
|
|
70
|
+
|
|
71
|
+
type JsonSetOutputOf<
|
|
72
|
+
Root,
|
|
73
|
+
Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment,
|
|
74
|
+
Next,
|
|
75
|
+
Operation extends string
|
|
76
|
+
> = Target extends JsonPath.Path<any>
|
|
77
|
+
? JsonSetAtPath<Root, Target, Next, Operation>
|
|
78
|
+
: Target extends JsonPath.CanonicalSegment
|
|
79
|
+
? JsonSetAtPath<Root, JsonPath.Path<[Target]>, Next, Operation>
|
|
80
|
+
: never
|
|
81
|
+
|
|
82
|
+
type JsonInsertOutputOf<
|
|
83
|
+
Root,
|
|
84
|
+
Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment,
|
|
85
|
+
Next,
|
|
86
|
+
InsertAfter extends boolean,
|
|
87
|
+
Operation extends string
|
|
88
|
+
> = Target extends JsonPath.Path<any>
|
|
89
|
+
? JsonInsertAtPath<Root, Target, Next, InsertAfter, Operation>
|
|
90
|
+
: Target extends JsonPath.CanonicalSegment
|
|
91
|
+
? JsonInsertAtPath<Root, JsonPath.Path<[Target]>, Next, InsertAfter, Operation>
|
|
92
|
+
: never
|
|
93
|
+
|
|
94
|
+
type JsonValuePathGuard<
|
|
95
|
+
Root,
|
|
96
|
+
Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment,
|
|
97
|
+
Operation extends string
|
|
98
|
+
> = JsonPathOutputOf<Root, Target, Operation> extends JsonPathUsageError<any, any, any, any>
|
|
99
|
+
? JsonPathOutputOf<Root, Target, Operation>
|
|
100
|
+
: unknown
|
|
101
|
+
|
|
102
|
+
type JsonDeletePathGuard<
|
|
103
|
+
Root,
|
|
104
|
+
Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment,
|
|
105
|
+
Operation extends string
|
|
106
|
+
> = JsonDeleteOutputOf<Root, Target, Operation> extends JsonPathUsageError<any, any, any, any>
|
|
107
|
+
? JsonDeleteOutputOf<Root, Target, Operation>
|
|
108
|
+
: unknown
|
|
109
|
+
|
|
110
|
+
type JsonSetPathGuard<
|
|
111
|
+
Root,
|
|
112
|
+
Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment,
|
|
113
|
+
Next,
|
|
114
|
+
Operation extends string
|
|
115
|
+
> = JsonSetOutputOf<Root, Target, Next, Operation> extends JsonPathUsageError<any, any, any, any>
|
|
116
|
+
? JsonSetOutputOf<Root, Target, Next, Operation>
|
|
117
|
+
: unknown
|
|
118
|
+
|
|
119
|
+
type JsonInsertPathGuard<
|
|
120
|
+
Root,
|
|
121
|
+
Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment,
|
|
122
|
+
Next,
|
|
123
|
+
InsertAfter extends boolean,
|
|
124
|
+
Operation extends string
|
|
125
|
+
> = JsonInsertOutputOf<Root, Target, Next, InsertAfter, Operation> extends JsonPathUsageError<any, any, any, any>
|
|
126
|
+
? JsonInsertOutputOf<Root, Target, Next, InsertAfter, Operation>
|
|
127
|
+
: unknown
|
|
128
|
+
|
|
129
|
+
type JsonbOnlyUsageError<
|
|
130
|
+
Operation extends string,
|
|
131
|
+
Value extends PostgresJsonExpression<any>
|
|
132
|
+
> = {
|
|
133
|
+
readonly __effect_qb_error__: "effect-qb: postgres jsonb helpers require a jsonb expression"
|
|
134
|
+
readonly __effect_qb_json_operation__: Operation
|
|
135
|
+
readonly __effect_qb_received_kind__: Expression.DbTypeOf<Value>["kind"]
|
|
136
|
+
readonly __effect_qb_hint__: "Use Column.jsonb(...), Cast.to(..., Type.jsonb()), or Postgres.Function.jsonb.toJsonb(...)"
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
type JsonbBaseGuard<
|
|
140
|
+
Base extends PostgresJsonExpression<any>,
|
|
141
|
+
Operation extends string
|
|
142
|
+
> = Expression.DbTypeOf<Base> extends Expression.DbType.Json<"postgres", "jsonb">
|
|
143
|
+
? unknown
|
|
144
|
+
: JsonbOnlyUsageError<Operation, Base>
|
|
145
|
+
|
|
146
|
+
type JsonNullabilityOf<Output> =
|
|
147
|
+
null extends Output
|
|
148
|
+
? Exclude<Output, null> extends never ? "always" : "maybe"
|
|
149
|
+
: "never"
|
|
150
|
+
|
|
151
|
+
type JsonResultExpression<
|
|
152
|
+
Runtime,
|
|
153
|
+
Db extends Expression.DbType.Json<any, any>
|
|
154
|
+
> = Expression.Expression<
|
|
155
|
+
Runtime,
|
|
156
|
+
Db,
|
|
157
|
+
JsonNullabilityOf<Runtime>,
|
|
158
|
+
string,
|
|
159
|
+
Expression.AggregationKind,
|
|
160
|
+
any,
|
|
161
|
+
Expression.SourceDependencies,
|
|
162
|
+
Expression.SourceNullabilityMode
|
|
163
|
+
>
|
|
164
|
+
|
|
165
|
+
type JsonDbOf<Base extends PostgresJsonExpression<any>> =
|
|
166
|
+
Expression.DbTypeOf<Base> extends Expression.DbType.Json<"postgres", infer Variant>
|
|
167
|
+
? Expression.DbType.Json<"postgres", Variant>
|
|
168
|
+
: Expression.DbType.Json<"postgres", "json">
|
|
169
|
+
|
|
170
|
+
type JsonGetResultExpression<
|
|
171
|
+
Base extends PostgresJsonExpression<any>,
|
|
172
|
+
Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment,
|
|
173
|
+
Operation extends string
|
|
174
|
+
> = JsonResultExpression<
|
|
175
|
+
JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, Operation>,
|
|
176
|
+
JsonDbOf<Base>
|
|
177
|
+
>
|
|
178
|
+
|
|
179
|
+
type JsonTextRuntime<
|
|
180
|
+
Base extends PostgresJsonExpression<any>,
|
|
181
|
+
Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment
|
|
182
|
+
> =
|
|
183
|
+
Extract<JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, "json.text">, string> |
|
|
184
|
+
(null extends JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, "json.text"> ? null : never)
|
|
185
|
+
|
|
186
|
+
type JsonTextResultExpression<
|
|
187
|
+
Base extends PostgresJsonExpression<any>,
|
|
188
|
+
Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment
|
|
189
|
+
> = Expression.Expression<
|
|
190
|
+
JsonTextRuntime<Base, Target>,
|
|
191
|
+
Expression.DbType.PgText,
|
|
192
|
+
JsonNullabilityOf<JsonTextRuntime<Base, Target>>,
|
|
193
|
+
string,
|
|
194
|
+
Expression.AggregationKind,
|
|
195
|
+
any,
|
|
196
|
+
Expression.SourceDependencies,
|
|
197
|
+
Expression.SourceNullabilityMode
|
|
198
|
+
>
|
|
199
|
+
|
|
200
|
+
const exactPath = <Segments extends readonly JsonPath.CanonicalSegment[]>(
|
|
201
|
+
...segments: Segments & ExactJsonPathSegmentsGuard<Segments>
|
|
202
|
+
): JsonPath.Path<Segments> => JsonPath.path(...segments) as unknown as JsonPath.Path<Segments>
|
|
203
|
+
|
|
204
|
+
const jsonGetDirect = <
|
|
205
|
+
Base extends PostgresJsonExpression<any>,
|
|
206
|
+
Target extends ExactJsonPathInput
|
|
207
|
+
>(
|
|
208
|
+
base: Base,
|
|
209
|
+
target: Target & ExactJsonPathGuard<Target>
|
|
210
|
+
): JsonGetResultExpression<Base, Target, "json.get"> =>
|
|
211
|
+
postgresQuery.json.get(base as never, target as never) as unknown as JsonGetResultExpression<Base, Target, "json.get">
|
|
212
|
+
|
|
213
|
+
const jsonTextDirect = <
|
|
214
|
+
Base extends PostgresJsonExpression<any>,
|
|
215
|
+
Target extends ExactJsonPathInput
|
|
216
|
+
>(
|
|
217
|
+
base: Base,
|
|
218
|
+
target: Target & ExactJsonPathGuard<Target>
|
|
219
|
+
): JsonTextResultExpression<Base, Target> =>
|
|
220
|
+
postgresQuery.json.text(base as never, target as never) as unknown as JsonTextResultExpression<Base, Target>
|
|
221
|
+
|
|
222
|
+
const json = {
|
|
223
|
+
key: postgresQuery.json.key,
|
|
224
|
+
index: postgresQuery.json.index,
|
|
225
|
+
path: exactPath,
|
|
226
|
+
get: ((...args: [PostgresJsonExpression<any>, ExactJsonPathInput] | [ExactJsonPathInput]) =>
|
|
227
|
+
args.length === 1
|
|
228
|
+
? ((base: PostgresJsonExpression<any>) => jsonGetDirect(base as never, args[0] as never))
|
|
229
|
+
: jsonGetDirect(args[0] as never, args[1] as never)) as unknown as
|
|
230
|
+
typeof jsonGetDirect & {
|
|
231
|
+
<Target extends ExactJsonPathInput>(
|
|
232
|
+
target: Target & ExactJsonPathGuard<Target>
|
|
233
|
+
): <Base extends PostgresJsonExpression<any>>(base: Base) => ReturnType<typeof jsonGetDirect>
|
|
234
|
+
},
|
|
235
|
+
access: <
|
|
236
|
+
Base extends PostgresJsonExpression<any>,
|
|
237
|
+
Target extends ExactJsonPathInput
|
|
238
|
+
>(
|
|
239
|
+
base: Base,
|
|
240
|
+
target: Target & ExactJsonPathGuard<Target> & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.access">
|
|
241
|
+
) => postgresQuery.json.access(base, target),
|
|
242
|
+
traverse: <
|
|
243
|
+
Base extends PostgresJsonExpression<any>,
|
|
244
|
+
Target extends ExactJsonPathInput
|
|
245
|
+
>(
|
|
246
|
+
base: Base,
|
|
247
|
+
target: Target & ExactJsonPathGuard<Target> & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.traverse">
|
|
248
|
+
) => postgresQuery.json.traverse(base, target),
|
|
249
|
+
text: ((...args: [PostgresJsonExpression<any>, ExactJsonPathInput] | [ExactJsonPathInput]) =>
|
|
250
|
+
args.length === 1
|
|
251
|
+
? ((base: PostgresJsonExpression<any>) => jsonTextDirect(base as never, args[0] as never))
|
|
252
|
+
: jsonTextDirect(args[0] as never, args[1] as never)) as unknown as
|
|
253
|
+
typeof jsonTextDirect & {
|
|
254
|
+
<Target extends ExactJsonPathInput>(
|
|
255
|
+
target: Target & ExactJsonPathGuard<Target>
|
|
256
|
+
): <Base extends PostgresJsonExpression<any>>(base: Base) => ReturnType<typeof jsonTextDirect>
|
|
257
|
+
},
|
|
258
|
+
accessText: <
|
|
259
|
+
Base extends PostgresJsonExpression<any>,
|
|
260
|
+
Target extends ExactJsonPathInput
|
|
261
|
+
>(
|
|
262
|
+
base: Base,
|
|
263
|
+
target: Target & ExactJsonPathGuard<Target> & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.accessText">
|
|
264
|
+
) => postgresQuery.json.accessText(base, target),
|
|
265
|
+
traverseText: <
|
|
266
|
+
Base extends PostgresJsonExpression<any>,
|
|
267
|
+
Target extends ExactJsonPathInput
|
|
268
|
+
>(
|
|
269
|
+
base: Base,
|
|
270
|
+
target: Target & ExactJsonPathGuard<Target> & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.traverseText">
|
|
271
|
+
) => postgresQuery.json.traverseText(base, target),
|
|
272
|
+
buildObject: postgresQuery.json.buildObject,
|
|
273
|
+
buildArray: postgresQuery.json.buildArray,
|
|
274
|
+
toJson: postgresQuery.json.toJson,
|
|
275
|
+
typeOf: postgresQuery.json.typeOf,
|
|
276
|
+
length: postgresQuery.json.length,
|
|
277
|
+
keys: postgresQuery.json.keys,
|
|
278
|
+
stripNulls: postgresQuery.json.stripNulls,
|
|
279
|
+
delete: <
|
|
280
|
+
Base extends PostgresJsonExpression<any>,
|
|
281
|
+
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
|
|
282
|
+
>(
|
|
283
|
+
base: Base,
|
|
284
|
+
target: Target & JsonDeletePathGuard<Expression.RuntimeOf<Base>, Target, "json.delete">
|
|
285
|
+
): JsonResultExpression<
|
|
286
|
+
JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.delete">,
|
|
287
|
+
Expression.DbTypeOf<Base>
|
|
288
|
+
> => postgresQuery.json.delete(base as any, target as any) as unknown as JsonResultExpression<
|
|
289
|
+
JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.delete">,
|
|
290
|
+
Expression.DbTypeOf<Base>
|
|
291
|
+
>,
|
|
292
|
+
remove: <
|
|
293
|
+
Base extends PostgresJsonExpression<any>,
|
|
294
|
+
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
|
|
295
|
+
>(
|
|
296
|
+
base: Base,
|
|
297
|
+
target: Target & JsonDeletePathGuard<Expression.RuntimeOf<Base>, Target, "json.remove">
|
|
298
|
+
): JsonResultExpression<
|
|
299
|
+
JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.remove">,
|
|
300
|
+
Expression.DbTypeOf<Base>
|
|
301
|
+
> => postgresQuery.json.remove(base as any, target as any) as unknown as JsonResultExpression<
|
|
302
|
+
JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.remove">,
|
|
303
|
+
Expression.DbTypeOf<Base>
|
|
304
|
+
>
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const jsonb = {
|
|
308
|
+
key: postgresQuery.jsonb.key,
|
|
309
|
+
index: postgresQuery.jsonb.index,
|
|
310
|
+
wildcard: postgresQuery.jsonb.wildcard,
|
|
311
|
+
slice: postgresQuery.jsonb.slice,
|
|
312
|
+
descend: postgresQuery.jsonb.descend,
|
|
313
|
+
path: postgresQuery.jsonb.path,
|
|
314
|
+
get: <
|
|
315
|
+
Base extends PostgresJsonExpression<any>,
|
|
316
|
+
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
|
|
317
|
+
>(
|
|
318
|
+
base: Base & JsonbBaseGuard<Base, "jsonb.get">,
|
|
319
|
+
target: Target & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.get">
|
|
320
|
+
) => postgresQuery.jsonb.get(base as Base, target),
|
|
321
|
+
access: <
|
|
322
|
+
Base extends PostgresJsonExpression<any>,
|
|
323
|
+
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
|
|
324
|
+
>(
|
|
325
|
+
base: Base & JsonbBaseGuard<Base, "jsonb.access">,
|
|
326
|
+
target: Target & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.access">
|
|
327
|
+
) => postgresQuery.jsonb.access(base as Base, target),
|
|
328
|
+
traverse: <
|
|
329
|
+
Base extends PostgresJsonExpression<any>,
|
|
330
|
+
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
|
|
331
|
+
>(
|
|
332
|
+
base: Base & JsonbBaseGuard<Base, "jsonb.traverse">,
|
|
333
|
+
target: Target & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.traverse">
|
|
334
|
+
) => postgresQuery.jsonb.traverse(base as Base, target),
|
|
335
|
+
text: <
|
|
336
|
+
Base extends PostgresJsonExpression<any>,
|
|
337
|
+
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
|
|
338
|
+
>(
|
|
339
|
+
base: Base & JsonbBaseGuard<Base, "jsonb.text">,
|
|
340
|
+
target: Target & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.text">
|
|
341
|
+
) => postgresQuery.jsonb.text(base as Base, target),
|
|
342
|
+
accessText: <
|
|
343
|
+
Base extends PostgresJsonExpression<any>,
|
|
344
|
+
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
|
|
345
|
+
>(
|
|
346
|
+
base: Base & JsonbBaseGuard<Base, "jsonb.accessText">,
|
|
347
|
+
target: Target & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.accessText">
|
|
348
|
+
) => postgresQuery.jsonb.accessText(base as Base, target),
|
|
349
|
+
traverseText: <
|
|
350
|
+
Base extends PostgresJsonExpression<any>,
|
|
351
|
+
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
|
|
352
|
+
>(
|
|
353
|
+
base: Base & JsonbBaseGuard<Base, "jsonb.traverseText">,
|
|
354
|
+
target: Target & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.traverseText">
|
|
355
|
+
) => postgresQuery.jsonb.traverseText(base as Base, target),
|
|
356
|
+
contains: <
|
|
357
|
+
Left extends PostgresJsonExpression<any>,
|
|
358
|
+
Right extends Parameters<typeof postgresQuery.jsonb.contains>[1]
|
|
359
|
+
>(
|
|
360
|
+
left: Left & JsonbBaseGuard<Left, "jsonb.contains">,
|
|
361
|
+
right: Right
|
|
362
|
+
) => postgresQuery.jsonb.contains(left as Left, right),
|
|
363
|
+
containedBy: <
|
|
364
|
+
Left extends PostgresJsonExpression<any>,
|
|
365
|
+
Right extends Parameters<typeof postgresQuery.jsonb.containedBy>[1]
|
|
366
|
+
>(
|
|
367
|
+
left: Left & JsonbBaseGuard<Left, "jsonb.containedBy">,
|
|
368
|
+
right: Right
|
|
369
|
+
) => postgresQuery.jsonb.containedBy(left as Left, right),
|
|
370
|
+
hasKey: <
|
|
371
|
+
Base extends PostgresJsonExpression<any>,
|
|
372
|
+
Key extends string
|
|
373
|
+
>(
|
|
374
|
+
base: Base & JsonbBaseGuard<Base, "jsonb.hasKey">,
|
|
375
|
+
key: Key
|
|
376
|
+
) => postgresQuery.jsonb.hasKey(base as Base, key),
|
|
377
|
+
keyExists: <
|
|
378
|
+
Base extends PostgresJsonExpression<any>,
|
|
379
|
+
Key extends string
|
|
380
|
+
>(
|
|
381
|
+
base: Base & JsonbBaseGuard<Base, "jsonb.keyExists">,
|
|
382
|
+
key: Key
|
|
383
|
+
) => postgresQuery.jsonb.keyExists(base as Base, key),
|
|
384
|
+
hasAnyKeys: <
|
|
385
|
+
Base extends PostgresJsonExpression<any>,
|
|
386
|
+
Keys extends readonly [string, ...string[]]
|
|
387
|
+
>(
|
|
388
|
+
base: Base & JsonbBaseGuard<Base, "jsonb.hasAnyKeys">,
|
|
389
|
+
...keys: Keys
|
|
390
|
+
) => postgresQuery.jsonb.hasAnyKeys(base as Base, ...keys),
|
|
391
|
+
hasAllKeys: <
|
|
392
|
+
Base extends PostgresJsonExpression<any>,
|
|
393
|
+
Keys extends readonly [string, ...string[]]
|
|
394
|
+
>(
|
|
395
|
+
base: Base & JsonbBaseGuard<Base, "jsonb.hasAllKeys">,
|
|
396
|
+
...keys: Keys
|
|
397
|
+
) => postgresQuery.jsonb.hasAllKeys(base as Base, ...keys),
|
|
398
|
+
delete: <
|
|
399
|
+
Base extends PostgresJsonExpression<any>,
|
|
400
|
+
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
|
|
401
|
+
>(
|
|
402
|
+
base: Base & JsonbBaseGuard<Base, "jsonb.delete">,
|
|
403
|
+
target: Target & JsonDeletePathGuard<Expression.RuntimeOf<Base>, Target, "json.delete">
|
|
404
|
+
): JsonResultExpression<
|
|
405
|
+
JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.delete">,
|
|
406
|
+
Expression.DbTypeOf<Base>
|
|
407
|
+
> => postgresQuery.jsonb.delete(base as any, target as any) as unknown as JsonResultExpression<
|
|
408
|
+
JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.delete">,
|
|
409
|
+
Expression.DbTypeOf<Base>
|
|
410
|
+
>,
|
|
411
|
+
remove: <
|
|
412
|
+
Base extends PostgresJsonExpression<any>,
|
|
413
|
+
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
|
|
414
|
+
>(
|
|
415
|
+
base: Base & JsonbBaseGuard<Base, "jsonb.remove">,
|
|
416
|
+
target: Target & JsonDeletePathGuard<Expression.RuntimeOf<Base>, Target, "json.remove">
|
|
417
|
+
): JsonResultExpression<
|
|
418
|
+
JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.remove">,
|
|
419
|
+
Expression.DbTypeOf<Base>
|
|
420
|
+
> => postgresQuery.jsonb.remove(base as any, target as any) as unknown as JsonResultExpression<
|
|
421
|
+
JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.remove">,
|
|
422
|
+
Expression.DbTypeOf<Base>
|
|
423
|
+
>,
|
|
424
|
+
set: <
|
|
425
|
+
Base extends PostgresJsonExpression<any>,
|
|
426
|
+
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>,
|
|
427
|
+
Next extends Parameters<typeof postgresQuery.jsonb.set>[2]
|
|
428
|
+
>(
|
|
429
|
+
base: Base & JsonbBaseGuard<Base, "jsonb.set">,
|
|
430
|
+
target: Target & JsonSetPathGuard<Expression.RuntimeOf<Base>, Target, Next, "json.set">,
|
|
431
|
+
next: Next,
|
|
432
|
+
options?: Parameters<typeof postgresQuery.jsonb.set>[3]
|
|
433
|
+
): JsonResultExpression<
|
|
434
|
+
JsonSetOutputOf<Expression.RuntimeOf<Base>, Target, Next, "json.set">,
|
|
435
|
+
Expression.DbTypeOf<Base>
|
|
436
|
+
> => postgresQuery.jsonb.set(base as any, target as any, next, options) as unknown as JsonResultExpression<
|
|
437
|
+
JsonSetOutputOf<Expression.RuntimeOf<Base>, Target, Next, "json.set">,
|
|
438
|
+
Expression.DbTypeOf<Base>
|
|
439
|
+
>,
|
|
440
|
+
insert: <
|
|
441
|
+
Base extends PostgresJsonExpression<any>,
|
|
442
|
+
Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>,
|
|
443
|
+
Next extends Parameters<typeof postgresQuery.jsonb.insert>[2],
|
|
444
|
+
InsertAfter extends boolean = false
|
|
445
|
+
>(
|
|
446
|
+
base: Base & JsonbBaseGuard<Base, "jsonb.insert">,
|
|
447
|
+
target: Target & JsonInsertPathGuard<Expression.RuntimeOf<Base>, Target, Next, InsertAfter, "json.insert">,
|
|
448
|
+
next: Next,
|
|
449
|
+
options?: {
|
|
450
|
+
readonly insertAfter?: InsertAfter
|
|
451
|
+
}
|
|
452
|
+
): JsonResultExpression<
|
|
453
|
+
JsonInsertOutputOf<Expression.RuntimeOf<Base>, Target, Next, InsertAfter, "json.insert">,
|
|
454
|
+
Expression.DbTypeOf<Base>
|
|
455
|
+
> => postgresQuery.jsonb.insert(base as any, target as any, next, options) as unknown as JsonResultExpression<
|
|
456
|
+
JsonInsertOutputOf<Expression.RuntimeOf<Base>, Target, Next, InsertAfter, "json.insert">,
|
|
457
|
+
Expression.DbTypeOf<Base>
|
|
458
|
+
>,
|
|
459
|
+
concat: postgresQuery.jsonb.concat,
|
|
460
|
+
merge: postgresQuery.jsonb.merge,
|
|
461
|
+
buildObject: postgresQuery.jsonb.buildObject,
|
|
462
|
+
buildArray: postgresQuery.jsonb.buildArray,
|
|
463
|
+
toJsonb: postgresQuery.jsonb.toJsonb,
|
|
464
|
+
typeOf: <
|
|
465
|
+
Base extends PostgresJsonExpression<any>
|
|
466
|
+
>(
|
|
467
|
+
base: Base & JsonbBaseGuard<Base, "jsonb.typeOf">
|
|
468
|
+
) => postgresQuery.jsonb.typeOf(base as Base),
|
|
469
|
+
length: <
|
|
470
|
+
Base extends PostgresJsonExpression<any>
|
|
471
|
+
>(
|
|
472
|
+
base: Base & JsonbBaseGuard<Base, "jsonb.length">
|
|
473
|
+
) => postgresQuery.jsonb.length(base as Base),
|
|
474
|
+
keys: <
|
|
475
|
+
Base extends PostgresJsonExpression<any>
|
|
476
|
+
>(
|
|
477
|
+
base: Base & JsonbBaseGuard<Base, "jsonb.keys">
|
|
478
|
+
) => postgresQuery.jsonb.keys(base as Base),
|
|
479
|
+
stripNulls: <
|
|
480
|
+
Base extends PostgresJsonExpression<any>
|
|
481
|
+
>(
|
|
482
|
+
base: Base & JsonbBaseGuard<Base, "jsonb.stripNulls">
|
|
483
|
+
) => postgresQuery.jsonb.stripNulls(base as Base),
|
|
484
|
+
pathExists: <
|
|
485
|
+
Base extends PostgresJsonExpression<any>
|
|
486
|
+
>(
|
|
487
|
+
base: Base & JsonbBaseGuard<Base, "jsonb.pathExists">,
|
|
488
|
+
query: Parameters<typeof postgresQuery.jsonb.pathExists>[1]
|
|
489
|
+
) => postgresQuery.jsonb.pathExists(base as Base, query),
|
|
490
|
+
pathMatch: <
|
|
491
|
+
Base extends PostgresJsonExpression<any>
|
|
492
|
+
>(
|
|
493
|
+
base: Base & JsonbBaseGuard<Base, "jsonb.pathMatch">,
|
|
494
|
+
query: Parameters<typeof postgresQuery.jsonb.pathMatch>[1]
|
|
495
|
+
) => postgresQuery.jsonb.pathMatch(base as Base, query)
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/** Postgres shared JSON helpers for exact paths and functions that work on both json and jsonb. */
|
|
499
|
+
export { json }
|
|
500
|
+
/** Postgres jsonb-only helpers for containment, mutation, wildcard paths, and SQL/JSON path predicates. */
|
|
501
|
+
export { jsonb }
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type * as Schema from "effect/Schema"
|
|
2
|
+
|
|
3
|
+
import type * as Expression from "../../internal/expression.js"
|
|
4
|
+
import type * as ExpressionAst from "../../internal/expression-ast.js"
|
|
5
|
+
import { makeExpression } from "../../internal/query.js"
|
|
6
|
+
import {
|
|
7
|
+
InstantStringSchema,
|
|
8
|
+
LocalDateStringSchema,
|
|
9
|
+
LocalDateTimeStringSchema,
|
|
10
|
+
LocalTimeStringSchema,
|
|
11
|
+
OffsetTimeStringSchema,
|
|
12
|
+
type InstantString,
|
|
13
|
+
type LocalDateString,
|
|
14
|
+
type LocalDateTimeString,
|
|
15
|
+
type LocalTimeString,
|
|
16
|
+
type OffsetTimeString
|
|
17
|
+
} from "../../internal/runtime-value.js"
|
|
18
|
+
|
|
19
|
+
type TemporalExpression<
|
|
20
|
+
Runtime,
|
|
21
|
+
Db extends Expression.DbType.Any,
|
|
22
|
+
Name extends string
|
|
23
|
+
> = Expression.Expression<
|
|
24
|
+
Runtime,
|
|
25
|
+
Db,
|
|
26
|
+
"never",
|
|
27
|
+
"postgres",
|
|
28
|
+
"scalar",
|
|
29
|
+
never,
|
|
30
|
+
{},
|
|
31
|
+
"resolved"
|
|
32
|
+
> & {
|
|
33
|
+
readonly [ExpressionAst.TypeId]: ExpressionAst.FunctionCallNode<Name, readonly []>
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const makeTemporal = <
|
|
37
|
+
Runtime,
|
|
38
|
+
Db extends Expression.DbType.Any,
|
|
39
|
+
Name extends string
|
|
40
|
+
>(
|
|
41
|
+
name: Name,
|
|
42
|
+
dbType: Db,
|
|
43
|
+
runtimeSchema: Schema.Schema<Runtime, any, any>
|
|
44
|
+
): TemporalExpression<Runtime, Db, Name> =>
|
|
45
|
+
makeExpression({
|
|
46
|
+
runtime: undefined as unknown as Runtime,
|
|
47
|
+
dbType,
|
|
48
|
+
runtimeSchema,
|
|
49
|
+
nullability: "never",
|
|
50
|
+
dialect: "postgres",
|
|
51
|
+
aggregation: "scalar",
|
|
52
|
+
source: undefined as never,
|
|
53
|
+
dependencies: {},
|
|
54
|
+
sourceNullability: "resolved"
|
|
55
|
+
}, {
|
|
56
|
+
kind: "function",
|
|
57
|
+
name,
|
|
58
|
+
args: []
|
|
59
|
+
}) as TemporalExpression<Runtime, Db, Name>
|
|
60
|
+
|
|
61
|
+
/** Postgres current instant. */
|
|
62
|
+
export const now = () =>
|
|
63
|
+
makeTemporal(
|
|
64
|
+
"now",
|
|
65
|
+
{ dialect: "postgres", kind: "timestamptz" } as Expression.DbType.PgTimestamptz,
|
|
66
|
+
InstantStringSchema
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
/** Postgres current date. */
|
|
70
|
+
export const currentDate = () =>
|
|
71
|
+
makeTemporal(
|
|
72
|
+
"current_date",
|
|
73
|
+
{ dialect: "postgres", kind: "date" } as Expression.DbType.PgDate,
|
|
74
|
+
LocalDateStringSchema
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
/** Postgres current time with time zone. */
|
|
78
|
+
export const currentTime = () =>
|
|
79
|
+
makeTemporal(
|
|
80
|
+
"current_time",
|
|
81
|
+
{ dialect: "postgres", kind: "timetz" } as Expression.DbType.PgTimetz,
|
|
82
|
+
OffsetTimeStringSchema
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
/** Postgres current timestamp with time zone. */
|
|
86
|
+
export const currentTimestamp = () =>
|
|
87
|
+
makeTemporal(
|
|
88
|
+
"current_timestamp",
|
|
89
|
+
{ dialect: "postgres", kind: "timestamptz" } as Expression.DbType.PgTimestamptz,
|
|
90
|
+
InstantStringSchema
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
/** Postgres local time without time zone. */
|
|
94
|
+
export const localTime = () =>
|
|
95
|
+
makeTemporal(
|
|
96
|
+
"localtime",
|
|
97
|
+
{ dialect: "postgres", kind: "time" } as Expression.DbType.PgTime,
|
|
98
|
+
LocalTimeStringSchema
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
/** Postgres local timestamp without time zone. */
|
|
102
|
+
export const localTimestamp = () =>
|
|
103
|
+
makeTemporal(
|
|
104
|
+
"localtimestamp",
|
|
105
|
+
{ dialect: "postgres", kind: "timestamp" } as Expression.DbType.PgTimestamp,
|
|
106
|
+
LocalDateTimeStringSchema
|
|
107
|
+
)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { postgresQuery } from "../private/query.js"
|
|
2
|
+
|
|
3
|
+
/** Postgres window functions. */
|
|
4
|
+
export const over = postgresQuery.over
|
|
5
|
+
export const rowNumber = postgresQuery.rowNumber
|
|
6
|
+
export const rank = postgresQuery.rank
|
|
7
|
+
export const denseRank = postgresQuery.denseRank
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export {
|
|
2
|
+
fromDiscoveredValues,
|
|
3
|
+
isEnumDefinition,
|
|
4
|
+
isTableDefinition,
|
|
5
|
+
tableKey,
|
|
6
|
+
enumKey,
|
|
7
|
+
toEnumModel,
|
|
8
|
+
toTableModel,
|
|
9
|
+
type ColumnModel,
|
|
10
|
+
type EnumModel,
|
|
11
|
+
type SchemaModel,
|
|
12
|
+
type TableModel
|
|
13
|
+
} from "../internal/postgres-schema-model.js"
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
EnumTypeId,
|
|
17
|
+
type AnyDefinition,
|
|
18
|
+
type EnumDefinition
|
|
19
|
+
} from "../postgres/schema-management.js"
|
|
20
|
+
|
|
21
|
+
export type {
|
|
22
|
+
DdlExpressionLike,
|
|
23
|
+
IndexKeySpec,
|
|
24
|
+
ReferentialAction,
|
|
25
|
+
TableOptionSpec
|
|
26
|
+
} from "../internal/table-options.js"
|
|
27
|
+
|
|
28
|
+
export {
|
|
29
|
+
normalizeDdlExpressionSql,
|
|
30
|
+
renderDdlExpressionSql
|
|
31
|
+
} from "../internal/schema-ddl.js"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { postgresQuery } from "../../internal/postgres-query.js"
|