kysely 0.17.3 → 0.19.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 +24 -17
- package/dist/cjs/dialect/database-introspector.d.ts +13 -0
- package/dist/cjs/dialect/mysql/mysql-dialect-config.d.ts +24 -207
- package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +26 -3
- package/dist/cjs/dialect/mysql/mysql-dialect.js +27 -5
- package/dist/cjs/dialect/mysql/mysql-driver.d.ts +13 -4
- package/dist/cjs/dialect/mysql/mysql-driver.js +33 -51
- package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +11 -1
- package/dist/cjs/dialect/mysql/mysql-introspector.js +29 -7
- package/dist/cjs/dialect/postgres/postgres-dialect-config.d.ts +25 -89
- package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +25 -5
- package/dist/cjs/dialect/postgres/postgres-dialect.js +26 -7
- package/dist/cjs/dialect/postgres/postgres-driver.d.ts +12 -3
- package/dist/cjs/dialect/postgres/postgres-driver.js +21 -39
- package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +11 -1
- package/dist/cjs/dialect/postgres/postgres-introspector.js +15 -4
- package/dist/cjs/dialect/sqlite/sqlite-dialect-config.d.ts +25 -28
- package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +19 -3
- package/dist/cjs/dialect/sqlite/sqlite-dialect.js +19 -3
- package/dist/cjs/dialect/sqlite/sqlite-driver.js +3 -37
- package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +11 -1
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +11 -4
- package/dist/cjs/index.d.ts +153 -2
- package/dist/cjs/index.js +147 -3
- package/dist/cjs/migration/file-migration-provider.d.ts +21 -5
- package/dist/cjs/migration/file-migration-provider.js +14 -13
- package/dist/cjs/migration/migrator.d.ts +44 -2
- package/dist/cjs/migration/migrator.js +77 -18
- package/dist/cjs/operation-node/alias-node.d.ts +2 -2
- package/dist/cjs/operation-node/alias-node.js +1 -2
- package/dist/cjs/operation-node/operation-node-transformer.js +1 -0
- package/dist/cjs/operation-node/update-query-node.d.ts +3 -0
- package/dist/cjs/operation-node/update-query-node.js +11 -2
- package/dist/cjs/parser/reference-parser.js +2 -1
- package/dist/cjs/parser/table-parser.js +2 -1
- package/dist/cjs/parser/update-set-parser.d.ts +3 -3
- package/dist/cjs/parser/with-parser.d.ts +2 -2
- package/dist/cjs/plugin/noop-plugin.d.ts +42 -0
- package/dist/cjs/plugin/noop-plugin.js +12 -0
- package/dist/cjs/query-builder/insert-query-builder.d.ts +1 -1
- package/dist/cjs/query-builder/on-conflict-builder.d.ts +1 -1
- package/dist/cjs/query-builder/select-query-builder.d.ts +3 -1
- package/dist/cjs/query-builder/select-query-builder.js +5 -5
- package/dist/cjs/query-builder/update-query-builder.d.ts +57 -28
- package/dist/cjs/query-builder/update-query-builder.js +7 -0
- package/dist/cjs/query-compiler/default-query-compiler.js +4 -0
- package/dist/cjs/query-creator.d.ts +10 -1
- package/dist/cjs/query-creator.js +18 -0
- package/dist/cjs/raw-builder/raw-builder.d.ts +32 -2
- package/dist/cjs/raw-builder/raw-builder.js +5 -26
- package/dist/cjs/schema/schema.d.ts +9 -0
- package/dist/cjs/schema/schema.js +12 -0
- package/dist/cjs/util/column-type.d.ts +9 -1
- package/dist/cjs/util/stack-trace-utils.d.ts +1 -0
- package/dist/cjs/util/stack-trace-utils.js +17 -0
- package/dist/esm/dialect/database-introspector.d.ts +13 -0
- package/dist/esm/dialect/mysql/mysql-dialect-config.d.ts +24 -207
- package/dist/esm/dialect/mysql/mysql-dialect.d.ts +26 -3
- package/dist/esm/dialect/mysql/mysql-dialect.js +27 -5
- package/dist/esm/dialect/mysql/mysql-driver.d.ts +13 -4
- package/dist/esm/dialect/mysql/mysql-driver.js +33 -51
- package/dist/esm/dialect/mysql/mysql-introspector.d.ts +11 -1
- package/dist/esm/dialect/mysql/mysql-introspector.js +30 -8
- package/dist/esm/dialect/postgres/postgres-dialect-config.d.ts +25 -89
- package/dist/esm/dialect/postgres/postgres-dialect.d.ts +25 -5
- package/dist/esm/dialect/postgres/postgres-dialect.js +26 -7
- package/dist/esm/dialect/postgres/postgres-driver.d.ts +12 -3
- package/dist/esm/dialect/postgres/postgres-driver.js +21 -39
- package/dist/esm/dialect/postgres/postgres-introspector.d.ts +11 -1
- package/dist/esm/dialect/postgres/postgres-introspector.js +16 -5
- package/dist/esm/dialect/sqlite/sqlite-dialect-config.d.ts +25 -28
- package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +19 -3
- package/dist/esm/dialect/sqlite/sqlite-dialect.js +19 -3
- package/dist/esm/dialect/sqlite/sqlite-driver.js +4 -38
- package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +11 -1
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +12 -5
- package/dist/esm/index.d.ts +153 -2
- package/dist/esm/index.js +142 -2
- package/dist/esm/migration/file-migration-provider.d.ts +21 -5
- package/dist/esm/migration/file-migration-provider.js +14 -13
- package/dist/esm/migration/migrator.d.ts +44 -2
- package/dist/esm/migration/migrator.js +76 -17
- package/dist/esm/operation-node/alias-node.d.ts +2 -2
- package/dist/esm/operation-node/alias-node.js +1 -2
- package/dist/esm/operation-node/operation-node-transformer.js +1 -0
- package/dist/esm/operation-node/update-query-node.d.ts +3 -0
- package/dist/esm/operation-node/update-query-node.js +11 -2
- package/dist/esm/parser/reference-parser.js +2 -1
- package/dist/esm/parser/table-parser.js +2 -1
- package/dist/esm/parser/update-set-parser.d.ts +3 -3
- package/dist/esm/parser/with-parser.d.ts +2 -2
- package/dist/esm/plugin/noop-plugin.d.ts +42 -0
- package/dist/esm/plugin/noop-plugin.js +9 -0
- package/dist/esm/query-builder/insert-query-builder.d.ts +1 -1
- package/dist/esm/query-builder/on-conflict-builder.d.ts +1 -1
- package/dist/esm/query-builder/select-query-builder.d.ts +3 -1
- package/dist/esm/query-builder/select-query-builder.js +5 -5
- package/dist/esm/query-builder/update-query-builder.d.ts +57 -28
- package/dist/esm/query-builder/update-query-builder.js +7 -0
- package/dist/esm/query-compiler/default-query-compiler.js +4 -0
- package/dist/esm/query-creator.d.ts +10 -1
- package/dist/esm/query-creator.js +18 -0
- package/dist/esm/raw-builder/raw-builder.d.ts +32 -2
- package/dist/esm/raw-builder/raw-builder.js +5 -26
- package/dist/esm/schema/schema.d.ts +9 -0
- package/dist/esm/schema/schema.js +12 -0
- package/dist/esm/util/column-type.d.ts +9 -1
- package/dist/esm/util/stack-trace-utils.d.ts +1 -0
- package/dist/esm/util/stack-trace-utils.js +14 -0
- package/package.json +10 -15
- package/dist/cjs/index-nodeless.d.ts +0 -152
- package/dist/cjs/index-nodeless.js +0 -153
- package/dist/esm/index-nodeless.d.ts +0 -152
- package/dist/esm/index-nodeless.js +0 -142
|
@@ -9,12 +9,12 @@ export declare type AliasNodeChild = ColumnNode | ReferenceNode | TableNode | Se
|
|
|
9
9
|
export interface AliasNode extends OperationNode {
|
|
10
10
|
readonly kind: 'AliasNode';
|
|
11
11
|
readonly node: AliasNodeChild;
|
|
12
|
-
readonly alias: IdentifierNode;
|
|
12
|
+
readonly alias: IdentifierNode | RawNode;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* @internal
|
|
16
16
|
*/
|
|
17
17
|
export declare const AliasNode: Readonly<{
|
|
18
18
|
is(node: OperationNode): node is AliasNode;
|
|
19
|
-
create(node: AliasNodeChild, alias:
|
|
19
|
+
create(node: AliasNodeChild, alias: IdentifierNode | RawNode): AliasNode;
|
|
20
20
|
}>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/// <reference types="./alias-node.d.ts" />
|
|
2
2
|
import { freeze } from '../util/object-utils.js';
|
|
3
|
-
import { IdentifierNode } from './identifier-node.js';
|
|
4
3
|
/**
|
|
5
4
|
* @internal
|
|
6
5
|
*/
|
|
@@ -12,7 +11,7 @@ export const AliasNode = freeze({
|
|
|
12
11
|
return freeze({
|
|
13
12
|
kind: 'AliasNode',
|
|
14
13
|
node,
|
|
15
|
-
alias
|
|
14
|
+
alias,
|
|
16
15
|
});
|
|
17
16
|
},
|
|
18
17
|
});
|
|
@@ -331,6 +331,7 @@ export class OperationNodeTransformer {
|
|
|
331
331
|
return {
|
|
332
332
|
kind: 'UpdateQueryNode',
|
|
333
333
|
table: this.transformNode(node.table),
|
|
334
|
+
from: this.transformNode(node.from),
|
|
334
335
|
joins: this.transformNodeList(node.joins),
|
|
335
336
|
where: this.transformNode(node.where),
|
|
336
337
|
updates: this.transformNodeList(node.updates),
|
|
@@ -7,10 +7,12 @@ import { ReturningNode } from './returning-node.js';
|
|
|
7
7
|
import { ValueListNode } from './value-list-node.js';
|
|
8
8
|
import { WhereNode } from './where-node.js';
|
|
9
9
|
import { WithNode } from './with-node.js';
|
|
10
|
+
import { FromNode } from './from-node.js';
|
|
10
11
|
export declare type UpdateValuesNode = ValueListNode | PrimitiveValueListNode;
|
|
11
12
|
export interface UpdateQueryNode extends OperationNode {
|
|
12
13
|
readonly kind: 'UpdateQueryNode';
|
|
13
14
|
readonly table: TableExpressionNode;
|
|
15
|
+
readonly from?: FromNode;
|
|
14
16
|
readonly joins?: ReadonlyArray<JoinNode>;
|
|
15
17
|
readonly where?: WhereNode;
|
|
16
18
|
readonly updates?: ReadonlyArray<ColumnUpdateNode>;
|
|
@@ -23,5 +25,6 @@ export interface UpdateQueryNode extends OperationNode {
|
|
|
23
25
|
export declare const UpdateQueryNode: Readonly<{
|
|
24
26
|
is(node: OperationNode): node is UpdateQueryNode;
|
|
25
27
|
create(table: TableExpressionNode, withNode?: WithNode | undefined): UpdateQueryNode;
|
|
28
|
+
cloneWithFromItems(updateQuery: UpdateQueryNode, fromItems: ReadonlyArray<TableExpressionNode>): UpdateQueryNode;
|
|
26
29
|
cloneWithUpdates(updateQuery: UpdateQueryNode, updates: ReadonlyArray<ColumnUpdateNode>): UpdateQueryNode;
|
|
27
30
|
}>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="./update-query-node.d.ts" />
|
|
2
2
|
import { freeze } from '../util/object-utils.js';
|
|
3
|
+
import { FromNode } from './from-node.js';
|
|
3
4
|
/**
|
|
4
5
|
* @internal
|
|
5
6
|
*/
|
|
@@ -8,11 +9,19 @@ export const UpdateQueryNode = freeze({
|
|
|
8
9
|
return node.kind === 'UpdateQueryNode';
|
|
9
10
|
},
|
|
10
11
|
create(table, withNode) {
|
|
11
|
-
return {
|
|
12
|
+
return freeze({
|
|
12
13
|
kind: 'UpdateQueryNode',
|
|
13
14
|
table,
|
|
14
15
|
...(withNode && { with: withNode }),
|
|
15
|
-
};
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
cloneWithFromItems(updateQuery, fromItems) {
|
|
19
|
+
return freeze({
|
|
20
|
+
...updateQuery,
|
|
21
|
+
from: updateQuery.from
|
|
22
|
+
? FromNode.cloneWithFroms(updateQuery.from, fromItems)
|
|
23
|
+
: FromNode.create(fromItems),
|
|
24
|
+
});
|
|
16
25
|
},
|
|
17
26
|
cloneWithUpdates(updateQuery, updates) {
|
|
18
27
|
return freeze({
|
|
@@ -6,6 +6,7 @@ import { TableNode } from '../operation-node/table-node.js';
|
|
|
6
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
|
+
import { IdentifierNode } from '../operation-node/identifier-node.js';
|
|
9
10
|
export function parseReferenceExpressionOrList(arg) {
|
|
10
11
|
if (isReadonlyArray(arg)) {
|
|
11
12
|
return arg.map((it) => parseReferenceExpression(it));
|
|
@@ -45,7 +46,7 @@ export function parseAliasedStringReference(ref) {
|
|
|
45
46
|
const ALIAS_SEPARATOR = ' as ';
|
|
46
47
|
if (ref.includes(ALIAS_SEPARATOR)) {
|
|
47
48
|
const [columnRef, alias] = ref.split(ALIAS_SEPARATOR).map(trim);
|
|
48
|
-
return AliasNode.create(parseStringReference(columnRef), alias);
|
|
49
|
+
return AliasNode.create(parseStringReference(columnRef), IdentifierNode.create(alias));
|
|
49
50
|
}
|
|
50
51
|
else {
|
|
51
52
|
return parseStringReference(ref);
|
|
@@ -3,6 +3,7 @@ import { isReadonlyArray, isString } from '../util/object-utils.js';
|
|
|
3
3
|
import { AliasNode } from '../operation-node/alias-node.js';
|
|
4
4
|
import { TableNode } from '../operation-node/table-node.js';
|
|
5
5
|
import { parseAliasedComplexExpression, } from './complex-expression-parser.js';
|
|
6
|
+
import { IdentifierNode } from '../operation-node/identifier-node.js';
|
|
6
7
|
export function parseTableExpressionOrList(table) {
|
|
7
8
|
if (isReadonlyArray(table)) {
|
|
8
9
|
return table.map((it) => parseTableExpression(it));
|
|
@@ -23,7 +24,7 @@ export function parseAliasedTable(from) {
|
|
|
23
24
|
const ALIAS_SEPARATOR = ' as ';
|
|
24
25
|
if (from.includes(ALIAS_SEPARATOR)) {
|
|
25
26
|
const [table, alias] = from.split(ALIAS_SEPARATOR).map(trim);
|
|
26
|
-
return AliasNode.create(parseTable(table), alias);
|
|
27
|
+
return AliasNode.create(parseTable(table), IdentifierNode.create(alias));
|
|
27
28
|
}
|
|
28
29
|
else {
|
|
29
30
|
return parseTable(from);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ColumnUpdateNode } from '../operation-node/column-update-node.js';
|
|
2
2
|
import { UpdateKeys, UpdateType } from '../util/column-type.js';
|
|
3
3
|
import { ValueExpression } from './value-parser.js';
|
|
4
|
-
export declare type MutationObject<DB, TB extends keyof DB> = {
|
|
5
|
-
[C in UpdateKeys<DB[
|
|
4
|
+
export declare type MutationObject<DB, TB extends keyof DB, TM extends keyof DB> = {
|
|
5
|
+
[C in UpdateKeys<DB[TM]>]?: ValueExpression<DB, TB, UpdateType<DB[TM][C]>>;
|
|
6
6
|
};
|
|
7
|
-
export declare function parseUpdateObject(row: MutationObject<any, any>): ReadonlyArray<ColumnUpdateNode>;
|
|
7
|
+
export declare function parseUpdateObject(row: MutationObject<any, any, any>): ReadonlyArray<ColumnUpdateNode>;
|
|
@@ -8,14 +8,14 @@ import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
|
8
8
|
export declare type CommonTableExpression<DB, CN extends string> = (creator: QueryCreator<DB>) => CommonTableExpressionOutput<DB, CN>;
|
|
9
9
|
export declare type RecursiveCommonTableExpression<DB, CN extends string> = (creator: QueryCreator<DB & Record<ExtractTableFromCommonTableExpressionName<CN>, ExtractRowFromCommonTableExpressionName<CN>>>) => CommonTableExpressionOutput<DB, CN>;
|
|
10
10
|
export declare type QueryCreatorWithCommonTableExpression<DB, CN extends string, CTE> = QueryCreator<DB & Record<ExtractTableFromCommonTableExpressionName<CN>, ExtractRowFromCommonTableExpression<CTE>>>;
|
|
11
|
-
declare type CommonTableExpressionOutput<DB, CN extends string> = SelectQueryBuilder<DB, any, ExtractRowFromCommonTableExpressionName<CN>> | InsertQueryBuilder<DB, any, ExtractRowFromCommonTableExpressionName<CN>> | UpdateQueryBuilder<DB, any, ExtractRowFromCommonTableExpressionName<CN>> | DeleteQueryBuilder<DB, any, ExtractRowFromCommonTableExpressionName<CN>> | RawBuilder<ExtractRowFromCommonTableExpressionName<CN>>;
|
|
11
|
+
declare type CommonTableExpressionOutput<DB, CN extends string> = SelectQueryBuilder<DB, any, ExtractRowFromCommonTableExpressionName<CN>> | InsertQueryBuilder<DB, any, ExtractRowFromCommonTableExpressionName<CN>> | UpdateQueryBuilder<DB, any, any, ExtractRowFromCommonTableExpressionName<CN>> | DeleteQueryBuilder<DB, any, ExtractRowFromCommonTableExpressionName<CN>> | RawBuilder<ExtractRowFromCommonTableExpressionName<CN>>;
|
|
12
12
|
/**
|
|
13
13
|
* Given a common CommonTableExpression CTE extracts the row type from it.
|
|
14
14
|
*
|
|
15
15
|
* For example a CTE `(db) => db.selectFrom('person').select(['id', 'first_name'])`
|
|
16
16
|
* would result in `Pick<Person, 'id' | 'first_name'>`.
|
|
17
17
|
*/
|
|
18
|
-
declare type ExtractRowFromCommonTableExpression<CTE> = CTE extends (creator: QueryCreator<any>) => infer Q ? Q extends SelectQueryBuilder<any, any, infer QO> ? QO : Q extends InsertQueryBuilder<any, any, infer QO> ? QO : Q extends UpdateQueryBuilder<any, any, infer QO> ? QO : Q extends DeleteQueryBuilder<any, any, infer QO> ? QO : Q extends RawBuilder<infer RO> ? RO : never : never;
|
|
18
|
+
declare type ExtractRowFromCommonTableExpression<CTE> = CTE extends (creator: QueryCreator<any>) => infer Q ? Q extends SelectQueryBuilder<any, any, infer QO> ? QO : Q extends InsertQueryBuilder<any, any, infer QO> ? QO : Q extends UpdateQueryBuilder<any, any, any, infer QO> ? QO : Q extends DeleteQueryBuilder<any, any, infer QO> ? QO : Q extends RawBuilder<infer RO> ? RO : never : never;
|
|
19
19
|
/**
|
|
20
20
|
* Extracts 'person' from a string like 'person(id, first_name)'.
|
|
21
21
|
*/
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
export declare class NoopPlugin implements KyselyPlugin {
|
|
6
|
+
/**
|
|
7
|
+
* This is called for each query before it is executed. You can modify the query by
|
|
8
|
+
* transforming its {@link OperationNode} tree provided in {@link PluginTransformQueryArgs.node | args.node}
|
|
9
|
+
* and returning the transformed tree. You'd usually want to use an {@link OperationNodeTransformer}
|
|
10
|
+
* for this.
|
|
11
|
+
*
|
|
12
|
+
* If you need to pass some query-related data between this method and `transformResult` you
|
|
13
|
+
* can use a `WeakMap` with {@link PluginTransformQueryArgs.queryId | args.queryId} as the key:
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* const plugin = {
|
|
17
|
+
* data: new WeakMap<QueryId, SomeData>(),
|
|
18
|
+
*
|
|
19
|
+
* transformQuery(args: PluginTransformQueryArgs): RootOperationNode {
|
|
20
|
+
* this.data.set(args.queryId, something)
|
|
21
|
+
* return args.node
|
|
22
|
+
* },
|
|
23
|
+
*
|
|
24
|
+
* transformResult(args: PluginTransformResultArgs): QueryResult<UnknownRow> {
|
|
25
|
+
* const data = this.data.get(args.queryId)
|
|
26
|
+
* return args.result
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* You should use a `WeakMap` instead of a `Map` or some other strong references because `transformQuery`
|
|
32
|
+
* is not always matched by a call to `transformResult` which would leave orphaned items in the map
|
|
33
|
+
* and cause a memory leak.
|
|
34
|
+
*/
|
|
35
|
+
transformQuery(args: PluginTransformQueryArgs): RootOperationNode;
|
|
36
|
+
/**
|
|
37
|
+
* This method is called for each query after it has been executed. The result
|
|
38
|
+
* of the query can be accessed through {@link PluginTransformResultArgs.result | args.result}.
|
|
39
|
+
* You can modify the result and return the modifier result.
|
|
40
|
+
*/
|
|
41
|
+
transformResult(args: PluginTransformResultArgs): Promise<QueryResult<UnknownRow>>;
|
|
42
|
+
}
|
|
@@ -382,7 +382,7 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
|
|
|
382
382
|
* .onDuplicateKeyUpdate({ species: 'hamster' })
|
|
383
383
|
* ```
|
|
384
384
|
*/
|
|
385
|
-
onDuplicateKeyUpdate(updates: MutationObject<DB, TB>): InsertQueryBuilder<DB, TB, O>;
|
|
385
|
+
onDuplicateKeyUpdate(updates: MutationObject<DB, TB, TB>): InsertQueryBuilder<DB, TB, O>;
|
|
386
386
|
/**
|
|
387
387
|
* Allows you to return data from modified rows.
|
|
388
388
|
*
|
|
@@ -386,7 +386,7 @@ export declare class OnConflictBuilder<DB, TB extends keyof DB> implements Where
|
|
|
386
386
|
* do update set "first_name" = $3
|
|
387
387
|
* ```
|
|
388
388
|
*/
|
|
389
|
-
doUpdateSet(updates: MutationObject<OnConflictDatabase<DB, TB>, OnConflictTables<TB>>): OnConflictUpdateBuilder<OnConflictDatabase<DB, TB>, OnConflictTables<TB>>;
|
|
389
|
+
doUpdateSet(updates: MutationObject<OnConflictDatabase<DB, TB>, OnConflictTables<TB>, OnConflictTables<TB>>): OnConflictUpdateBuilder<OnConflictDatabase<DB, TB>, OnConflictTables<TB>>;
|
|
390
390
|
}
|
|
391
391
|
export interface OnConflictBuilderProps {
|
|
392
392
|
readonly onConflictNode: OnConflictNode;
|
|
@@ -1212,7 +1212,7 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
1212
1212
|
* ### Examples
|
|
1213
1213
|
*
|
|
1214
1214
|
* ```ts
|
|
1215
|
-
* await db.selectFrom('pet')
|
|
1215
|
+
* const pets = await db.selectFrom('pet')
|
|
1216
1216
|
* .selectAll('pet')
|
|
1217
1217
|
* .select(
|
|
1218
1218
|
* (qb) => qb.selectFrom('person')
|
|
@@ -1221,6 +1221,8 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
1221
1221
|
* .as('owner_first_name')
|
|
1222
1222
|
* )
|
|
1223
1223
|
* .execute()
|
|
1224
|
+
*
|
|
1225
|
+
* pets[0].owner_first_name
|
|
1224
1226
|
* ```
|
|
1225
1227
|
*/
|
|
1226
1228
|
as<A extends string>(alias: A): AliasedQueryBuilder<DB, TB, O, A>;
|
|
@@ -13,6 +13,7 @@ import { freeze } from '../util/object-utils.js';
|
|
|
13
13
|
import { parseGroupBy } from '../parser/group-by-parser.js';
|
|
14
14
|
import { parseUnion } from '../parser/union-parser.js';
|
|
15
15
|
import { NoResultError } from './no-result-error.js';
|
|
16
|
+
import { IdentifierNode } from '../operation-node/identifier-node.js';
|
|
16
17
|
export class SelectQueryBuilder {
|
|
17
18
|
#props;
|
|
18
19
|
constructor(props) {
|
|
@@ -513,7 +514,7 @@ export class SelectQueryBuilder {
|
|
|
513
514
|
* ### Examples
|
|
514
515
|
*
|
|
515
516
|
* ```ts
|
|
516
|
-
* await db.selectFrom('pet')
|
|
517
|
+
* const pets = await db.selectFrom('pet')
|
|
517
518
|
* .selectAll('pet')
|
|
518
519
|
* .select(
|
|
519
520
|
* (qb) => qb.selectFrom('person')
|
|
@@ -522,6 +523,8 @@ export class SelectQueryBuilder {
|
|
|
522
523
|
* .as('owner_first_name')
|
|
523
524
|
* )
|
|
524
525
|
* .execute()
|
|
526
|
+
*
|
|
527
|
+
* pets[0].owner_first_name
|
|
525
528
|
* ```
|
|
526
529
|
*/
|
|
527
530
|
as(alias) {
|
|
@@ -610,9 +613,6 @@ export class AliasedQueryBuilder {
|
|
|
610
613
|
}
|
|
611
614
|
toOperationNode() {
|
|
612
615
|
const node = this.#queryBuilder.toOperationNode();
|
|
613
|
-
|
|
614
|
-
return AliasNode.create(node, this.#alias);
|
|
615
|
-
}
|
|
616
|
-
throw new Error('only select queries can be aliased');
|
|
616
|
+
return AliasNode.create(node, IdentifierNode.create(this.#alias));
|
|
617
617
|
}
|
|
618
618
|
}
|
|
@@ -19,7 +19,7 @@ import { JoinInterface } from './join-interface.js';
|
|
|
19
19
|
import { ReturningInterface } from './returning-interface.js';
|
|
20
20
|
import { NoResultErrorConstructor } from './no-result-error.js';
|
|
21
21
|
import { Selectable } from '../util/column-type.js';
|
|
22
|
-
export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements WhereInterface<DB, TB>, JoinInterface<DB, TB>, ReturningInterface<DB, TB, O>, OperationNodeSource, Compilable {
|
|
22
|
+
export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyof DB, O> implements WhereInterface<DB, TB>, JoinInterface<DB, TB>, ReturningInterface<DB, TB, O>, OperationNodeSource, Compilable {
|
|
23
23
|
#private;
|
|
24
24
|
constructor(props: UpdateQueryBuilderProps);
|
|
25
25
|
/**
|
|
@@ -206,9 +206,9 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
206
206
|
* .execute()
|
|
207
207
|
* ```
|
|
208
208
|
*/
|
|
209
|
-
where<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): UpdateQueryBuilder<DB, TB, O>;
|
|
210
|
-
where(grouper: WhereGrouper<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
|
|
211
|
-
where(raw: AnyRawBuilder): UpdateQueryBuilder<DB, TB, O>;
|
|
209
|
+
where<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
210
|
+
where(grouper: WhereGrouper<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
211
|
+
where(raw: AnyRawBuilder): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
212
212
|
/**
|
|
213
213
|
* Adds a `where` clause where both sides of the operator are references
|
|
214
214
|
* to columns.
|
|
@@ -260,7 +260,7 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
260
260
|
* ) as "pet_name"
|
|
261
261
|
* from "person"
|
|
262
262
|
*/
|
|
263
|
-
whereRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
|
|
263
|
+
whereRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
264
264
|
/**
|
|
265
265
|
* Adds an `or where` clause to the query. Otherwise works just like {@link where}.
|
|
266
266
|
*
|
|
@@ -324,15 +324,15 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
324
324
|
* select * from "person" (where "id" = 1 or "id" = 2)
|
|
325
325
|
* ```
|
|
326
326
|
*/
|
|
327
|
-
orWhere<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): UpdateQueryBuilder<DB, TB, O>;
|
|
328
|
-
orWhere(grouper: WhereGrouper<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
|
|
329
|
-
orWhere(raw: AnyRawBuilder): UpdateQueryBuilder<DB, TB, O>;
|
|
327
|
+
orWhere<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
328
|
+
orWhere(grouper: WhereGrouper<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
329
|
+
orWhere(raw: AnyRawBuilder): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
330
330
|
/**
|
|
331
331
|
* Adds an `or where` clause to the query. Otherwise works just like {@link whereRef}.
|
|
332
332
|
*
|
|
333
333
|
* Also see {@link orWhere} and {@link where}.
|
|
334
334
|
*/
|
|
335
|
-
orWhereRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
|
|
335
|
+
orWhereRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
336
336
|
/**
|
|
337
337
|
* Adds a `where exists` clause to the query.
|
|
338
338
|
*
|
|
@@ -393,19 +393,48 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
393
393
|
* )
|
|
394
394
|
* ```
|
|
395
395
|
*/
|
|
396
|
-
whereExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
|
|
396
|
+
whereExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
397
397
|
/**
|
|
398
398
|
* Just like {@link whereExists} but creates a `not exists` clause.
|
|
399
399
|
*/
|
|
400
|
-
whereNotExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
|
|
400
|
+
whereNotExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
401
401
|
/**
|
|
402
402
|
* Just like {@link whereExists} but creates a `or exists` clause.
|
|
403
403
|
*/
|
|
404
|
-
orWhereExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
|
|
404
|
+
orWhereExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
405
405
|
/**
|
|
406
406
|
* Just like {@link whereExists} but creates a `or not exists` clause.
|
|
407
407
|
*/
|
|
408
|
-
orWhereNotExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
|
|
408
|
+
orWhereNotExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
409
|
+
/**
|
|
410
|
+
* Adds a from clause to the update query.
|
|
411
|
+
*
|
|
412
|
+
* This is supported only on some databases like PostgreSQL.
|
|
413
|
+
*
|
|
414
|
+
* The API is the same as {@link QueryCreator.selectFrom}.
|
|
415
|
+
*
|
|
416
|
+
* ### Examples
|
|
417
|
+
*
|
|
418
|
+
* ```ts
|
|
419
|
+
* db.updateTable('person')
|
|
420
|
+
* .from('pet')
|
|
421
|
+
* .set({
|
|
422
|
+
* first_name: (eb) => eb.ref('pet.name')
|
|
423
|
+
* })
|
|
424
|
+
* .whereRef('pet.owner_id', '=', 'person.id')
|
|
425
|
+
* ```
|
|
426
|
+
*
|
|
427
|
+
* The generated SQL (PostgreSQL):
|
|
428
|
+
*
|
|
429
|
+
* ```sql
|
|
430
|
+
* update "person"
|
|
431
|
+
* set "first_name" = "pet"."name"
|
|
432
|
+
* from "pet"
|
|
433
|
+
* where "pet"."owner_id" = "person"."id"
|
|
434
|
+
* ```
|
|
435
|
+
*/
|
|
436
|
+
from<TE extends TableExpression<DB, TB>>(table: TE): UpdateQueryBuilder<TableExpressionDatabase<DB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
|
|
437
|
+
from<TE extends TableExpression<DB, TB>>(table: TE[]): UpdateQueryBuilder<TableExpressionDatabase<DB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
|
|
409
438
|
/**
|
|
410
439
|
* Joins another table to the query using an inner join.
|
|
411
440
|
*
|
|
@@ -515,23 +544,23 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
515
544
|
* on "doggos"."owner_id" = "person"."id"
|
|
516
545
|
* ```
|
|
517
546
|
*/
|
|
518
|
-
innerJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<TableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
519
|
-
innerJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<TableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
547
|
+
innerJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<TableExpressionDatabase<DB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
|
|
548
|
+
innerJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<TableExpressionDatabase<DB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
|
|
520
549
|
/**
|
|
521
550
|
* Just like {@link innerJoin} but adds a left join nstead of an inner join.
|
|
522
551
|
*/
|
|
523
|
-
leftJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<LeftJoinTableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
524
|
-
leftJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<LeftJoinTableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
552
|
+
leftJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<LeftJoinTableExpressionDatabase<DB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
|
|
553
|
+
leftJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<LeftJoinTableExpressionDatabase<DB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
|
|
525
554
|
/**
|
|
526
555
|
* Just like {@link innerJoin} but adds a right join instead of an inner join.
|
|
527
556
|
*/
|
|
528
|
-
rightJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<RightJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
529
|
-
rightJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<RightJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
557
|
+
rightJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<RightJoinTableExpressionDatabase<DB, TB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
|
|
558
|
+
rightJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<RightJoinTableExpressionDatabase<DB, TB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
|
|
530
559
|
/**
|
|
531
560
|
* Just like {@link innerJoin} but adds a full join instead of an inner join.
|
|
532
561
|
*/
|
|
533
|
-
fullJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<FullJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
534
|
-
fullJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<FullJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
562
|
+
fullJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<FullJoinTableExpressionDatabase<DB, TB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
|
|
563
|
+
fullJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<FullJoinTableExpressionDatabase<DB, TB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
|
|
535
564
|
/**
|
|
536
565
|
* Sets the values to update for an {@link Kysely.updateTable | update} query.
|
|
537
566
|
*
|
|
@@ -619,7 +648,7 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
619
648
|
* where "id" = $4
|
|
620
649
|
* ```
|
|
621
650
|
*/
|
|
622
|
-
set(row: MutationObject<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
|
|
651
|
+
set(row: MutationObject<DB, TB, UT>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
623
652
|
/**
|
|
624
653
|
* Allows you to return data from modified rows.
|
|
625
654
|
*
|
|
@@ -679,13 +708,13 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
679
708
|
* .executeTakeFirst()
|
|
680
709
|
* ```
|
|
681
710
|
*/
|
|
682
|
-
returning<SE extends SelectExpression<DB, TB>>(selections: ReadonlyArray<SE>): UpdateQueryBuilder<DB, TB, ReturningRow<DB, TB, O, SE>>;
|
|
683
|
-
returning<SE extends SelectExpression<DB, TB>>(selection: SE): UpdateQueryBuilder<DB, TB, ReturningRow<DB, TB, O, SE>>;
|
|
711
|
+
returning<SE extends SelectExpression<DB, TB>>(selections: ReadonlyArray<SE>): UpdateQueryBuilder<DB, UT, TB, ReturningRow<DB, TB, O, SE>>;
|
|
712
|
+
returning<SE extends SelectExpression<DB, TB>>(selection: SE): UpdateQueryBuilder<DB, UT, TB, ReturningRow<DB, TB, O, SE>>;
|
|
684
713
|
/**
|
|
685
714
|
* Adds a `returning *` to an insert/update/delete query on databases
|
|
686
715
|
* that support `returning` such as PostgreSQL.
|
|
687
716
|
*/
|
|
688
|
-
returningAll(): UpdateQueryBuilder<DB, TB, Selectable<DB[TB]>>;
|
|
717
|
+
returningAll(): UpdateQueryBuilder<DB, UT, TB, Selectable<DB[TB]>>;
|
|
689
718
|
/**
|
|
690
719
|
* Simply calls the given function passing `this` as the only argument.
|
|
691
720
|
*
|
|
@@ -745,18 +774,18 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
745
774
|
* }
|
|
746
775
|
* ```
|
|
747
776
|
*/
|
|
748
|
-
if<O2>(condition: boolean, func: (qb: this) => UpdateQueryBuilder<DB, TB, O2>): UpdateQueryBuilder<DB, TB, O2 extends UpdateResult ? UpdateResult : O extends UpdateResult ? Partial<O2> : MergePartial<O, O2>>;
|
|
777
|
+
if<O2>(condition: boolean, func: (qb: this) => UpdateQueryBuilder<DB, UT, TB, O2>): UpdateQueryBuilder<DB, UT, TB, O2 extends UpdateResult ? UpdateResult : O extends UpdateResult ? Partial<O2> : MergePartial<O, O2>>;
|
|
749
778
|
/**
|
|
750
779
|
* Change the output type of the query.
|
|
751
780
|
*
|
|
752
781
|
* You should only use this method as the last resort if the types
|
|
753
782
|
* don't support your use case.
|
|
754
783
|
*/
|
|
755
|
-
castTo<T>(): UpdateQueryBuilder<DB, TB, T>;
|
|
784
|
+
castTo<T>(): UpdateQueryBuilder<DB, UT, TB, T>;
|
|
756
785
|
/**
|
|
757
786
|
* Returns a copy of this UpdateQueryBuilder instance with the given plugin installed.
|
|
758
787
|
*/
|
|
759
|
-
withPlugin(plugin: KyselyPlugin): UpdateQueryBuilder<DB, TB, O>;
|
|
788
|
+
withPlugin(plugin: KyselyPlugin): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
760
789
|
toOperationNode(): UpdateQueryNode;
|
|
761
790
|
compile(): CompiledQuery;
|
|
762
791
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="./update-query-builder.d.ts" />
|
|
2
2
|
import { parseJoin, } from '../parser/join-parser.js';
|
|
3
|
+
import { parseTableExpressionOrList, } from '../parser/table-parser.js';
|
|
3
4
|
import { parseSelectExpressionOrList, parseSelectAll, } from '../parser/select-parser.js';
|
|
4
5
|
import { parseExistFilter, parseReferenceFilter, parseWhereFilter, parseNotExistFilter, } from '../parser/filter-parser.js';
|
|
5
6
|
import { QueryNode } from '../operation-node/query-node.js';
|
|
@@ -62,6 +63,12 @@ export class UpdateQueryBuilder {
|
|
|
62
63
|
queryNode: QueryNode.cloneWithOrWhere(this.#props.queryNode, parseNotExistFilter(arg)),
|
|
63
64
|
});
|
|
64
65
|
}
|
|
66
|
+
from(from) {
|
|
67
|
+
return new UpdateQueryBuilder({
|
|
68
|
+
...this.#props,
|
|
69
|
+
queryNode: UpdateQueryNode.cloneWithFromItems(this.#props.queryNode, parseTableExpressionOrList(from)),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
65
72
|
innerJoin(...args) {
|
|
66
73
|
return new UpdateQueryBuilder({
|
|
67
74
|
...this.#props,
|
|
@@ -425,6 +425,10 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
|
|
|
425
425
|
if (node.updates) {
|
|
426
426
|
this.compileList(node.updates);
|
|
427
427
|
}
|
|
428
|
+
if (node.from) {
|
|
429
|
+
this.append(' ');
|
|
430
|
+
this.visitNode(node.from);
|
|
431
|
+
}
|
|
428
432
|
if (node.joins) {
|
|
429
433
|
this.append(' ');
|
|
430
434
|
this.compileList(node.joins, ' ');
|
|
@@ -9,6 +9,7 @@ import { WithNode } from './operation-node/with-node.js';
|
|
|
9
9
|
import { InsertResult } from './query-builder/insert-result.js';
|
|
10
10
|
import { DeleteResult } from './query-builder/delete-result.js';
|
|
11
11
|
import { UpdateResult } from './query-builder/update-result.js';
|
|
12
|
+
import { KyselyPlugin } from './plugin/kysely-plugin.js';
|
|
12
13
|
export declare class QueryCreator<DB> {
|
|
13
14
|
#private;
|
|
14
15
|
constructor(props: QueryCreatorProps);
|
|
@@ -203,7 +204,7 @@ export declare class QueryCreator<DB> {
|
|
|
203
204
|
* console.log(result.numUpdatedRows)
|
|
204
205
|
* ```
|
|
205
206
|
*/
|
|
206
|
-
updateTable<TR extends TableReference<DB>>(table: TR): UpdateQueryBuilder<TableExpressionDatabase<DB, TR>, TableExpressionTables<DB, never, TR>, UpdateResult>;
|
|
207
|
+
updateTable<TR extends TableReference<DB>>(table: TR): UpdateQueryBuilder<TableExpressionDatabase<DB, TR>, TableExpressionTables<DB, never, TR>, TableExpressionTables<DB, never, TR>, UpdateResult>;
|
|
207
208
|
/**
|
|
208
209
|
* Creates a `with` query (Common Table Expression).
|
|
209
210
|
*
|
|
@@ -252,6 +253,14 @@ export declare class QueryCreator<DB> {
|
|
|
252
253
|
* See the {@link with} method for examples and more documentation.
|
|
253
254
|
*/
|
|
254
255
|
withRecursive<N extends string, E extends RecursiveCommonTableExpression<DB, N>>(name: N, expression: E): QueryCreatorWithCommonTableExpression<DB, N, E>;
|
|
256
|
+
/**
|
|
257
|
+
* Returns a copy of this query creator instance with the given plugin installed.
|
|
258
|
+
*/
|
|
259
|
+
withPlugin(plugin: KyselyPlugin): QueryCreator<DB>;
|
|
260
|
+
/**
|
|
261
|
+
* Returns a copy of this query creator instance without any plugins.
|
|
262
|
+
*/
|
|
263
|
+
withoutPlugins(): QueryCreator<DB>;
|
|
255
264
|
/**
|
|
256
265
|
* Sets the schema to be used for all table references that don't explicitly
|
|
257
266
|
* specify a schema.
|
|
@@ -190,6 +190,24 @@ export class QueryCreator {
|
|
|
190
190
|
: WithNode.create(cte, { recursive: true }),
|
|
191
191
|
});
|
|
192
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Returns a copy of this query creator instance with the given plugin installed.
|
|
195
|
+
*/
|
|
196
|
+
withPlugin(plugin) {
|
|
197
|
+
return new QueryCreator({
|
|
198
|
+
...this.#props,
|
|
199
|
+
executor: this.#props.executor.withPlugin(plugin),
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Returns a copy of this query creator instance without any plugins.
|
|
204
|
+
*/
|
|
205
|
+
withoutPlugins() {
|
|
206
|
+
return new QueryCreator({
|
|
207
|
+
...this.#props,
|
|
208
|
+
executor: this.#props.executor.withoutPlugins(),
|
|
209
|
+
});
|
|
210
|
+
}
|
|
193
211
|
/**
|
|
194
212
|
* Sets the schema to be used for all table references that don't explicitly
|
|
195
213
|
* specify a schema.
|
|
@@ -5,6 +5,7 @@ import { RawNode } from '../operation-node/raw-node.js';
|
|
|
5
5
|
import { KyselyPlugin } from '../plugin/kysely-plugin.js';
|
|
6
6
|
import { QueryExecutorProvider } from '../query-executor/query-executor-provider.js';
|
|
7
7
|
import { QueryId } from '../util/query-id.js';
|
|
8
|
+
import { AnyRawBuilder } from '../util/type-utils.js';
|
|
8
9
|
/**
|
|
9
10
|
* An instance of this class can be used to create raw SQL snippets or queries.
|
|
10
11
|
*
|
|
@@ -38,8 +39,37 @@ export declare class RawBuilder<O = unknown> implements OperationNodeSource {
|
|
|
38
39
|
* select concat(first_name, ' ', last_name) as "full_name"
|
|
39
40
|
* from "person"
|
|
40
41
|
* ```
|
|
42
|
+
*
|
|
43
|
+
* You can also pass in a raw SQL snippet but in that case you must
|
|
44
|
+
* provide the alias as the only type argument:
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* const values = sql<{ a: number, b: string }>`(values (1, 'foo'))`
|
|
48
|
+
*
|
|
49
|
+
* // The alias is `t(a, b)` which specifies the column names
|
|
50
|
+
* // in addition to the table name. We must tell kysely that
|
|
51
|
+
* // columns of the table can be referenced through `t`
|
|
52
|
+
* // by providing an explicit type argument.
|
|
53
|
+
* const aliasedValues = values.as<'t'>(sql`t(a, b)`)
|
|
54
|
+
*
|
|
55
|
+
* await db
|
|
56
|
+
* .insertInto('person')
|
|
57
|
+
* .columns(['first_name', 'last_name'])
|
|
58
|
+
* .expression(
|
|
59
|
+
* db.selectFrom(aliasedValues).select(['t.a', 't.b'])
|
|
60
|
+
* )
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* The generated SQL (PostgreSQL):
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* insert into "person" ("first_name", "last_name")
|
|
67
|
+
* from (values (1, 'foo')) as t(a, b)
|
|
68
|
+
* select "t"."a", "t"."b"
|
|
69
|
+
* ```
|
|
41
70
|
*/
|
|
42
71
|
as<A extends string>(alias: A): AliasedRawBuilder<O, A>;
|
|
72
|
+
as<A extends string = never>(alias: AnyRawBuilder): AliasedRawBuilder<O, A>;
|
|
43
73
|
/**
|
|
44
74
|
* Change the output type of the raw expression.
|
|
45
75
|
*
|
|
@@ -67,9 +97,9 @@ export declare class AliasedRawBuilder<O = unknown, A extends string = never> im
|
|
|
67
97
|
* which causes this type to be equal to AliasedRawBuilder with any A
|
|
68
98
|
* as long as O is the same.
|
|
69
99
|
*/
|
|
70
|
-
protected get alias(): A;
|
|
100
|
+
protected get alias(): A | AnyRawBuilder;
|
|
71
101
|
toOperationNode(): AliasNode;
|
|
72
|
-
constructor(rawBuilder: RawBuilder<O>, alias: A);
|
|
102
|
+
constructor(rawBuilder: RawBuilder<O>, alias: A | AnyRawBuilder);
|
|
73
103
|
}
|
|
74
104
|
export interface RawBuilderProps {
|
|
75
105
|
readonly queryId: QueryId;
|