kysely 0.16.4 → 0.16.8
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 +118 -5
- package/dist/cjs/dialect/mysql/mysql-dialect.js +2 -1
- package/dist/cjs/dialect/mysql/mysql-driver.js +1 -1
- package/dist/cjs/dialect/postgres/postgres-dialect.js +2 -1
- package/dist/cjs/dialect/postgres/postgres-driver.js +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-dialect.js +2 -1
- package/dist/cjs/dialect/sqlite/sqlite-driver.js +1 -1
- package/dist/cjs/driver/dummy-driver.d.ts +68 -0
- package/dist/cjs/driver/dummy-driver.js +62 -0
- package/dist/cjs/driver/runtime-driver.d.ts +1 -1
- package/dist/cjs/driver/runtime-driver.js +30 -33
- package/dist/cjs/index-nodeless.d.ts +2 -0
- package/dist/cjs/index-nodeless.js +2 -0
- package/dist/cjs/kysely.d.ts +8 -6
- package/dist/cjs/kysely.js +8 -6
- package/dist/cjs/migration/migrator.d.ts +2 -2
- package/dist/cjs/operation-node/primitive-value-list-node.d.ts +2 -3
- package/dist/cjs/operation-node/value-node.d.ts +3 -4
- package/dist/cjs/parser/complex-expression-parser.d.ts +1 -0
- package/dist/cjs/parser/complex-expression-parser.js +5 -1
- package/dist/cjs/parser/default-value-parser.d.ts +2 -3
- package/dist/cjs/parser/default-value-parser.js +2 -2
- package/dist/cjs/parser/insert-values-parser.js +4 -3
- package/dist/cjs/parser/reference-parser.d.ts +2 -3
- package/dist/cjs/parser/value-parser.d.ts +2 -3
- package/dist/cjs/parser/value-parser.js +6 -7
- package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-plugin.d.ts +48 -0
- package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-plugin.js +19 -0
- package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +9 -0
- package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-transformer.js +42 -0
- package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.d.ts +0 -0
- package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.js +0 -0
- package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.d.ts +0 -0
- package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.js +0 -0
- package/dist/cjs/query-builder/delete-query-builder.d.ts +51 -9
- package/dist/cjs/query-builder/delete-query-builder.js +56 -8
- package/dist/cjs/query-builder/expression-builder.d.ts +1 -1
- package/dist/cjs/query-builder/expression-builder.js +2 -2
- package/dist/cjs/query-builder/function-builder.d.ts +29 -5
- package/dist/cjs/query-builder/function-builder.js +31 -7
- package/dist/cjs/query-builder/insert-query-builder.d.ts +53 -11
- package/dist/cjs/query-builder/insert-query-builder.js +58 -10
- package/dist/cjs/query-builder/select-query-builder.d.ts +58 -16
- package/dist/cjs/query-builder/select-query-builder.js +64 -15
- package/dist/cjs/query-builder/update-query-builder.d.ts +52 -9
- package/dist/cjs/query-builder/update-query-builder.js +57 -8
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +1 -2
- package/dist/cjs/query-creator.d.ts +2 -2
- package/dist/cjs/query-creator.js +2 -2
- package/dist/cjs/query-executor/query-executor.js +3 -2
- package/dist/cjs/raw-builder/raw-builder.d.ts +2 -2
- package/dist/cjs/raw-builder/raw-builder.js +8 -1
- package/dist/cjs/schema/alter-table-builder.d.ts +30 -4
- package/dist/cjs/schema/alter-table-builder.js +2 -5
- package/dist/cjs/schema/column-definition-builder.d.ts +27 -2
- package/dist/cjs/schema/create-view-builder.js +1 -1
- package/dist/cjs/util/log.d.ts +1 -0
- package/dist/cjs/util/log.js +3 -0
- package/dist/cjs/util/object-utils.d.ts +5 -5
- package/dist/cjs/util/object-utils.js +52 -11
- package/dist/cjs/util/type-utils.d.ts +21 -0
- package/dist/esm/dialect/mysql/mysql-dialect.js +2 -1
- package/dist/esm/dialect/mysql/mysql-driver.js +2 -2
- package/dist/esm/dialect/postgres/postgres-dialect.js +2 -1
- package/dist/esm/dialect/postgres/postgres-driver.js +2 -2
- package/dist/esm/dialect/sqlite/sqlite-dialect.js +2 -1
- package/dist/esm/dialect/sqlite/sqlite-driver.js +2 -2
- package/dist/esm/driver/dummy-driver.d.ts +68 -0
- package/dist/esm/driver/dummy-driver.js +59 -0
- package/dist/esm/driver/runtime-driver.d.ts +1 -1
- package/dist/esm/driver/runtime-driver.js +29 -32
- package/dist/esm/index-nodeless.d.ts +2 -0
- package/dist/esm/index-nodeless.js +2 -0
- package/dist/esm/kysely.d.ts +8 -6
- package/dist/esm/kysely.js +8 -6
- package/dist/esm/migration/migrator.d.ts +2 -2
- package/dist/esm/operation-node/primitive-value-list-node.d.ts +2 -3
- package/dist/esm/operation-node/value-node.d.ts +3 -4
- package/dist/esm/parser/complex-expression-parser.d.ts +1 -0
- package/dist/esm/parser/complex-expression-parser.js +3 -0
- package/dist/esm/parser/default-value-parser.d.ts +2 -3
- package/dist/esm/parser/default-value-parser.js +2 -2
- package/dist/esm/parser/insert-values-parser.js +5 -4
- package/dist/esm/parser/reference-parser.d.ts +2 -3
- package/dist/esm/parser/reference-parser.js +1 -1
- package/dist/esm/parser/value-parser.d.ts +2 -3
- package/dist/esm/parser/value-parser.js +8 -9
- package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-plugin.d.ts +48 -0
- package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-plugin.js +16 -0
- package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +9 -0
- package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-transformer.js +39 -0
- package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.d.ts +0 -0
- package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.js +0 -0
- package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.d.ts +0 -0
- package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.js +0 -0
- package/dist/esm/query-builder/delete-query-builder.d.ts +51 -9
- package/dist/esm/query-builder/delete-query-builder.js +56 -8
- package/dist/esm/query-builder/expression-builder.d.ts +1 -1
- package/dist/esm/query-builder/expression-builder.js +1 -1
- package/dist/esm/query-builder/function-builder.d.ts +29 -5
- package/dist/esm/query-builder/function-builder.js +31 -7
- package/dist/esm/query-builder/insert-query-builder.d.ts +53 -11
- package/dist/esm/query-builder/insert-query-builder.js +58 -10
- package/dist/esm/query-builder/select-query-builder.d.ts +58 -16
- package/dist/esm/query-builder/select-query-builder.js +64 -15
- package/dist/esm/query-builder/update-query-builder.d.ts +52 -9
- package/dist/esm/query-builder/update-query-builder.js +57 -8
- package/dist/esm/query-compiler/default-query-compiler.d.ts +1 -2
- package/dist/esm/query-creator.d.ts +2 -2
- package/dist/esm/query-creator.js +2 -2
- package/dist/esm/query-executor/query-executor.js +3 -2
- package/dist/esm/raw-builder/raw-builder.d.ts +2 -2
- package/dist/esm/raw-builder/raw-builder.js +8 -1
- package/dist/esm/schema/alter-table-builder.d.ts +30 -4
- package/dist/esm/schema/alter-table-builder.js +2 -5
- package/dist/esm/schema/column-definition-builder.d.ts +27 -2
- package/dist/esm/schema/create-view-builder.js +1 -1
- package/dist/esm/util/log.d.ts +1 -0
- package/dist/esm/util/log.js +3 -0
- package/dist/esm/util/object-utils.d.ts +5 -5
- package/dist/esm/util/object-utils.js +50 -9
- package/dist/esm/util/type-utils.d.ts +21 -0
- package/package.json +11 -5
|
@@ -40,6 +40,7 @@ export * from './driver/database-connection.js';
|
|
|
40
40
|
export * from './driver/connection-provider.js';
|
|
41
41
|
export * from './driver/default-connection-provider.js';
|
|
42
42
|
export * from './driver/single-connection-provider.js';
|
|
43
|
+
export * from './driver/dummy-driver.js';
|
|
43
44
|
export * from './dialect/dialect.js';
|
|
44
45
|
export * from './dialect/dialect-adapter.js';
|
|
45
46
|
export * from './dialect/dialect-adapter-base.js';
|
|
@@ -58,6 +59,7 @@ export * from './query-compiler/query-compiler.js';
|
|
|
58
59
|
export * from './migration/migrator.js';
|
|
59
60
|
export * from './plugin/kysely-plugin.js';
|
|
60
61
|
export * from './plugin/camel-case/camel-case-plugin.js';
|
|
62
|
+
export * from './plugin/deduplicate-joins/deduplicate-joins-plugin.js';
|
|
61
63
|
export * from './operation-node/add-column-node.js';
|
|
62
64
|
export * from './operation-node/add-constraint-node.js';
|
|
63
65
|
export * from './operation-node/alias-node.js';
|
|
@@ -41,6 +41,7 @@ export * from './driver/database-connection.js';
|
|
|
41
41
|
export * from './driver/connection-provider.js';
|
|
42
42
|
export * from './driver/default-connection-provider.js';
|
|
43
43
|
export * from './driver/single-connection-provider.js';
|
|
44
|
+
export * from './driver/dummy-driver.js';
|
|
44
45
|
export * from './dialect/dialect.js';
|
|
45
46
|
export * from './dialect/dialect-adapter.js';
|
|
46
47
|
export * from './dialect/dialect-adapter-base.js';
|
|
@@ -59,6 +60,7 @@ export * from './query-compiler/query-compiler.js';
|
|
|
59
60
|
export * from './migration/migrator.js';
|
|
60
61
|
export * from './plugin/kysely-plugin.js';
|
|
61
62
|
export * from './plugin/camel-case/camel-case-plugin.js';
|
|
63
|
+
export * from './plugin/deduplicate-joins/deduplicate-joins-plugin.js';
|
|
62
64
|
export * from './operation-node/add-column-node.js';
|
|
63
65
|
export * from './operation-node/add-constraint-node.js';
|
|
64
66
|
export * from './operation-node/alias-node.js';
|
package/dist/esm/kysely.d.ts
CHANGED
|
@@ -22,22 +22,24 @@ import { DialectAdapter } from './dialect/dialect-adapter.js';
|
|
|
22
22
|
* This example assumes your database has tables `person` and `pet`:
|
|
23
23
|
*
|
|
24
24
|
* ```ts
|
|
25
|
-
*
|
|
26
|
-
*
|
|
25
|
+
* import { Kysely, Generated, PostgresDialect } from 'kysely'
|
|
26
|
+
*
|
|
27
|
+
* interface PersonTable {
|
|
28
|
+
* id: Generated<number>
|
|
27
29
|
* first_name: string
|
|
28
30
|
* last_name: string
|
|
29
31
|
* }
|
|
30
32
|
*
|
|
31
|
-
* interface
|
|
32
|
-
* id: number
|
|
33
|
+
* interface PetTable {
|
|
34
|
+
* id: Generated<number>
|
|
33
35
|
* owner_id: number
|
|
34
36
|
* name: string
|
|
35
37
|
* species 'cat' | 'dog'
|
|
36
38
|
* }
|
|
37
39
|
*
|
|
38
40
|
* interface Database {
|
|
39
|
-
* person:
|
|
40
|
-
* pet:
|
|
41
|
+
* person: PersonTable,
|
|
42
|
+
* pet: PetTable
|
|
41
43
|
* }
|
|
42
44
|
*
|
|
43
45
|
* const db = new Kysely<Database>({
|
package/dist/esm/kysely.js
CHANGED
|
@@ -24,22 +24,24 @@ import { PRIVATE_ADAPTER } from './util/private-symbols.js';
|
|
|
24
24
|
* This example assumes your database has tables `person` and `pet`:
|
|
25
25
|
*
|
|
26
26
|
* ```ts
|
|
27
|
-
*
|
|
28
|
-
*
|
|
27
|
+
* import { Kysely, Generated, PostgresDialect } from 'kysely'
|
|
28
|
+
*
|
|
29
|
+
* interface PersonTable {
|
|
30
|
+
* id: Generated<number>
|
|
29
31
|
* first_name: string
|
|
30
32
|
* last_name: string
|
|
31
33
|
* }
|
|
32
34
|
*
|
|
33
|
-
* interface
|
|
34
|
-
* id: number
|
|
35
|
+
* interface PetTable {
|
|
36
|
+
* id: Generated<number>
|
|
35
37
|
* owner_id: number
|
|
36
38
|
* name: string
|
|
37
39
|
* species 'cat' | 'dog'
|
|
38
40
|
* }
|
|
39
41
|
*
|
|
40
42
|
* interface Database {
|
|
41
|
-
* person:
|
|
42
|
-
* pet:
|
|
43
|
+
* person: PersonTable,
|
|
44
|
+
* pet: PetTable
|
|
43
45
|
* }
|
|
44
46
|
*
|
|
45
47
|
* const db = new Kysely<Database>({
|
|
@@ -144,8 +144,8 @@ export interface MigratorProps {
|
|
|
144
144
|
readonly provider: MigrationProvider;
|
|
145
145
|
}
|
|
146
146
|
/**
|
|
147
|
-
* All migration methods ({@link
|
|
148
|
-
* {@link
|
|
147
|
+
* All migration methods ({@link Migrator.migrateTo | migrateTo},
|
|
148
|
+
* {@link Migrator.migrateToLatest | migrateToLatest} etc.) never
|
|
149
149
|
* throw but return this object instead.
|
|
150
150
|
*/
|
|
151
151
|
export interface MigrationResultSet {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { PrimitiveValue } from '../util/object-utils.js';
|
|
2
1
|
import { OperationNode } from './operation-node.js';
|
|
3
2
|
/**
|
|
4
3
|
* This node is basically just a performance optimization over the normal ValueListNode.
|
|
@@ -7,12 +6,12 @@ import { OperationNode } from './operation-node.js';
|
|
|
7
6
|
*/
|
|
8
7
|
export interface PrimitiveValueListNode extends OperationNode {
|
|
9
8
|
readonly kind: 'PrimitiveValueListNode';
|
|
10
|
-
readonly values: ReadonlyArray<
|
|
9
|
+
readonly values: ReadonlyArray<unknown>;
|
|
11
10
|
}
|
|
12
11
|
/**
|
|
13
12
|
* @internal
|
|
14
13
|
*/
|
|
15
14
|
export declare const PrimitiveValueListNode: Readonly<{
|
|
16
15
|
is(node: OperationNode): node is PrimitiveValueListNode;
|
|
17
|
-
create(values: ReadonlyArray<
|
|
16
|
+
create(values: ReadonlyArray<unknown>): PrimitiveValueListNode;
|
|
18
17
|
}>;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { PrimitiveValue } from '../util/object-utils.js';
|
|
2
1
|
import { OperationNode } from './operation-node.js';
|
|
3
2
|
export interface ValueNode extends OperationNode {
|
|
4
3
|
readonly kind: 'ValueNode';
|
|
5
|
-
readonly value:
|
|
4
|
+
readonly value: unknown;
|
|
6
5
|
readonly immediate?: boolean;
|
|
7
6
|
}
|
|
8
7
|
/**
|
|
@@ -10,6 +9,6 @@ export interface ValueNode extends OperationNode {
|
|
|
10
9
|
*/
|
|
11
10
|
export declare const ValueNode: Readonly<{
|
|
12
11
|
is(node: OperationNode): node is ValueNode;
|
|
13
|
-
create(value:
|
|
14
|
-
createImmediate(value:
|
|
12
|
+
create(value: unknown): ValueNode;
|
|
13
|
+
createImmediate(value: unknown): ValueNode;
|
|
15
14
|
}>;
|
|
@@ -7,3 +7,4 @@ export declare type ComplexExpression<DB, TB extends keyof DB> = AnySelectQueryB
|
|
|
7
7
|
export declare type AliasedComplexExpression<DB, TB extends keyof DB> = AnyAliasedQueryBuilder | AliasedQueryBuilderFactory<DB, TB> | AnyAliasedRawBuilder | AliasedRawBuilderFactory<DB, TB>;
|
|
8
8
|
export declare function parseComplexExpression(ctx: ParseContext, exp: ComplexExpression<any, any>): SelectQueryNode | RawNode;
|
|
9
9
|
export declare function parseAliasedComplexExpression(ctx: ParseContext, exp: AliasedComplexExpression<any, any>): AliasNode;
|
|
10
|
+
export declare function isComplexExpression(obj: unknown): obj is ComplexExpression<any, any>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { RawNode } from '../operation-node/raw-node.js';
|
|
2
2
|
import { ValueNode } from '../operation-node/value-node.js';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export declare type DefaultValueExpression = PrimitiveValue | AnyRawBuilder;
|
|
3
|
+
import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
4
|
+
export declare type DefaultValueExpression = unknown | RawBuilder;
|
|
6
5
|
export declare function parseDefaultValueExpression(value: DefaultValueExpression): ValueNode | RawNode;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="./default-value-parser.d.ts" />
|
|
2
|
-
import { isOperationNodeSource } from '../operation-node/operation-node-source.js';
|
|
3
2
|
import { ValueNode } from '../operation-node/value-node.js';
|
|
3
|
+
import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
4
4
|
export function parseDefaultValueExpression(value) {
|
|
5
|
-
return
|
|
5
|
+
return value instanceof RawBuilder
|
|
6
6
|
? value.toOperationNode()
|
|
7
7
|
: ValueNode.createImmediate(value);
|
|
8
8
|
}
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
import { ColumnNode } from '../operation-node/column-node.js';
|
|
3
3
|
import { PrimitiveValueListNode } from '../operation-node/primitive-value-list-node.js';
|
|
4
4
|
import { ValueListNode } from '../operation-node/value-list-node.js';
|
|
5
|
-
import { freeze
|
|
5
|
+
import { freeze } from '../util/object-utils.js';
|
|
6
6
|
import { parseValueExpression } from './value-parser.js';
|
|
7
7
|
import { ValuesNode } from '../operation-node/values-node.js';
|
|
8
|
+
import { isComplexExpression } from './complex-expression-parser.js';
|
|
8
9
|
export function parseInsertObjectOrList(ctx, args) {
|
|
9
10
|
return parseInsertColumnsAndValues(ctx, Array.isArray(args) ? args : [args]);
|
|
10
11
|
}
|
|
@@ -37,8 +38,8 @@ function parseRowValues(ctx, row, columns) {
|
|
|
37
38
|
rowValues[columnIdx] = value;
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
|
-
if (rowValues.
|
|
41
|
-
return
|
|
41
|
+
if (rowValues.some(isComplexExpression)) {
|
|
42
|
+
return ValueListNode.create(rowValues.map((it) => parseValueExpression(ctx, it)));
|
|
42
43
|
}
|
|
43
|
-
return
|
|
44
|
+
return PrimitiveValueListNode.create(rowValues);
|
|
44
45
|
}
|
|
@@ -2,7 +2,6 @@ import { AliasNode } from '../operation-node/alias-node.js';
|
|
|
2
2
|
import { ColumnNode } from '../operation-node/column-node.js';
|
|
3
3
|
import { ReferenceExpressionNode } from '../operation-node/operation-node-utils.js';
|
|
4
4
|
import { ReferenceNode } from '../operation-node/reference-node.js';
|
|
5
|
-
import { PrimitiveValue } from '../util/object-utils.js';
|
|
6
5
|
import { AnyColumn, AnyColumnWithTable, ExtractColumnType, ValueType } from '../util/type-utils.js';
|
|
7
6
|
import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
8
7
|
import { SelectQueryBuilder } from '../query-builder/select-query-builder.js';
|
|
@@ -13,8 +12,8 @@ import { SelectType } from '../util/column-type.js';
|
|
|
13
12
|
export declare type ReferenceExpression<DB, TB extends keyof DB> = StringReference<DB, TB> | DynamicReferenceBuilder<any> | ComplexExpression<DB, TB>;
|
|
14
13
|
export declare type ReferenceExpressionOrList<DB, TB extends keyof DB> = ReferenceExpression<DB, TB> | ReadonlyArray<ReferenceExpression<DB, TB>>;
|
|
15
14
|
export declare type StringReference<DB, TB extends keyof DB> = AnyColumn<DB, TB> | AnyColumnWithTable<DB, TB>;
|
|
16
|
-
export declare type ExtractTypeFromReferenceExpression<DB, TB extends keyof DB, RE> = RE extends string ? SelectType<ExtractTypeFromStringReference<DB, TB, RE>> : RE extends RawBuilder<infer O> ? O : RE extends (qb: any) => RawBuilder<infer O> ? O : RE extends SelectQueryBuilder<any, any, infer O> ? ValueType<O> : RE extends (qb: any) => SelectQueryBuilder<any, any, infer O> ? ValueType<O> :
|
|
17
|
-
declare type ExtractTypeFromStringReference<DB, TB extends keyof DB, RE extends string> = RE extends `${infer SC}.${infer T}.${infer C}` ? `${SC}.${T}` extends TB ? C extends keyof DB[`${SC}.${T}`] ? DB[`${SC}.${T}`][C] : never : never : RE extends `${infer T}.${infer C}` ? T extends TB ? C extends keyof DB[T] ? DB[T][C] : never : never : RE extends AnyColumn<DB, TB> ? ExtractColumnType<DB, TB, RE> :
|
|
15
|
+
export declare type ExtractTypeFromReferenceExpression<DB, TB extends keyof DB, RE> = RE extends string ? SelectType<ExtractTypeFromStringReference<DB, TB, RE>> : RE extends RawBuilder<infer O> ? O : RE extends (qb: any) => RawBuilder<infer O> ? O : RE extends SelectQueryBuilder<any, any, infer O> ? ValueType<O> : RE extends (qb: any) => SelectQueryBuilder<any, any, infer O> ? ValueType<O> : unknown;
|
|
16
|
+
declare type ExtractTypeFromStringReference<DB, TB extends keyof DB, RE extends string> = RE extends `${infer SC}.${infer T}.${infer C}` ? `${SC}.${T}` extends TB ? C extends keyof DB[`${SC}.${T}`] ? DB[`${SC}.${T}`][C] : never : never : RE extends `${infer T}.${infer C}` ? T extends TB ? C extends keyof DB[T] ? DB[T][C] : never : never : RE extends AnyColumn<DB, TB> ? ExtractColumnType<DB, TB, RE> : unknown;
|
|
18
17
|
export declare function parseReferenceExpressionOrList(ctx: ParseContext, arg: ReferenceExpressionOrList<any, any>): ReferenceExpressionNode[];
|
|
19
18
|
export declare function parseReferenceExpression(ctx: ParseContext, exp: ReferenceExpression<any, any>): ReferenceExpressionNode;
|
|
20
19
|
export declare function parseStringReference(ref: string): ColumnNode | ReferenceNode;
|
|
@@ -3,7 +3,7 @@ import { AliasNode } from '../operation-node/alias-node.js';
|
|
|
3
3
|
import { ColumnNode } from '../operation-node/column-node.js';
|
|
4
4
|
import { ReferenceNode } from '../operation-node/reference-node.js';
|
|
5
5
|
import { TableNode } from '../operation-node/table-node.js';
|
|
6
|
-
import { isReadonlyArray, isString
|
|
6
|
+
import { isReadonlyArray, isString } from '../util/object-utils.js';
|
|
7
7
|
import { parseComplexExpression, } from './complex-expression-parser.js';
|
|
8
8
|
import { isDynamicReferenceBuilder, } from '../dynamic/dynamic-reference-builder.js';
|
|
9
9
|
export function parseReferenceExpressionOrList(ctx, arg) {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { ValueExpressionNode } from '../operation-node/operation-node-utils.js';
|
|
2
2
|
import { ValueNode } from '../operation-node/value-node.js';
|
|
3
|
-
import { PrimitiveValue } from '../util/object-utils.js';
|
|
4
3
|
import { ParseContext } from './parse-context.js';
|
|
5
4
|
import { SelectQueryNode } from '../operation-node/select-query-node.js';
|
|
6
5
|
import { RawNode } from '../operation-node/raw-node.js';
|
|
7
6
|
import { ComplexExpression } from './complex-expression-parser.js';
|
|
8
7
|
export declare type ValueExpression<DB, TB extends keyof DB, V> = V | ComplexExpression<DB, TB>;
|
|
9
8
|
export declare type ValueExpressionOrList<DB, TB extends keyof DB, V> = ValueExpression<DB, TB, V> | ReadonlyArray<ValueExpression<DB, TB, V>>;
|
|
10
|
-
export declare function parseValueExpressionOrList(ctx: ParseContext, arg: ValueExpressionOrList<any, any,
|
|
11
|
-
export declare function parseValueExpression(ctx: ParseContext, exp: ValueExpression<any, any,
|
|
9
|
+
export declare function parseValueExpressionOrList(ctx: ParseContext, arg: ValueExpressionOrList<any, any, unknown>): ValueExpressionNode;
|
|
10
|
+
export declare function parseValueExpression(ctx: ParseContext, exp: ValueExpression<any, any, unknown>): ValueNode | SelectQueryNode | RawNode;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { PrimitiveValueListNode } from '../operation-node/primitive-value-list-node.js';
|
|
3
3
|
import { ValueListNode } from '../operation-node/value-list-node.js';
|
|
4
4
|
import { ValueNode } from '../operation-node/value-node.js';
|
|
5
|
-
import {
|
|
6
|
-
import { parseComplexExpression, } from './complex-expression-parser.js';
|
|
5
|
+
import { isReadonlyArray } from '../util/object-utils.js';
|
|
6
|
+
import { parseComplexExpression, isComplexExpression, } from './complex-expression-parser.js';
|
|
7
7
|
export function parseValueExpressionOrList(ctx, arg) {
|
|
8
8
|
if (isReadonlyArray(arg)) {
|
|
9
9
|
return parseValueExpressionList(ctx, arg);
|
|
@@ -13,15 +13,14 @@ export function parseValueExpressionOrList(ctx, arg) {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
export function parseValueExpression(ctx, exp) {
|
|
16
|
-
if (
|
|
17
|
-
return
|
|
16
|
+
if (isComplexExpression(exp)) {
|
|
17
|
+
return parseComplexExpression(ctx, exp);
|
|
18
18
|
}
|
|
19
|
-
return
|
|
19
|
+
return ValueNode.create(exp);
|
|
20
20
|
}
|
|
21
21
|
function parseValueExpressionList(ctx, arg) {
|
|
22
|
-
if (arg.
|
|
23
|
-
|
|
24
|
-
return PrimitiveValueListNode.create(arg);
|
|
22
|
+
if (arg.some(isComplexExpression)) {
|
|
23
|
+
return ValueListNode.create(arg.map((it) => parseValueExpression(ctx, it)));
|
|
25
24
|
}
|
|
26
|
-
return
|
|
25
|
+
return PrimitiveValueListNode.create(arg);
|
|
27
26
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { QueryResult } from '../../driver/database-connection.js';
|
|
2
|
+
import { RootOperationNode } from '../../query-compiler/query-compiler.js';
|
|
3
|
+
import { UnknownRow } from '../../util/type-utils.js';
|
|
4
|
+
import { KyselyPlugin, PluginTransformQueryArgs, PluginTransformResultArgs } from '../kysely-plugin.js';
|
|
5
|
+
/**
|
|
6
|
+
* Plugin that removes duplicate joins from queries.
|
|
7
|
+
*
|
|
8
|
+
* See [this recipe](https://github.com/koskimas/kysely/tree/master/recipes/deduplicate-joins.md)
|
|
9
|
+
*/
|
|
10
|
+
export declare class DeduplicateJoinsPlugin implements KyselyPlugin {
|
|
11
|
+
#private;
|
|
12
|
+
/**
|
|
13
|
+
* This is called for each query before it is executed. You can modify the query by
|
|
14
|
+
* transforming its {@link OperationNode} tree provided in {@link PluginTransformQueryArgs.node | args.node}
|
|
15
|
+
* and returning the transformed tree. You'd usually want to use an {@link OperationNodeTransformer}
|
|
16
|
+
* for this.
|
|
17
|
+
*
|
|
18
|
+
* If you need to pass some query-related data between this method and `transformResult` you
|
|
19
|
+
* can use a `WeakMap` with {@link PluginTransformQueryArgs.queryId | args.queryId} as the key:
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* const plugin = {
|
|
23
|
+
* data: new WeakMap<QueryId, SomeData>(),
|
|
24
|
+
*
|
|
25
|
+
* transformQuery(args: PluginTransformQueryArgs): RootOperationNode {
|
|
26
|
+
* this.data.set(args.queryId, something)
|
|
27
|
+
* return args.node
|
|
28
|
+
* },
|
|
29
|
+
*
|
|
30
|
+
* transformResult(args: PluginTransformResultArgs): QueryResult<UnknownRow> {
|
|
31
|
+
* const data = this.data.get(args.queryId)
|
|
32
|
+
* return args.result
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* You should use a `WeakMap` instead of a `Map` or some other strong references because `transformQuery`
|
|
38
|
+
* is not always matched by a call to `transformResult` which would leave orphaned items in the map
|
|
39
|
+
* and cause a memory leak.
|
|
40
|
+
*/
|
|
41
|
+
transformQuery(args: PluginTransformQueryArgs): RootOperationNode;
|
|
42
|
+
/**
|
|
43
|
+
* This method is called for each query after it has been executed. The result
|
|
44
|
+
* of the query can be accessed through {@link PluginTransformResultArgs.result | args.result}.
|
|
45
|
+
* You can modify the result and return the modifier result.
|
|
46
|
+
*/
|
|
47
|
+
transformResult(args: PluginTransformResultArgs): Promise<QueryResult<UnknownRow>>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="./deduplicate-joins-plugin.d.ts" />
|
|
2
|
+
import { DeduplicateJoinsTransformer } from './deduplicate-joins-transformer.js';
|
|
3
|
+
/**
|
|
4
|
+
* Plugin that removes duplicate joins from queries.
|
|
5
|
+
*
|
|
6
|
+
* See [this recipe](https://github.com/koskimas/kysely/tree/master/recipes/deduplicate-joins.md)
|
|
7
|
+
*/
|
|
8
|
+
export class DeduplicateJoinsPlugin {
|
|
9
|
+
#transformer = new DeduplicateJoinsTransformer();
|
|
10
|
+
transformQuery(args) {
|
|
11
|
+
return this.#transformer.transformNode(args.node);
|
|
12
|
+
}
|
|
13
|
+
transformResult(args) {
|
|
14
|
+
return Promise.resolve(args.result);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DeleteQueryNode, UpdateQueryNode } from '../../index-nodeless.js';
|
|
2
|
+
import { OperationNodeTransformer } from '../../operation-node/operation-node-transformer.js';
|
|
3
|
+
import { SelectQueryNode } from '../../operation-node/select-query-node.js';
|
|
4
|
+
export declare class DeduplicateJoinsTransformer extends OperationNodeTransformer {
|
|
5
|
+
#private;
|
|
6
|
+
protected transformSelectQuery(node: SelectQueryNode): SelectQueryNode;
|
|
7
|
+
protected transformUpdateQuery(node: UpdateQueryNode): UpdateQueryNode;
|
|
8
|
+
protected transformDeleteQuery(node: DeleteQueryNode): DeleteQueryNode;
|
|
9
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/// <reference types="./deduplicate-joins-transformer.d.ts" />
|
|
2
|
+
import { OperationNodeTransformer } from '../../operation-node/operation-node-transformer.js';
|
|
3
|
+
import { compare, freeze } from '../../util/object-utils.js';
|
|
4
|
+
export class DeduplicateJoinsTransformer extends OperationNodeTransformer {
|
|
5
|
+
transformSelectQuery(node) {
|
|
6
|
+
return this.#transformQuery(super.transformSelectQuery(node));
|
|
7
|
+
}
|
|
8
|
+
transformUpdateQuery(node) {
|
|
9
|
+
return this.#transformQuery(super.transformUpdateQuery(node));
|
|
10
|
+
}
|
|
11
|
+
transformDeleteQuery(node) {
|
|
12
|
+
return this.#transformQuery(super.transformDeleteQuery(node));
|
|
13
|
+
}
|
|
14
|
+
#transformQuery(node) {
|
|
15
|
+
if (!node.joins || node.joins.length === 0) {
|
|
16
|
+
return node;
|
|
17
|
+
}
|
|
18
|
+
return freeze({
|
|
19
|
+
...node,
|
|
20
|
+
joins: this.#deduplicateJoins(node.joins),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
#deduplicateJoins(joins) {
|
|
24
|
+
const out = [];
|
|
25
|
+
for (let i = 0; i < joins.length; ++i) {
|
|
26
|
+
let foundDuplicate = false;
|
|
27
|
+
for (let j = i + 1; j < joins.length; ++j) {
|
|
28
|
+
if (compare(joins[i], joins[j])) {
|
|
29
|
+
foundDuplicate = true;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (!foundDuplicate) {
|
|
34
|
+
out.push(joins[i]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return freeze(out);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
File without changes
|
|
File without changes
|
package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.d.ts
RENAMED
|
File without changes
|
package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.js
RENAMED
|
File without changes
|
|
@@ -6,7 +6,7 @@ import { SelectExpression } from '../parser/select-parser.js';
|
|
|
6
6
|
import { ExistsExpression, FilterOperator, FilterValueExpressionOrList, WhereGrouper } from '../parser/filter-parser.js';
|
|
7
7
|
import { ReturningRow } from '../parser/returning-parser.js';
|
|
8
8
|
import { ReferenceExpression } from '../parser/reference-parser.js';
|
|
9
|
-
import { AnyRawBuilder, SingleResultType } from '../util/type-utils.js';
|
|
9
|
+
import { AnyRawBuilder, MergePartial, SingleResultType } from '../util/type-utils.js';
|
|
10
10
|
import { Compilable } from '../util/compilable.js';
|
|
11
11
|
import { QueryExecutor } from '../query-executor/query-executor.js';
|
|
12
12
|
import { QueryId } from '../util/query-id.js';
|
|
@@ -16,6 +16,7 @@ import { WhereInterface } from './where-interface.js';
|
|
|
16
16
|
import { JoinInterface } from './join-interface.js';
|
|
17
17
|
import { ReturningInterface } from './returning-interface.js';
|
|
18
18
|
import { NoResultErrorConstructor } from './no-result-error.js';
|
|
19
|
+
import { DeleteResult } from './delete-result.js';
|
|
19
20
|
import { DeleteQueryNode } from '../operation-node/delete-query-node.js';
|
|
20
21
|
import { Selectable } from '../util/column-type.js';
|
|
21
22
|
export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements WhereInterface<DB, TB>, JoinInterface<DB, TB>, ReturningInterface<DB, TB, O>, OperationNodeSource, Compilable {
|
|
@@ -589,23 +590,61 @@ export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
589
590
|
/**
|
|
590
591
|
* Simply calls the given function passing `this` as the only argument.
|
|
591
592
|
*
|
|
592
|
-
*
|
|
593
|
+
* If you want to conditionally call a method on `this`, see
|
|
594
|
+
* the {@link if} method.
|
|
593
595
|
*
|
|
594
596
|
* ### Examples
|
|
595
597
|
*
|
|
598
|
+
* The next example uses a helper funtion `log` to log a query:
|
|
599
|
+
*
|
|
596
600
|
* ```ts
|
|
601
|
+
* function log<T extends Compilable>(qb: T): T {
|
|
602
|
+
* console.log(qb.compile())
|
|
603
|
+
* return qb
|
|
604
|
+
* }
|
|
605
|
+
*
|
|
597
606
|
* db.deleteFrom('person')
|
|
598
|
-
* .call(
|
|
599
|
-
* if (something) {
|
|
600
|
-
* return qb.where('something', '=', something)
|
|
601
|
-
* } else {
|
|
602
|
-
* return qb.where('somethingElse', '=', somethingElse)
|
|
603
|
-
* }
|
|
604
|
-
* })
|
|
607
|
+
* .call(log)
|
|
605
608
|
* .execute()
|
|
606
609
|
* ```
|
|
607
610
|
*/
|
|
608
611
|
call<T>(func: (qb: this) => T): T;
|
|
612
|
+
/**
|
|
613
|
+
* Call `func(this)` if `condition` is true.
|
|
614
|
+
*
|
|
615
|
+
* This method is especially handy with optional selects. Any `returning` or `returningAll`
|
|
616
|
+
* method calls add columns as optional fields to the output type when called inside
|
|
617
|
+
* the `func` callback. This is because we can't know if those selections were actually
|
|
618
|
+
* made before running the code.
|
|
619
|
+
*
|
|
620
|
+
* You can also call any other methods inside the callback.
|
|
621
|
+
*
|
|
622
|
+
* ### Examples
|
|
623
|
+
*
|
|
624
|
+
* ```ts
|
|
625
|
+
* async function deletePerson(id: number, returnLastName: boolean) {
|
|
626
|
+
* return await db
|
|
627
|
+
* .deleteFrom('person')
|
|
628
|
+
* .where('id', '=', id)
|
|
629
|
+
* .returning(['id', 'first_name'])
|
|
630
|
+
* .if(returnLastName, (qb) => qb.returning('last_name'))
|
|
631
|
+
* .executeTakeFirstOrThrow()
|
|
632
|
+
* }
|
|
633
|
+
* ```
|
|
634
|
+
*
|
|
635
|
+
* Any selections added inside the `if` callback will be added as optional fields to the
|
|
636
|
+
* output type since we can't know if the selections were actually made before running
|
|
637
|
+
* the code. In the example above the return type of the `deletePerson` function is:
|
|
638
|
+
*
|
|
639
|
+
* ```ts
|
|
640
|
+
* {
|
|
641
|
+
* id: number
|
|
642
|
+
* first_name: string
|
|
643
|
+
* last_name?: string
|
|
644
|
+
* }
|
|
645
|
+
* ```
|
|
646
|
+
*/
|
|
647
|
+
if<O2>(condition: boolean, func: (qb: this) => DeleteQueryBuilder<DB, TB, O2>): DeleteQueryBuilder<DB, TB, O2 extends DeleteResult ? DeleteResult : O extends DeleteResult ? Partial<O2> : MergePartial<O, O2>>;
|
|
609
648
|
/**
|
|
610
649
|
* Change the output type of the query.
|
|
611
650
|
*
|
|
@@ -613,6 +652,9 @@ export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
613
652
|
* don't support your use case.
|
|
614
653
|
*/
|
|
615
654
|
castTo<T>(): DeleteQueryBuilder<DB, TB, T>;
|
|
655
|
+
/**
|
|
656
|
+
* Returns a copy of this DeleteQueryBuilder instance with the given plugin installed.
|
|
657
|
+
*/
|
|
616
658
|
withPlugin(plugin: KyselyPlugin): DeleteQueryBuilder<DB, TB, O>;
|
|
617
659
|
toOperationNode(): DeleteQueryNode;
|
|
618
660
|
compile(): CompiledQuery;
|
|
@@ -99,25 +99,70 @@ export class DeleteQueryBuilder {
|
|
|
99
99
|
/**
|
|
100
100
|
* Simply calls the given function passing `this` as the only argument.
|
|
101
101
|
*
|
|
102
|
-
*
|
|
102
|
+
* If you want to conditionally call a method on `this`, see
|
|
103
|
+
* the {@link if} method.
|
|
103
104
|
*
|
|
104
105
|
* ### Examples
|
|
105
106
|
*
|
|
107
|
+
* The next example uses a helper funtion `log` to log a query:
|
|
108
|
+
*
|
|
106
109
|
* ```ts
|
|
110
|
+
* function log<T extends Compilable>(qb: T): T {
|
|
111
|
+
* console.log(qb.compile())
|
|
112
|
+
* return qb
|
|
113
|
+
* }
|
|
114
|
+
*
|
|
107
115
|
* db.deleteFrom('person')
|
|
108
|
-
* .call(
|
|
109
|
-
* if (something) {
|
|
110
|
-
* return qb.where('something', '=', something)
|
|
111
|
-
* } else {
|
|
112
|
-
* return qb.where('somethingElse', '=', somethingElse)
|
|
113
|
-
* }
|
|
114
|
-
* })
|
|
116
|
+
* .call(log)
|
|
115
117
|
* .execute()
|
|
116
118
|
* ```
|
|
117
119
|
*/
|
|
118
120
|
call(func) {
|
|
119
121
|
return func(this);
|
|
120
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Call `func(this)` if `condition` is true.
|
|
125
|
+
*
|
|
126
|
+
* This method is especially handy with optional selects. Any `returning` or `returningAll`
|
|
127
|
+
* method calls add columns as optional fields to the output type when called inside
|
|
128
|
+
* the `func` callback. This is because we can't know if those selections were actually
|
|
129
|
+
* made before running the code.
|
|
130
|
+
*
|
|
131
|
+
* You can also call any other methods inside the callback.
|
|
132
|
+
*
|
|
133
|
+
* ### Examples
|
|
134
|
+
*
|
|
135
|
+
* ```ts
|
|
136
|
+
* async function deletePerson(id: number, returnLastName: boolean) {
|
|
137
|
+
* return await db
|
|
138
|
+
* .deleteFrom('person')
|
|
139
|
+
* .where('id', '=', id)
|
|
140
|
+
* .returning(['id', 'first_name'])
|
|
141
|
+
* .if(returnLastName, (qb) => qb.returning('last_name'))
|
|
142
|
+
* .executeTakeFirstOrThrow()
|
|
143
|
+
* }
|
|
144
|
+
* ```
|
|
145
|
+
*
|
|
146
|
+
* Any selections added inside the `if` callback will be added as optional fields to the
|
|
147
|
+
* output type since we can't know if the selections were actually made before running
|
|
148
|
+
* the code. In the example above the return type of the `deletePerson` function is:
|
|
149
|
+
*
|
|
150
|
+
* ```ts
|
|
151
|
+
* {
|
|
152
|
+
* id: number
|
|
153
|
+
* first_name: string
|
|
154
|
+
* last_name?: string
|
|
155
|
+
* }
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
if(condition, func) {
|
|
159
|
+
if (condition) {
|
|
160
|
+
return func(this);
|
|
161
|
+
}
|
|
162
|
+
return new DeleteQueryBuilder({
|
|
163
|
+
...this.#props,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
121
166
|
/**
|
|
122
167
|
* Change the output type of the query.
|
|
123
168
|
*
|
|
@@ -127,6 +172,9 @@ export class DeleteQueryBuilder {
|
|
|
127
172
|
castTo() {
|
|
128
173
|
return new DeleteQueryBuilder(this.#props);
|
|
129
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* Returns a copy of this DeleteQueryBuilder instance with the given plugin installed.
|
|
177
|
+
*/
|
|
130
178
|
withPlugin(plugin) {
|
|
131
179
|
return new DeleteQueryBuilder({
|
|
132
180
|
...this.#props,
|
|
@@ -3,8 +3,8 @@ import { TableExpression, TableExpressionDatabase, TableExpressionTables } from
|
|
|
3
3
|
import { NoopQueryExecutor } from '../query-executor/noop-query-executor.js';
|
|
4
4
|
import { ParseContext } from '../parser/parse-context.js';
|
|
5
5
|
import { FunctionBuilder } from './function-builder.js';
|
|
6
|
-
import { RawBuilder } from '../index-nodeless.js';
|
|
7
6
|
import { ExtractTypeFromReferenceExpression, StringReference } from '../parser/reference-parser.js';
|
|
7
|
+
import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
8
8
|
export declare class ExpressionBuilder<DB, TB extends keyof DB> {
|
|
9
9
|
#private;
|
|
10
10
|
constructor(props: ExpressionBuilderProps);
|
|
@@ -6,7 +6,7 @@ import { WithSchemaPlugin } from '../plugin/with-schema/with-schema-plugin.js';
|
|
|
6
6
|
import { createQueryId } from '../util/query-id.js';
|
|
7
7
|
import { freeze } from '../util/object-utils.js';
|
|
8
8
|
import { FunctionBuilder } from './function-builder.js';
|
|
9
|
-
import { RawBuilder } from '../
|
|
9
|
+
import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
10
10
|
export class ExpressionBuilder {
|
|
11
11
|
#props;
|
|
12
12
|
constructor(props) {
|