effect-qb 0.13.0 → 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 -1431
- package/dist/mysql.js +1678 -355
- package/dist/postgres/metadata.js +2724 -0
- package/dist/postgres.js +7197 -5433
- package/package.json +8 -10
- package/src/internal/column-state.ts +84 -10
- package/src/internal/column.ts +556 -34
- package/src/internal/datatypes/define.ts +0 -30
- package/src/internal/executor.ts +45 -11
- package/src/internal/expression-ast.ts +4 -0
- package/src/internal/expression.ts +1 -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} +619 -167
- 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 +455 -39
- 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 +95 -31
- package/src/internal/table-options.ts +87 -7
- package/src/internal/table.ts +104 -41
- package/src/mysql/column.ts +1 -0
- package/src/mysql/datatypes/index.ts +17 -2
- package/src/mysql/function/core.ts +1 -0
- package/src/mysql/function/index.ts +1 -0
- package/src/mysql/private/query.ts +1 -13
- package/src/mysql/query.ts +5 -0
- package/src/postgres/cast.ts +31 -0
- package/src/postgres/column.ts +26 -0
- package/src/postgres/datatypes/index.ts +40 -5
- package/src/postgres/function/core.ts +12 -0
- package/src/postgres/function/index.ts +2 -1
- package/src/postgres/function/json.ts +499 -2
- package/src/postgres/metadata.ts +31 -0
- package/src/postgres/private/query.ts +1 -13
- package/src/postgres/query.ts +5 -2
- 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 +14 -0
- package/CHANGELOG.md +0 -134
|
@@ -1,4 +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"
|
|
1
10
|
import { postgresQuery } from "../private/query.js"
|
|
2
11
|
|
|
3
|
-
|
|
4
|
-
|
|
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,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"
|
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { makeDialectQuery } from "../../internal/query-factory.js"
|
|
3
|
-
import { postgresDatatypes } from "../datatypes/index.js"
|
|
4
|
-
|
|
5
|
-
export const postgresQuery = makeDialectQuery({
|
|
6
|
-
dialect: "postgres",
|
|
7
|
-
textDb: { dialect: "postgres", kind: "text" } as Expression.DbType.PgText,
|
|
8
|
-
numericDb: { dialect: "postgres", kind: "float8" } as Expression.DbType.PgFloat8,
|
|
9
|
-
boolDb: { dialect: "postgres", kind: "bool" } as Expression.DbType.PgBool,
|
|
10
|
-
timestampDb: { dialect: "postgres", kind: "timestamp" } as Expression.DbType.PgTimestamp,
|
|
11
|
-
nullDb: { dialect: "postgres", kind: "null" } as Expression.DbType.Base<"postgres", "null">,
|
|
12
|
-
type: postgresDatatypes
|
|
13
|
-
})
|
|
1
|
+
export { postgresQuery } from "../../internal/postgres-query.js"
|
package/src/postgres/query.ts
CHANGED
|
@@ -38,8 +38,7 @@ import {
|
|
|
38
38
|
} from "../internal/query.js"
|
|
39
39
|
|
|
40
40
|
export const literal = postgresQuery.literal
|
|
41
|
-
export const
|
|
42
|
-
export const type = postgresQuery.type
|
|
41
|
+
export const column = postgresQuery.column
|
|
43
42
|
export const eq = postgresQuery.eq
|
|
44
43
|
export const neq = postgresQuery.neq
|
|
45
44
|
export const lt = postgresQuery.lt
|
|
@@ -50,6 +49,10 @@ export const isNull = postgresQuery.isNull
|
|
|
50
49
|
export const isNotNull = postgresQuery.isNotNull
|
|
51
50
|
export const like = postgresQuery.like
|
|
52
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
|
|
53
56
|
export const and = postgresQuery.and
|
|
54
57
|
export const or = postgresQuery.or
|
|
55
58
|
export const not = postgresQuery.not
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export {
|
|
2
|
+
TypeId,
|
|
3
|
+
fromAst,
|
|
4
|
+
isSchemaExpression,
|
|
5
|
+
normalize,
|
|
6
|
+
parseExpression,
|
|
7
|
+
render,
|
|
8
|
+
toAst,
|
|
9
|
+
type Any,
|
|
10
|
+
type SchemaExpression
|
|
11
|
+
} from "../internal/schema-expression.js"
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
normalizeDdlExpressionSql,
|
|
15
|
+
renderDdlExpressionSql
|
|
16
|
+
} from "../internal/schema-ddl.js"
|