kysely 0.26.0 → 0.26.2
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 -6
- package/dist/cjs/dialect/dialect-adapter-base.d.ts +3 -3
- package/dist/cjs/dialect/mysql/mysql-adapter.d.ts +3 -2
- package/dist/cjs/dialect/mysql/mysql-adapter.js +2 -2
- package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +3 -2
- package/dist/cjs/dialect/postgres/postgres-adapter.js +2 -2
- package/dist/cjs/dialect/postgres/postgres-dialect-config.d.ts +2 -2
- package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +4 -2
- package/dist/cjs/dialect/sqlite/sqlite-adapter.js +2 -2
- package/dist/cjs/driver/runtime-driver.js +17 -2
- package/dist/cjs/expression/expression-builder.d.ts +299 -28
- package/dist/cjs/expression/expression-builder.js +36 -26
- package/dist/cjs/expression/expression-wrapper.d.ts +177 -8
- package/dist/cjs/expression/expression-wrapper.js +4 -4
- package/dist/cjs/expression/expression.d.ts +64 -1
- package/dist/cjs/helpers/mysql.d.ts +11 -8
- package/dist/cjs/helpers/mysql.js +21 -32
- package/dist/cjs/helpers/postgres.d.ts +8 -5
- package/dist/cjs/helpers/postgres.js +8 -5
- package/dist/cjs/helpers/sqlite.d.ts +164 -0
- package/dist/cjs/helpers/sqlite.js +180 -0
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/kysely.d.ts +4 -3
- package/dist/cjs/kysely.js +1 -1
- package/dist/cjs/operation-node/common-table-expression-node.d.ts +4 -0
- package/dist/cjs/operation-node/common-table-expression-node.js +6 -0
- package/dist/cjs/operation-node/delete-query-node.d.ts +1 -1
- package/dist/cjs/operation-node/delete-query-node.js +3 -3
- package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-transformer.js +8 -0
- package/dist/cjs/operation-node/operation-node-visitor.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-visitor.js +1 -0
- package/dist/cjs/operation-node/operation-node.d.ts +1 -1
- package/dist/cjs/operation-node/operator-node.d.ts +3 -3
- package/dist/cjs/operation-node/operator-node.js +3 -0
- package/dist/cjs/operation-node/order-by-node.d.ts +2 -2
- package/dist/cjs/operation-node/order-by-node.js +4 -4
- package/dist/cjs/operation-node/over-node.d.ts +1 -1
- package/dist/cjs/operation-node/over-node.js +3 -3
- package/dist/cjs/operation-node/select-query-node.d.ts +5 -4
- package/dist/cjs/operation-node/select-query-node.js +13 -7
- package/dist/cjs/operation-node/tuple-node.d.ts +12 -0
- package/dist/cjs/operation-node/tuple-node.js +18 -0
- package/dist/cjs/parser/binary-operation-parser.d.ts +11 -7
- package/dist/cjs/parser/binary-operation-parser.js +35 -46
- package/dist/cjs/parser/expression-parser.d.ts +9 -4
- package/dist/cjs/parser/join-parser.d.ts +2 -2
- package/dist/cjs/parser/join-parser.js +2 -3
- package/dist/cjs/parser/order-by-parser.d.ts +6 -2
- package/dist/cjs/parser/order-by-parser.js +41 -7
- package/dist/cjs/parser/parse-utils.js +2 -2
- package/dist/cjs/parser/reference-parser.js +1 -1
- package/dist/cjs/parser/select-parser.d.ts +5 -5
- package/dist/cjs/parser/set-operation-parser.d.ts +3 -1
- package/dist/cjs/parser/set-operation-parser.js +13 -4
- package/dist/cjs/parser/tuple-parser.d.ts +47 -0
- package/dist/cjs/parser/tuple-parser.js +2 -0
- package/dist/cjs/parser/value-parser.d.ts +4 -2
- package/dist/cjs/parser/value-parser.js +12 -1
- package/dist/cjs/parser/with-parser.d.ts +3 -2
- package/dist/cjs/parser/with-parser.js +16 -4
- package/dist/cjs/plugin/camel-case/camel-case-plugin.d.ts +3 -3
- package/dist/cjs/plugin/camel-case/camel-case-plugin.js +4 -8
- package/dist/cjs/plugin/parse-json-results/parse-json-results-plugin.d.ts +13 -0
- package/dist/cjs/plugin/parse-json-results/parse-json-results-plugin.js +50 -14
- package/dist/cjs/query-builder/aggregate-function-builder.d.ts +5 -5
- package/dist/cjs/query-builder/aggregate-function-builder.js +2 -2
- package/dist/cjs/query-builder/case-builder.js +8 -4
- package/dist/cjs/query-builder/cte-builder.d.ts +20 -0
- package/dist/cjs/query-builder/cte-builder.js +39 -0
- package/dist/cjs/query-builder/delete-query-builder.d.ts +74 -24
- package/dist/cjs/query-builder/delete-query-builder.js +3 -3
- package/dist/cjs/query-builder/function-module.d.ts +41 -6
- package/dist/cjs/query-builder/function-module.js +3 -0
- package/dist/cjs/query-builder/having-interface.d.ts +2 -5
- package/dist/cjs/query-builder/insert-query-builder.d.ts +1 -1
- package/dist/cjs/query-builder/join-builder.d.ts +2 -6
- package/dist/cjs/query-builder/join-builder.js +2 -2
- package/dist/cjs/query-builder/json-path-builder.d.ts +60 -4
- package/dist/cjs/query-builder/on-conflict-builder.d.ts +143 -44
- package/dist/cjs/query-builder/on-conflict-builder.js +4 -4
- package/dist/cjs/query-builder/over-builder.js +1 -1
- package/dist/cjs/query-builder/select-query-builder.d.ts +245 -86
- package/dist/cjs/query-builder/select-query-builder.js +72 -924
- package/dist/cjs/query-builder/update-query-builder.d.ts +106 -25
- package/dist/cjs/query-builder/update-query-builder.js +2 -2
- package/dist/cjs/query-builder/where-interface.d.ts +71 -24
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +3 -0
- package/dist/cjs/query-compiler/default-query-compiler.js +39 -7
- package/dist/cjs/query-creator.d.ts +74 -2
- package/dist/cjs/query-creator.js +83 -6
- package/dist/cjs/raw-builder/raw-builder.d.ts +88 -49
- package/dist/cjs/raw-builder/raw-builder.js +18 -45
- package/dist/cjs/raw-builder/sql.js +8 -8
- package/dist/cjs/schema/alter-table-builder.d.ts +4 -0
- package/dist/cjs/schema/alter-table-builder.js +12 -0
- package/dist/cjs/schema/create-index-builder.d.ts +1 -1
- package/dist/cjs/schema/create-index-builder.js +1 -1
- package/dist/cjs/util/column-type.d.ts +7 -6
- package/dist/cjs/util/json-object-args.d.ts +3 -0
- package/dist/cjs/util/json-object-args.js +35 -0
- package/dist/cjs/util/object-utils.d.ts +1 -0
- package/dist/cjs/util/object-utils.js +9 -1
- package/dist/cjs/util/type-utils.d.ts +10 -10
- package/dist/esm/dialect/dialect-adapter-base.d.ts +3 -3
- package/dist/esm/dialect/mysql/mysql-adapter.d.ts +3 -2
- package/dist/esm/dialect/mysql/mysql-adapter.js +2 -2
- package/dist/esm/dialect/postgres/postgres-adapter.d.ts +3 -2
- package/dist/esm/dialect/postgres/postgres-adapter.js +2 -2
- package/dist/esm/dialect/postgres/postgres-dialect-config.d.ts +2 -2
- package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +4 -2
- package/dist/esm/dialect/sqlite/sqlite-adapter.js +2 -2
- package/dist/esm/driver/runtime-driver.js +17 -2
- package/dist/esm/expression/expression-builder.d.ts +299 -28
- package/dist/esm/expression/expression-builder.js +40 -30
- package/dist/esm/expression/expression-wrapper.d.ts +177 -8
- package/dist/esm/expression/expression-wrapper.js +5 -5
- package/dist/esm/expression/expression.d.ts +64 -1
- package/dist/esm/helpers/mysql.d.ts +11 -8
- package/dist/esm/helpers/mysql.js +21 -32
- package/dist/esm/helpers/postgres.d.ts +8 -5
- package/dist/esm/helpers/postgres.js +8 -5
- package/dist/esm/helpers/sqlite.d.ts +164 -0
- package/dist/esm/helpers/sqlite.js +175 -0
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/kysely.d.ts +4 -3
- package/dist/esm/kysely.js +1 -1
- package/dist/esm/operation-node/common-table-expression-node.d.ts +4 -0
- package/dist/esm/operation-node/common-table-expression-node.js +6 -0
- package/dist/esm/operation-node/delete-query-node.d.ts +1 -1
- package/dist/esm/operation-node/delete-query-node.js +3 -3
- package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-transformer.js +8 -0
- package/dist/esm/operation-node/operation-node-visitor.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-visitor.js +1 -0
- package/dist/esm/operation-node/operation-node.d.ts +1 -1
- package/dist/esm/operation-node/operator-node.d.ts +3 -3
- package/dist/esm/operation-node/operator-node.js +3 -0
- package/dist/esm/operation-node/order-by-node.d.ts +2 -2
- package/dist/esm/operation-node/order-by-node.js +4 -4
- package/dist/esm/operation-node/over-node.d.ts +1 -1
- package/dist/esm/operation-node/over-node.js +3 -3
- package/dist/esm/operation-node/select-query-node.d.ts +5 -4
- package/dist/esm/operation-node/select-query-node.js +13 -7
- package/dist/esm/operation-node/tuple-node.d.ts +12 -0
- package/dist/esm/operation-node/tuple-node.js +16 -0
- package/dist/esm/parser/binary-operation-parser.d.ts +11 -7
- package/dist/esm/parser/binary-operation-parser.js +36 -47
- package/dist/esm/parser/expression-parser.d.ts +9 -4
- package/dist/esm/parser/join-parser.d.ts +2 -2
- package/dist/esm/parser/join-parser.js +3 -4
- package/dist/esm/parser/order-by-parser.d.ts +6 -2
- package/dist/esm/parser/order-by-parser.js +40 -7
- package/dist/esm/parser/parse-utils.js +3 -3
- package/dist/esm/parser/reference-parser.js +1 -1
- package/dist/esm/parser/select-parser.d.ts +5 -5
- package/dist/esm/parser/set-operation-parser.d.ts +3 -1
- package/dist/esm/parser/set-operation-parser.js +11 -2
- package/dist/esm/parser/tuple-parser.d.ts +47 -0
- package/dist/esm/parser/tuple-parser.js +2 -0
- package/dist/esm/parser/value-parser.d.ts +4 -2
- package/dist/esm/parser/value-parser.js +10 -1
- package/dist/esm/parser/with-parser.d.ts +3 -2
- package/dist/esm/parser/with-parser.js +16 -4
- package/dist/esm/plugin/camel-case/camel-case-plugin.d.ts +3 -3
- package/dist/esm/plugin/camel-case/camel-case-plugin.js +5 -9
- package/dist/esm/plugin/parse-json-results/parse-json-results-plugin.d.ts +13 -0
- package/dist/esm/plugin/parse-json-results/parse-json-results-plugin.js +51 -15
- package/dist/esm/query-builder/aggregate-function-builder.d.ts +5 -5
- package/dist/esm/query-builder/aggregate-function-builder.js +3 -3
- package/dist/esm/query-builder/case-builder.js +10 -6
- package/dist/esm/query-builder/cte-builder.d.ts +20 -0
- package/dist/esm/query-builder/cte-builder.js +36 -0
- package/dist/esm/query-builder/delete-query-builder.d.ts +74 -24
- package/dist/esm/query-builder/delete-query-builder.js +4 -4
- package/dist/esm/query-builder/function-module.d.ts +41 -6
- package/dist/esm/query-builder/function-module.js +3 -0
- package/dist/esm/query-builder/having-interface.d.ts +2 -5
- package/dist/esm/query-builder/insert-query-builder.d.ts +1 -1
- package/dist/esm/query-builder/join-builder.d.ts +2 -6
- package/dist/esm/query-builder/join-builder.js +3 -3
- package/dist/esm/query-builder/json-path-builder.d.ts +60 -4
- package/dist/esm/query-builder/on-conflict-builder.d.ts +143 -44
- package/dist/esm/query-builder/on-conflict-builder.js +5 -5
- package/dist/esm/query-builder/over-builder.js +1 -1
- package/dist/esm/query-builder/select-query-builder.d.ts +245 -86
- package/dist/esm/query-builder/select-query-builder.js +72 -923
- package/dist/esm/query-builder/update-query-builder.d.ts +106 -25
- package/dist/esm/query-builder/update-query-builder.js +3 -3
- package/dist/esm/query-builder/where-interface.d.ts +71 -24
- package/dist/esm/query-compiler/default-query-compiler.d.ts +3 -0
- package/dist/esm/query-compiler/default-query-compiler.js +39 -7
- package/dist/esm/query-creator.d.ts +74 -2
- package/dist/esm/query-creator.js +84 -7
- package/dist/esm/raw-builder/raw-builder.d.ts +88 -49
- package/dist/esm/raw-builder/raw-builder.js +17 -42
- package/dist/esm/raw-builder/sql.js +9 -9
- package/dist/esm/schema/alter-table-builder.d.ts +4 -0
- package/dist/esm/schema/alter-table-builder.js +12 -0
- package/dist/esm/schema/create-index-builder.d.ts +1 -1
- package/dist/esm/schema/create-index-builder.js +2 -2
- package/dist/esm/util/column-type.d.ts +7 -6
- package/dist/esm/util/json-object-args.d.ts +3 -0
- package/dist/esm/util/json-object-args.js +32 -0
- package/dist/esm/util/object-utils.d.ts +1 -0
- package/dist/esm/util/object-utils.js +7 -0
- package/dist/esm/util/type-utils.d.ts +10 -10
- package/helpers/sqlite.d.ts +1 -0
- package/helpers/sqlite.js +1 -0
- package/package.json +7 -4
|
@@ -4,11 +4,12 @@ import { OperationNode } from '../operation-node/operation-node.js';
|
|
|
4
4
|
import { OrNode } from '../operation-node/or-node.js';
|
|
5
5
|
import { ParensNode } from '../operation-node/parens-node.js';
|
|
6
6
|
import { ComparisonOperatorExpression, OperandValueExpressionOrList } from '../parser/binary-operation-parser.js';
|
|
7
|
+
import { OperandExpression } from '../parser/expression-parser.js';
|
|
7
8
|
import { ReferenceExpression } from '../parser/reference-parser.js';
|
|
8
9
|
import { KyselyTypeError } from '../util/type-error.js';
|
|
9
10
|
import { SqlBool } from '../util/type-utils.js';
|
|
10
|
-
import { AliasedExpression, Expression } from './expression.js';
|
|
11
|
-
export declare class ExpressionWrapper<DB, TB extends keyof DB, T> implements
|
|
11
|
+
import { AliasableExpression, AliasedExpression, Expression } from './expression.js';
|
|
12
|
+
export declare class ExpressionWrapper<DB, TB extends keyof DB, T> implements AliasableExpression<T> {
|
|
12
13
|
#private;
|
|
13
14
|
constructor(node: OperationNode);
|
|
14
15
|
/** @private */
|
|
@@ -55,6 +56,62 @@ export declare class ExpressionWrapper<DB, TB extends keyof DB, T> implements Ex
|
|
|
55
56
|
* ```
|
|
56
57
|
*/
|
|
57
58
|
as<A extends string>(alias: A): AliasedExpression<T, A>;
|
|
59
|
+
/**
|
|
60
|
+
* Returns an aliased version of the expression.
|
|
61
|
+
*
|
|
62
|
+
* In addition to slapping `as "the_alias"` at the end of the expression,
|
|
63
|
+
* this method also provides strict typing:
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* const result = await db
|
|
67
|
+
* .selectFrom('person')
|
|
68
|
+
* .select((eb) =>
|
|
69
|
+
* // `eb.fn<string>` returns an AliasableExpression<string>
|
|
70
|
+
* eb.fn<string>('concat', ['first_name' eb.val(' '), 'last_name']).as('full_name')
|
|
71
|
+
* )
|
|
72
|
+
* .executeTakeFirstOrThrow()
|
|
73
|
+
*
|
|
74
|
+
* // `full_name: string` field exists in the result type.
|
|
75
|
+
* console.log(result.full_name)
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* The generated SQL (PostgreSQL):
|
|
79
|
+
*
|
|
80
|
+
* ```ts
|
|
81
|
+
* select
|
|
82
|
+
* concat("first_name", $1, "last_name") as "full_name"
|
|
83
|
+
* from
|
|
84
|
+
* "person"
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* You can also pass in a raw SQL snippet (or any expression) but in that case you must
|
|
88
|
+
* provide the alias as the only type argument:
|
|
89
|
+
*
|
|
90
|
+
* ```ts
|
|
91
|
+
* const values = sql<{ a: number, b: string }>`(values (1, 'foo'))`
|
|
92
|
+
*
|
|
93
|
+
* // The alias is `t(a, b)` which specifies the column names
|
|
94
|
+
* // in addition to the table name. We must tell kysely that
|
|
95
|
+
* // columns of the table can be referenced through `t`
|
|
96
|
+
* // by providing an explicit type argument.
|
|
97
|
+
* const aliasedValues = values.as<'t'>(sql`t(a, b)`)
|
|
98
|
+
*
|
|
99
|
+
* await db
|
|
100
|
+
* .insertInto('person')
|
|
101
|
+
* .columns(['first_name', 'last_name'])
|
|
102
|
+
* .expression(
|
|
103
|
+
* db.selectFrom(aliasedValues).select(['t.a', 't.b'])
|
|
104
|
+
* )
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* The generated SQL (PostgreSQL):
|
|
108
|
+
*
|
|
109
|
+
* ```ts
|
|
110
|
+
* insert into "person" ("first_name", "last_name")
|
|
111
|
+
* from (values (1, 'foo')) as t(a, b)
|
|
112
|
+
* select "t"."a", "t"."b"
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
58
115
|
as<A extends string>(alias: Expression<unknown>): AliasedExpression<T, A>;
|
|
59
116
|
/**
|
|
60
117
|
* Combines `this` and another expression using `OR`.
|
|
@@ -117,7 +174,7 @@ export declare class ExpressionWrapper<DB, TB extends keyof DB, T> implements Ex
|
|
|
117
174
|
* ```
|
|
118
175
|
*/
|
|
119
176
|
or<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: ComparisonOperatorExpression, rhs: OperandValueExpressionOrList<DB, TB, RE>): T extends SqlBool ? OrWrapper<DB, TB, SqlBool> : KyselyTypeError<'or() method can only be called on boolean expressions'>;
|
|
120
|
-
or(expression:
|
|
177
|
+
or(expression: OperandExpression<SqlBool>): T extends SqlBool ? OrWrapper<DB, TB, SqlBool> : KyselyTypeError<'or() method can only be called on boolean expressions'>;
|
|
121
178
|
/**
|
|
122
179
|
* Combines `this` and another expression using `AND`.
|
|
123
180
|
*
|
|
@@ -179,7 +236,7 @@ export declare class ExpressionWrapper<DB, TB extends keyof DB, T> implements Ex
|
|
|
179
236
|
* ```
|
|
180
237
|
*/
|
|
181
238
|
and<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: ComparisonOperatorExpression, rhs: OperandValueExpressionOrList<DB, TB, RE>): T extends SqlBool ? AndWrapper<DB, TB, SqlBool> : KyselyTypeError<'and() method can only be called on boolean expressions'>;
|
|
182
|
-
and(expression:
|
|
239
|
+
and(expression: OperandExpression<SqlBool>): T extends SqlBool ? AndWrapper<DB, TB, SqlBool> : KyselyTypeError<'and() method can only be called on boolean expressions'>;
|
|
183
240
|
/**
|
|
184
241
|
* Change the output type of the expression.
|
|
185
242
|
*
|
|
@@ -221,7 +278,7 @@ export declare class AliasedExpressionWrapper<T, A extends string> implements Al
|
|
|
221
278
|
*/
|
|
222
279
|
toOperationNode(): AliasNode;
|
|
223
280
|
}
|
|
224
|
-
export declare class OrWrapper<DB, TB extends keyof DB, T extends SqlBool> implements
|
|
281
|
+
export declare class OrWrapper<DB, TB extends keyof DB, T extends SqlBool> implements AliasableExpression<T> {
|
|
225
282
|
#private;
|
|
226
283
|
constructor(node: OrNode);
|
|
227
284
|
/** @private */
|
|
@@ -270,6 +327,62 @@ export declare class OrWrapper<DB, TB extends keyof DB, T extends SqlBool> imple
|
|
|
270
327
|
* ```
|
|
271
328
|
*/
|
|
272
329
|
as<A extends string>(alias: A): AliasedExpression<T, A>;
|
|
330
|
+
/**
|
|
331
|
+
* Returns an aliased version of the expression.
|
|
332
|
+
*
|
|
333
|
+
* In addition to slapping `as "the_alias"` at the end of the expression,
|
|
334
|
+
* this method also provides strict typing:
|
|
335
|
+
*
|
|
336
|
+
* ```ts
|
|
337
|
+
* const result = await db
|
|
338
|
+
* .selectFrom('person')
|
|
339
|
+
* .select((eb) =>
|
|
340
|
+
* // `eb.fn<string>` returns an AliasableExpression<string>
|
|
341
|
+
* eb.fn<string>('concat', ['first_name' eb.val(' '), 'last_name']).as('full_name')
|
|
342
|
+
* )
|
|
343
|
+
* .executeTakeFirstOrThrow()
|
|
344
|
+
*
|
|
345
|
+
* // `full_name: string` field exists in the result type.
|
|
346
|
+
* console.log(result.full_name)
|
|
347
|
+
* ```
|
|
348
|
+
*
|
|
349
|
+
* The generated SQL (PostgreSQL):
|
|
350
|
+
*
|
|
351
|
+
* ```ts
|
|
352
|
+
* select
|
|
353
|
+
* concat("first_name", $1, "last_name") as "full_name"
|
|
354
|
+
* from
|
|
355
|
+
* "person"
|
|
356
|
+
* ```
|
|
357
|
+
*
|
|
358
|
+
* You can also pass in a raw SQL snippet (or any expression) but in that case you must
|
|
359
|
+
* provide the alias as the only type argument:
|
|
360
|
+
*
|
|
361
|
+
* ```ts
|
|
362
|
+
* const values = sql<{ a: number, b: string }>`(values (1, 'foo'))`
|
|
363
|
+
*
|
|
364
|
+
* // The alias is `t(a, b)` which specifies the column names
|
|
365
|
+
* // in addition to the table name. We must tell kysely that
|
|
366
|
+
* // columns of the table can be referenced through `t`
|
|
367
|
+
* // by providing an explicit type argument.
|
|
368
|
+
* const aliasedValues = values.as<'t'>(sql`t(a, b)`)
|
|
369
|
+
*
|
|
370
|
+
* await db
|
|
371
|
+
* .insertInto('person')
|
|
372
|
+
* .columns(['first_name', 'last_name'])
|
|
373
|
+
* .expression(
|
|
374
|
+
* db.selectFrom(aliasedValues).select(['t.a', 't.b'])
|
|
375
|
+
* )
|
|
376
|
+
* ```
|
|
377
|
+
*
|
|
378
|
+
* The generated SQL (PostgreSQL):
|
|
379
|
+
*
|
|
380
|
+
* ```ts
|
|
381
|
+
* insert into "person" ("first_name", "last_name")
|
|
382
|
+
* from (values (1, 'foo')) as t(a, b)
|
|
383
|
+
* select "t"."a", "t"."b"
|
|
384
|
+
* ```
|
|
385
|
+
*/
|
|
273
386
|
as<A extends string>(alias: Expression<unknown>): AliasedExpression<T, A>;
|
|
274
387
|
/**
|
|
275
388
|
* Combines `this` and another expression using `OR`.
|
|
@@ -277,7 +390,7 @@ export declare class OrWrapper<DB, TB extends keyof DB, T extends SqlBool> imple
|
|
|
277
390
|
* See {@link ExpressionWrapper.or} for examples.
|
|
278
391
|
*/
|
|
279
392
|
or<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: ComparisonOperatorExpression, rhs: OperandValueExpressionOrList<DB, TB, RE>): OrWrapper<DB, TB, T>;
|
|
280
|
-
or(expression:
|
|
393
|
+
or(expression: OperandExpression<SqlBool>): OrWrapper<DB, TB, T>;
|
|
281
394
|
/**
|
|
282
395
|
* Change the output type of the expression.
|
|
283
396
|
*
|
|
@@ -301,7 +414,7 @@ export declare class OrWrapper<DB, TB extends keyof DB, T extends SqlBool> imple
|
|
|
301
414
|
*/
|
|
302
415
|
toOperationNode(): ParensNode;
|
|
303
416
|
}
|
|
304
|
-
export declare class AndWrapper<DB, TB extends keyof DB, T extends SqlBool> implements
|
|
417
|
+
export declare class AndWrapper<DB, TB extends keyof DB, T extends SqlBool> implements AliasableExpression<T> {
|
|
305
418
|
#private;
|
|
306
419
|
constructor(node: AndNode);
|
|
307
420
|
/** @private */
|
|
@@ -350,6 +463,62 @@ export declare class AndWrapper<DB, TB extends keyof DB, T extends SqlBool> impl
|
|
|
350
463
|
* ```
|
|
351
464
|
*/
|
|
352
465
|
as<A extends string>(alias: A): AliasedExpression<T, A>;
|
|
466
|
+
/**
|
|
467
|
+
* Returns an aliased version of the expression.
|
|
468
|
+
*
|
|
469
|
+
* In addition to slapping `as "the_alias"` at the end of the expression,
|
|
470
|
+
* this method also provides strict typing:
|
|
471
|
+
*
|
|
472
|
+
* ```ts
|
|
473
|
+
* const result = await db
|
|
474
|
+
* .selectFrom('person')
|
|
475
|
+
* .select((eb) =>
|
|
476
|
+
* // `eb.fn<string>` returns an AliasableExpression<string>
|
|
477
|
+
* eb.fn<string>('concat', ['first_name' eb.val(' '), 'last_name']).as('full_name')
|
|
478
|
+
* )
|
|
479
|
+
* .executeTakeFirstOrThrow()
|
|
480
|
+
*
|
|
481
|
+
* // `full_name: string` field exists in the result type.
|
|
482
|
+
* console.log(result.full_name)
|
|
483
|
+
* ```
|
|
484
|
+
*
|
|
485
|
+
* The generated SQL (PostgreSQL):
|
|
486
|
+
*
|
|
487
|
+
* ```ts
|
|
488
|
+
* select
|
|
489
|
+
* concat("first_name", $1, "last_name") as "full_name"
|
|
490
|
+
* from
|
|
491
|
+
* "person"
|
|
492
|
+
* ```
|
|
493
|
+
*
|
|
494
|
+
* You can also pass in a raw SQL snippet (or any expression) but in that case you must
|
|
495
|
+
* provide the alias as the only type argument:
|
|
496
|
+
*
|
|
497
|
+
* ```ts
|
|
498
|
+
* const values = sql<{ a: number, b: string }>`(values (1, 'foo'))`
|
|
499
|
+
*
|
|
500
|
+
* // The alias is `t(a, b)` which specifies the column names
|
|
501
|
+
* // in addition to the table name. We must tell kysely that
|
|
502
|
+
* // columns of the table can be referenced through `t`
|
|
503
|
+
* // by providing an explicit type argument.
|
|
504
|
+
* const aliasedValues = values.as<'t'>(sql`t(a, b)`)
|
|
505
|
+
*
|
|
506
|
+
* await db
|
|
507
|
+
* .insertInto('person')
|
|
508
|
+
* .columns(['first_name', 'last_name'])
|
|
509
|
+
* .expression(
|
|
510
|
+
* db.selectFrom(aliasedValues).select(['t.a', 't.b'])
|
|
511
|
+
* )
|
|
512
|
+
* ```
|
|
513
|
+
*
|
|
514
|
+
* The generated SQL (PostgreSQL):
|
|
515
|
+
*
|
|
516
|
+
* ```ts
|
|
517
|
+
* insert into "person" ("first_name", "last_name")
|
|
518
|
+
* from (values (1, 'foo')) as t(a, b)
|
|
519
|
+
* select "t"."a", "t"."b"
|
|
520
|
+
* ```
|
|
521
|
+
*/
|
|
353
522
|
as<A extends string>(alias: Expression<unknown>): AliasedExpression<T, A>;
|
|
354
523
|
/**
|
|
355
524
|
* Combines `this` and another expression using `AND`.
|
|
@@ -357,7 +526,7 @@ export declare class AndWrapper<DB, TB extends keyof DB, T extends SqlBool> impl
|
|
|
357
526
|
* See {@link ExpressionWrapper.and} for examples.
|
|
358
527
|
*/
|
|
359
528
|
and<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: ComparisonOperatorExpression, rhs: OperandValueExpressionOrList<DB, TB, RE>): AndWrapper<DB, TB, T>;
|
|
360
|
-
and(expression:
|
|
529
|
+
and(expression: OperandExpression<SqlBool>): AndWrapper<DB, TB, T>;
|
|
361
530
|
/**
|
|
362
531
|
* Change the output type of the expression.
|
|
363
532
|
*
|
|
@@ -21,10 +21,10 @@ class ExpressionWrapper {
|
|
|
21
21
|
return new AliasedExpressionWrapper(this, alias);
|
|
22
22
|
}
|
|
23
23
|
or(...args) {
|
|
24
|
-
return new OrWrapper(or_node_js_1.OrNode.create(this.#node, (0, binary_operation_parser_js_1.
|
|
24
|
+
return new OrWrapper(or_node_js_1.OrNode.create(this.#node, (0, binary_operation_parser_js_1.parseValueBinaryOperationOrExpression)(args)));
|
|
25
25
|
}
|
|
26
26
|
and(...args) {
|
|
27
|
-
return new AndWrapper(and_node_js_1.AndNode.create(this.#node, (0, binary_operation_parser_js_1.
|
|
27
|
+
return new AndWrapper(and_node_js_1.AndNode.create(this.#node, (0, binary_operation_parser_js_1.parseValueBinaryOperationOrExpression)(args)));
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Change the output type of the expression.
|
|
@@ -75,7 +75,7 @@ class OrWrapper {
|
|
|
75
75
|
return new AliasedExpressionWrapper(this, alias);
|
|
76
76
|
}
|
|
77
77
|
or(...args) {
|
|
78
|
-
return new OrWrapper(or_node_js_1.OrNode.create(this.#node, (0, binary_operation_parser_js_1.
|
|
78
|
+
return new OrWrapper(or_node_js_1.OrNode.create(this.#node, (0, binary_operation_parser_js_1.parseValueBinaryOperationOrExpression)(args)));
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* Change the output type of the expression.
|
|
@@ -104,7 +104,7 @@ class AndWrapper {
|
|
|
104
104
|
return new AliasedExpressionWrapper(this, alias);
|
|
105
105
|
}
|
|
106
106
|
and(...args) {
|
|
107
|
-
return new AndWrapper(and_node_js_1.AndNode.create(this.#node, (0, binary_operation_parser_js_1.
|
|
107
|
+
return new AndWrapper(and_node_js_1.AndNode.create(this.#node, (0, binary_operation_parser_js_1.parseValueBinaryOperationOrExpression)(args)));
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
110
110
|
* Change the output type of the expression.
|
|
@@ -49,7 +49,70 @@ export interface Expression<T> extends OperationNodeSource {
|
|
|
49
49
|
toOperationNode(): OperationNode;
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
52
|
+
* An expression with an `as` method.
|
|
53
|
+
*/
|
|
54
|
+
export interface AliasableExpression<T> extends Expression<T> {
|
|
55
|
+
/**
|
|
56
|
+
* Returns an aliased version of the expression.
|
|
57
|
+
*
|
|
58
|
+
* In addition to slapping `as "the_alias"` at the end of the expression,
|
|
59
|
+
* this method also provides strict typing:
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* const result = await db
|
|
63
|
+
* .selectFrom('person')
|
|
64
|
+
* .select((eb) =>
|
|
65
|
+
* // `eb.fn<string>` returns an AliasableExpression<string>
|
|
66
|
+
* eb.fn<string>('concat', ['first_name' eb.val(' '), 'last_name']).as('full_name')
|
|
67
|
+
* )
|
|
68
|
+
* .executeTakeFirstOrThrow()
|
|
69
|
+
*
|
|
70
|
+
* // `full_name: string` field exists in the result type.
|
|
71
|
+
* console.log(result.full_name)
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* The generated SQL (PostgreSQL):
|
|
75
|
+
*
|
|
76
|
+
* ```ts
|
|
77
|
+
* select
|
|
78
|
+
* concat("first_name", $1, "last_name") as "full_name"
|
|
79
|
+
* from
|
|
80
|
+
* "person"
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* You can also pass in a raw SQL snippet (or any expression) but in that case you must
|
|
84
|
+
* provide the alias as the only type argument:
|
|
85
|
+
*
|
|
86
|
+
* ```ts
|
|
87
|
+
* const values = sql<{ a: number, b: string }>`(values (1, 'foo'))`
|
|
88
|
+
*
|
|
89
|
+
* // The alias is `t(a, b)` which specifies the column names
|
|
90
|
+
* // in addition to the table name. We must tell kysely that
|
|
91
|
+
* // columns of the table can be referenced through `t`
|
|
92
|
+
* // by providing an explicit type argument.
|
|
93
|
+
* const aliasedValues = values.as<'t'>(sql`t(a, b)`)
|
|
94
|
+
*
|
|
95
|
+
* await db
|
|
96
|
+
* .insertInto('person')
|
|
97
|
+
* .columns(['first_name', 'last_name'])
|
|
98
|
+
* .expression(
|
|
99
|
+
* db.selectFrom(aliasedValues).select(['t.a', 't.b'])
|
|
100
|
+
* )
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* The generated SQL (PostgreSQL):
|
|
104
|
+
*
|
|
105
|
+
* ```ts
|
|
106
|
+
* insert into "person" ("first_name", "last_name")
|
|
107
|
+
* from (values (1, 'foo')) as t(a, b)
|
|
108
|
+
* select "t"."a", "t"."b"
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
as<A extends string>(alias: A): AliasedExpression<T, A>;
|
|
112
|
+
as<A extends string>(alias: Expression<any>): AliasedExpression<T, A>;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* A type that holds an expression and an alias for it.
|
|
53
116
|
*
|
|
54
117
|
* `AliasedExpression<T, A>` can be used in places where, in addition to the value type `T`, you
|
|
55
118
|
* also need a name `A` for that value. For example anything you can pass into the `select` method
|
|
@@ -6,8 +6,9 @@ import { Simplify } from '../util/type-utils.js';
|
|
|
6
6
|
* A MySQL helper for aggregating a subquery into a JSON array.
|
|
7
7
|
*
|
|
8
8
|
* NOTE: This helper is only guaranteed to fully work with the built-in `MysqlDialect`.
|
|
9
|
-
* While the produced SQL is
|
|
10
|
-
* may not parse the nested
|
|
9
|
+
* While the produced SQL is compatible with all MySQL databases, some 3rd party dialects
|
|
10
|
+
* may not parse the nested JSON into arrays. In these cases you can use the built in
|
|
11
|
+
* `ParseJSONResultsPlugin` to parse the results.
|
|
11
12
|
*
|
|
12
13
|
* ### Examples
|
|
13
14
|
*
|
|
@@ -19,7 +20,7 @@ import { Simplify } from '../util/type-utils.js';
|
|
|
19
20
|
* jsonArrayFrom(
|
|
20
21
|
* eb.selectFrom('pet')
|
|
21
22
|
* .select(['pet.id as pet_id', 'pet.name'])
|
|
22
|
-
* .
|
|
23
|
+
* .whereRef('pet.owner_id', '=', 'person.id')
|
|
23
24
|
* .orderBy('pet.name')
|
|
24
25
|
* ).as('pets')
|
|
25
26
|
* ])
|
|
@@ -54,8 +55,9 @@ export declare function jsonArrayFrom<O>(expr: SelectQueryBuilder<any, any, O>):
|
|
|
54
55
|
* The subquery must only return one row.
|
|
55
56
|
*
|
|
56
57
|
* NOTE: This helper is only guaranteed to fully work with the built-in `MysqlDialect`.
|
|
57
|
-
* While the produced SQL is
|
|
58
|
-
* may not parse the nested
|
|
58
|
+
* While the produced SQL is compatible with all MySQL databases, some 3rd party dialects
|
|
59
|
+
* may not parse the nested JSON into objects. In these cases you can use the built in
|
|
60
|
+
* `ParseJSONResultsPlugin` to parse the results.
|
|
59
61
|
*
|
|
60
62
|
* ### Examples
|
|
61
63
|
*
|
|
@@ -67,7 +69,7 @@ export declare function jsonArrayFrom<O>(expr: SelectQueryBuilder<any, any, O>):
|
|
|
67
69
|
* jsonObjectFrom(
|
|
68
70
|
* eb.selectFrom('pet')
|
|
69
71
|
* .select(['pet.id as pet_id', 'pet.name'])
|
|
70
|
-
* .
|
|
72
|
+
* .whereRef('pet.owner_id', '=', 'person.id')
|
|
71
73
|
* .where('pet.is_favorite', '=', true)
|
|
72
74
|
* ).as('favorite_pet')
|
|
73
75
|
* ])
|
|
@@ -100,8 +102,9 @@ export declare function jsonObjectFrom<O>(expr: SelectQueryBuilder<any, any, O>)
|
|
|
100
102
|
* The MySQL `json_object` function.
|
|
101
103
|
*
|
|
102
104
|
* NOTE: This helper is only guaranteed to fully work with the built-in `MysqlDialect`.
|
|
103
|
-
* While the produced SQL is
|
|
104
|
-
* may not parse the nested
|
|
105
|
+
* While the produced SQL is compatible with all MySQL databases, some 3rd party dialects
|
|
106
|
+
* may not parse the nested JSON into objects. In these cases you can use the built in
|
|
107
|
+
* `ParseJSONResultsPlugin` to parse the results.
|
|
105
108
|
*
|
|
106
109
|
* ### Examples
|
|
107
110
|
*
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.jsonBuildObject = exports.jsonObjectFrom = exports.jsonArrayFrom = void 0;
|
|
4
|
-
const alias_node_js_1 = require("../operation-node/alias-node.js");
|
|
5
|
-
const column_node_js_1 = require("../operation-node/column-node.js");
|
|
6
|
-
const identifier_node_js_1 = require("../operation-node/identifier-node.js");
|
|
7
|
-
const reference_node_js_1 = require("../operation-node/reference-node.js");
|
|
8
4
|
const sql_js_1 = require("../raw-builder/sql.js");
|
|
5
|
+
const json_object_args_js_1 = require("../util/json-object-args.js");
|
|
9
6
|
/**
|
|
10
7
|
* A MySQL helper for aggregating a subquery into a JSON array.
|
|
11
8
|
*
|
|
12
9
|
* NOTE: This helper is only guaranteed to fully work with the built-in `MysqlDialect`.
|
|
13
|
-
* While the produced SQL is
|
|
14
|
-
* may not parse the nested
|
|
10
|
+
* While the produced SQL is compatible with all MySQL databases, some 3rd party dialects
|
|
11
|
+
* may not parse the nested JSON into arrays. In these cases you can use the built in
|
|
12
|
+
* `ParseJSONResultsPlugin` to parse the results.
|
|
15
13
|
*
|
|
16
14
|
* ### Examples
|
|
17
15
|
*
|
|
@@ -23,7 +21,7 @@ const sql_js_1 = require("../raw-builder/sql.js");
|
|
|
23
21
|
* jsonArrayFrom(
|
|
24
22
|
* eb.selectFrom('pet')
|
|
25
23
|
* .select(['pet.id as pet_id', 'pet.name'])
|
|
26
|
-
* .
|
|
24
|
+
* .whereRef('pet.owner_id', '=', 'person.id')
|
|
27
25
|
* .orderBy('pet.name')
|
|
28
26
|
* ).as('pets')
|
|
29
27
|
* ])
|
|
@@ -52,7 +50,7 @@ const sql_js_1 = require("../raw-builder/sql.js");
|
|
|
52
50
|
* ```
|
|
53
51
|
*/
|
|
54
52
|
function jsonArrayFrom(expr) {
|
|
55
|
-
return (0, sql_js_1.sql) `(select cast(coalesce(json_arrayagg(json_object(${sql_js_1.sql.join(
|
|
53
|
+
return (0, sql_js_1.sql) `(select cast(coalesce(json_arrayagg(json_object(${sql_js_1.sql.join(getMysqlJsonObjectArgs(expr.toOperationNode(), 'agg'))})), '[]') as json) from ${expr} as agg)`;
|
|
56
54
|
}
|
|
57
55
|
exports.jsonArrayFrom = jsonArrayFrom;
|
|
58
56
|
/**
|
|
@@ -61,8 +59,9 @@ exports.jsonArrayFrom = jsonArrayFrom;
|
|
|
61
59
|
* The subquery must only return one row.
|
|
62
60
|
*
|
|
63
61
|
* NOTE: This helper is only guaranteed to fully work with the built-in `MysqlDialect`.
|
|
64
|
-
* While the produced SQL is
|
|
65
|
-
* may not parse the nested
|
|
62
|
+
* While the produced SQL is compatible with all MySQL databases, some 3rd party dialects
|
|
63
|
+
* may not parse the nested JSON into objects. In these cases you can use the built in
|
|
64
|
+
* `ParseJSONResultsPlugin` to parse the results.
|
|
66
65
|
*
|
|
67
66
|
* ### Examples
|
|
68
67
|
*
|
|
@@ -74,7 +73,7 @@ exports.jsonArrayFrom = jsonArrayFrom;
|
|
|
74
73
|
* jsonObjectFrom(
|
|
75
74
|
* eb.selectFrom('pet')
|
|
76
75
|
* .select(['pet.id as pet_id', 'pet.name'])
|
|
77
|
-
* .
|
|
76
|
+
* .whereRef('pet.owner_id', '=', 'person.id')
|
|
78
77
|
* .where('pet.is_favorite', '=', true)
|
|
79
78
|
* ).as('favorite_pet')
|
|
80
79
|
* ])
|
|
@@ -103,15 +102,16 @@ exports.jsonArrayFrom = jsonArrayFrom;
|
|
|
103
102
|
* ```
|
|
104
103
|
*/
|
|
105
104
|
function jsonObjectFrom(expr) {
|
|
106
|
-
return (0, sql_js_1.sql) `(select json_object(${sql_js_1.sql.join(
|
|
105
|
+
return (0, sql_js_1.sql) `(select json_object(${sql_js_1.sql.join(getMysqlJsonObjectArgs(expr.toOperationNode(), 'obj'))}) from ${expr} as obj)`;
|
|
107
106
|
}
|
|
108
107
|
exports.jsonObjectFrom = jsonObjectFrom;
|
|
109
108
|
/**
|
|
110
109
|
* The MySQL `json_object` function.
|
|
111
110
|
*
|
|
112
111
|
* NOTE: This helper is only guaranteed to fully work with the built-in `MysqlDialect`.
|
|
113
|
-
* While the produced SQL is
|
|
114
|
-
* may not parse the nested
|
|
112
|
+
* While the produced SQL is compatible with all MySQL databases, some 3rd party dialects
|
|
113
|
+
* may not parse the nested JSON into objects. In these cases you can use the built in
|
|
114
|
+
* `ParseJSONResultsPlugin` to parse the results.
|
|
115
115
|
*
|
|
116
116
|
* ### Examples
|
|
117
117
|
*
|
|
@@ -149,22 +149,11 @@ function jsonBuildObject(obj) {
|
|
|
149
149
|
return (0, sql_js_1.sql) `json_object(${sql_js_1.sql.join(Object.keys(obj).flatMap((k) => [sql_js_1.sql.lit(k), obj[k]]))})`;
|
|
150
150
|
}
|
|
151
151
|
exports.jsonBuildObject = jsonBuildObject;
|
|
152
|
-
function
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
else if (column_node_js_1.ColumnNode.is(s)) {
|
|
161
|
-
return [sql_js_1.sql.lit(s.column.name), sql_js_1.sql.id(table, s.column.name)];
|
|
162
|
-
}
|
|
163
|
-
else if (alias_node_js_1.AliasNode.is(s) && identifier_node_js_1.IdentifierNode.is(s.alias)) {
|
|
164
|
-
return [sql_js_1.sql.lit(s.alias.name), sql_js_1.sql.id(table, s.alias.name)];
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
throw new Error('MySQL jsonArrayFrom and jsonObjectFrom functions can only handle explicit selections due to limitations of the json_object function. selectAll() is not allowed in the subquery.');
|
|
168
|
-
}
|
|
169
|
-
});
|
|
152
|
+
function getMysqlJsonObjectArgs(node, table) {
|
|
153
|
+
try {
|
|
154
|
+
return (0, json_object_args_js_1.getJsonObjectArgs)(node, table);
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
throw new Error('MySQL jsonArrayFrom and jsonObjectFrom functions can only handle explicit selections due to limitations of the json_object function. selectAll() is not allowed in the subquery.');
|
|
158
|
+
}
|
|
170
159
|
}
|
|
@@ -16,7 +16,8 @@ import { Simplify } from '../util/type-utils.js';
|
|
|
16
16
|
* `jsonArrayFrom`, are not guaranteed to work with third party dialects. In order for
|
|
17
17
|
* them to work, the dialect must automatically parse the `json` data type into
|
|
18
18
|
* javascript JSON values like objects and arrays. Some dialects might simply return
|
|
19
|
-
* the data as a JSON string.
|
|
19
|
+
* the data as a JSON string. In these cases you can use the built in `ParseJSONResultsPlugin`
|
|
20
|
+
* to parse the results.
|
|
20
21
|
*
|
|
21
22
|
* ```ts
|
|
22
23
|
* import { jsonArrayFrom } from 'kysely/helpers/postgres'
|
|
@@ -64,10 +65,11 @@ export declare function jsonArrayFrom<O>(expr: Expression<O>): RawBuilder<Simpli
|
|
|
64
65
|
* use the `jsonObjectFrom` helper to fetch person's favorite pet along with the person's id.
|
|
65
66
|
*
|
|
66
67
|
* Please keep in mind that the helpers under the `kysely/helpers` folder, including
|
|
67
|
-
* `jsonObjectFrom`, are not guaranteed to work with
|
|
68
|
+
* `jsonObjectFrom`, are not guaranteed to work with 3rd party dialects. In order for
|
|
68
69
|
* them to work, the dialect must automatically parse the `json` data type into
|
|
69
70
|
* javascript JSON values like objects and arrays. Some dialects might simply return
|
|
70
|
-
* the data as a JSON string.
|
|
71
|
+
* the data as a JSON string. In these cases you can use the built in `ParseJSONResultsPlugin`
|
|
72
|
+
* to parse the results.
|
|
71
73
|
*
|
|
72
74
|
* ```ts
|
|
73
75
|
* import { jsonObjectFrom } from 'kysely/helpers/postgres'
|
|
@@ -105,8 +107,9 @@ export declare function jsonObjectFrom<O>(expr: Expression<O>): RawBuilder<Simpl
|
|
|
105
107
|
* The PostgreSQL `json_build_object` function.
|
|
106
108
|
*
|
|
107
109
|
* NOTE: This helper is only guaranteed to fully work with the built-in `PostgresDialect`.
|
|
108
|
-
* While the produced SQL is
|
|
109
|
-
* may not parse the nested
|
|
110
|
+
* While the produced SQL is compatible with all PostgreSQL databases, some 3rd party dialects
|
|
111
|
+
* may not parse the nested JSON into objects. In these cases you can use the built in
|
|
112
|
+
* `ParseJSONResultsPlugin` to parse the results.
|
|
110
113
|
*
|
|
111
114
|
* ### Examples
|
|
112
115
|
*
|
|
@@ -17,7 +17,8 @@ const sql_js_1 = require("../raw-builder/sql.js");
|
|
|
17
17
|
* `jsonArrayFrom`, are not guaranteed to work with third party dialects. In order for
|
|
18
18
|
* them to work, the dialect must automatically parse the `json` data type into
|
|
19
19
|
* javascript JSON values like objects and arrays. Some dialects might simply return
|
|
20
|
-
* the data as a JSON string.
|
|
20
|
+
* the data as a JSON string. In these cases you can use the built in `ParseJSONResultsPlugin`
|
|
21
|
+
* to parse the results.
|
|
21
22
|
*
|
|
22
23
|
* ```ts
|
|
23
24
|
* import { jsonArrayFrom } from 'kysely/helpers/postgres'
|
|
@@ -68,10 +69,11 @@ exports.jsonArrayFrom = jsonArrayFrom;
|
|
|
68
69
|
* use the `jsonObjectFrom` helper to fetch person's favorite pet along with the person's id.
|
|
69
70
|
*
|
|
70
71
|
* Please keep in mind that the helpers under the `kysely/helpers` folder, including
|
|
71
|
-
* `jsonObjectFrom`, are not guaranteed to work with
|
|
72
|
+
* `jsonObjectFrom`, are not guaranteed to work with 3rd party dialects. In order for
|
|
72
73
|
* them to work, the dialect must automatically parse the `json` data type into
|
|
73
74
|
* javascript JSON values like objects and arrays. Some dialects might simply return
|
|
74
|
-
* the data as a JSON string.
|
|
75
|
+
* the data as a JSON string. In these cases you can use the built in `ParseJSONResultsPlugin`
|
|
76
|
+
* to parse the results.
|
|
75
77
|
*
|
|
76
78
|
* ```ts
|
|
77
79
|
* import { jsonObjectFrom } from 'kysely/helpers/postgres'
|
|
@@ -112,8 +114,9 @@ exports.jsonObjectFrom = jsonObjectFrom;
|
|
|
112
114
|
* The PostgreSQL `json_build_object` function.
|
|
113
115
|
*
|
|
114
116
|
* NOTE: This helper is only guaranteed to fully work with the built-in `PostgresDialect`.
|
|
115
|
-
* While the produced SQL is
|
|
116
|
-
* may not parse the nested
|
|
117
|
+
* While the produced SQL is compatible with all PostgreSQL databases, some 3rd party dialects
|
|
118
|
+
* may not parse the nested JSON into objects. In these cases you can use the built in
|
|
119
|
+
* `ParseJSONResultsPlugin` to parse the results.
|
|
117
120
|
*
|
|
118
121
|
* ### Examples
|
|
119
122
|
*
|