kysely 0.23.4 → 0.23.5
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 +3 -1
- package/dist/cjs/dialect/database-introspector.d.ts +4 -2
- package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-introspector.js +19 -13
- package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +1 -1
- package/dist/cjs/dialect/postgres/postgres-introspector.js +3 -1
- package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +6 -5
- package/dist/cjs/operation-node/aggregate-function-node.d.ts +3 -2
- package/dist/cjs/operation-node/aggregate-function-node.js +2 -2
- package/dist/cjs/operation-node/delete-query-node.d.ts +1 -1
- package/dist/cjs/operation-node/delete-query-node.js +2 -2
- package/dist/cjs/operation-node/operation-node-transformer.js +2 -2
- package/dist/cjs/parser/expression-parser.js +1 -1
- package/dist/cjs/parser/table-parser.d.ts +1 -0
- package/dist/cjs/plugin/camel-case/camel-case-plugin.d.ts +7 -0
- package/dist/cjs/plugin/camel-case/camel-case-plugin.js +10 -4
- package/dist/cjs/query-builder/delete-query-builder.d.ts +5 -5
- package/dist/cjs/query-builder/delete-query-builder.js +1 -1
- package/dist/cjs/query-builder/function-module.d.ts +273 -39
- package/dist/cjs/query-builder/function-module.js +156 -34
- package/dist/cjs/query-builder/insert-query-builder.d.ts +4 -5
- package/dist/cjs/query-builder/insert-query-builder.js +0 -1
- package/dist/cjs/query-builder/select-query-builder.d.ts +8 -7
- package/dist/cjs/query-builder/update-query-builder.d.ts +5 -5
- package/dist/cjs/query-builder/update-query-builder.js +1 -1
- package/dist/cjs/query-compiler/default-query-compiler.js +1 -1
- package/dist/cjs/query-creator.d.ts +29 -0
- package/dist/cjs/query-creator.js +2 -21
- package/dist/cjs/util/type-utils.d.ts +5 -4
- package/dist/esm/dialect/database-introspector.d.ts +4 -2
- package/dist/esm/dialect/mysql/mysql-introspector.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-introspector.js +19 -13
- package/dist/esm/dialect/postgres/postgres-introspector.d.ts +1 -1
- package/dist/esm/dialect/postgres/postgres-introspector.js +3 -1
- package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +1 -1
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +6 -5
- package/dist/esm/operation-node/aggregate-function-node.d.ts +3 -2
- package/dist/esm/operation-node/aggregate-function-node.js +2 -2
- package/dist/esm/operation-node/delete-query-node.d.ts +1 -1
- package/dist/esm/operation-node/delete-query-node.js +2 -2
- package/dist/esm/operation-node/operation-node-transformer.js +2 -2
- package/dist/esm/parser/expression-parser.js +2 -2
- package/dist/esm/parser/table-parser.d.ts +1 -0
- package/dist/esm/plugin/camel-case/camel-case-plugin.d.ts +7 -0
- package/dist/esm/plugin/camel-case/camel-case-plugin.js +10 -4
- package/dist/esm/query-builder/delete-query-builder.d.ts +5 -5
- package/dist/esm/query-builder/delete-query-builder.js +1 -1
- package/dist/esm/query-builder/function-module.d.ts +273 -39
- package/dist/esm/query-builder/function-module.js +156 -34
- package/dist/esm/query-builder/insert-query-builder.d.ts +4 -5
- package/dist/esm/query-builder/insert-query-builder.js +0 -1
- package/dist/esm/query-builder/select-query-builder.d.ts +8 -7
- package/dist/esm/query-builder/update-query-builder.d.ts +5 -5
- package/dist/esm/query-builder/update-query-builder.js +1 -1
- package/dist/esm/query-compiler/default-query-compiler.js +1 -1
- package/dist/esm/query-creator.d.ts +29 -0
- package/dist/esm/query-creator.js +2 -21
- package/dist/esm/util/type-utils.d.ts +5 -4
- package/package.json +1 -1
|
@@ -32,6 +32,7 @@ export class PostgresIntrospector {
|
|
|
32
32
|
'a.attnotnull as not_null',
|
|
33
33
|
'a.atthasdef as has_default',
|
|
34
34
|
'c.relname as table',
|
|
35
|
+
'c.relkind as table_type',
|
|
35
36
|
'ns.nspname as schema',
|
|
36
37
|
'typ.typname as type',
|
|
37
38
|
'dtns.nspname as type_schema',
|
|
@@ -47,7 +48,7 @@ export class PostgresIntrospector {
|
|
|
47
48
|
.as('auto_incrementing'),
|
|
48
49
|
])
|
|
49
50
|
// r == normal table
|
|
50
|
-
.where('c.relkind', '
|
|
51
|
+
.where('c.relkind', 'in', ['r', 'v'])
|
|
51
52
|
.where('ns.nspname', '!~', '^pg_')
|
|
52
53
|
.where('ns.nspname', '!=', 'information_schema')
|
|
53
54
|
// No system columns
|
|
@@ -76,6 +77,7 @@ export class PostgresIntrospector {
|
|
|
76
77
|
if (!table) {
|
|
77
78
|
table = freeze({
|
|
78
79
|
name: it.table,
|
|
80
|
+
isView: it.table_type === 'v',
|
|
79
81
|
schema: it.schema,
|
|
80
82
|
columns: [],
|
|
81
83
|
});
|
|
@@ -8,7 +8,7 @@ export declare class SqliteIntrospector implements DatabaseIntrospector {
|
|
|
8
8
|
*/
|
|
9
9
|
getSchemas(): Promise<SchemaMetadata[]>;
|
|
10
10
|
/**
|
|
11
|
-
* Get
|
|
11
|
+
* Get tables and views metadata.
|
|
12
12
|
*/
|
|
13
13
|
getTables(options?: DatabaseMetadataOptions): Promise<TableMetadata[]>;
|
|
14
14
|
/**
|
|
@@ -13,7 +13,7 @@ export class SqliteIntrospector {
|
|
|
13
13
|
async getTables(options = { withInternalKyselyTables: false }) {
|
|
14
14
|
let query = this.#db
|
|
15
15
|
.selectFrom('sqlite_schema')
|
|
16
|
-
.where('type', '
|
|
16
|
+
.where('type', 'in', ['table', 'view'])
|
|
17
17
|
.where('name', 'not like', 'sqlite_%')
|
|
18
18
|
.select('name')
|
|
19
19
|
.orderBy('name')
|
|
@@ -34,14 +34,14 @@ export class SqliteIntrospector {
|
|
|
34
34
|
async #getTableMetadata(table) {
|
|
35
35
|
const db = this.#db;
|
|
36
36
|
// Get the SQL that was used to create the table.
|
|
37
|
-
const
|
|
37
|
+
const tableDefinition = await db
|
|
38
38
|
.selectFrom('sqlite_master')
|
|
39
39
|
.where('name', '=', table)
|
|
40
|
-
.select('sql')
|
|
40
|
+
.select(['sql', 'type'])
|
|
41
41
|
.$castTo()
|
|
42
|
-
.
|
|
42
|
+
.executeTakeFirstOrThrow();
|
|
43
43
|
// Try to find the name of the column that has `autoincrement` 🤦
|
|
44
|
-
const autoIncrementCol =
|
|
44
|
+
const autoIncrementCol = tableDefinition.sql
|
|
45
45
|
?.split(/[\(\),]/)
|
|
46
46
|
?.find((it) => it.toLowerCase().includes('autoincrement'))
|
|
47
47
|
?.trimStart()
|
|
@@ -54,6 +54,7 @@ export class SqliteIntrospector {
|
|
|
54
54
|
.execute();
|
|
55
55
|
return {
|
|
56
56
|
name: table,
|
|
57
|
+
isView: tableDefinition.type === 'view',
|
|
57
58
|
columns: columns.map((col) => ({
|
|
58
59
|
name: col.name,
|
|
59
60
|
dataType: col.type,
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { OperationNode } from './operation-node.js';
|
|
2
2
|
import { OverNode } from './over-node.js';
|
|
3
|
+
import { SelectAllNode } from './select-all-node.js';
|
|
3
4
|
import { SimpleReferenceExpressionNode } from './simple-reference-expression-node.js';
|
|
4
5
|
import { WhereNode } from './where-node.js';
|
|
5
6
|
declare type AggregateFunction = 'avg' | 'count' | 'max' | 'min' | 'sum';
|
|
6
7
|
export interface AggregateFunctionNode extends OperationNode {
|
|
7
8
|
readonly kind: 'AggregateFunctionNode';
|
|
8
9
|
readonly func: AggregateFunction;
|
|
9
|
-
readonly
|
|
10
|
+
readonly aggregated: SimpleReferenceExpressionNode | SelectAllNode;
|
|
10
11
|
readonly distinct?: boolean;
|
|
11
12
|
readonly filter?: WhereNode;
|
|
12
13
|
readonly over?: OverNode;
|
|
@@ -16,7 +17,7 @@ export interface AggregateFunctionNode extends OperationNode {
|
|
|
16
17
|
*/
|
|
17
18
|
export declare const AggregateFunctionNode: Readonly<{
|
|
18
19
|
is(node: OperationNode): node is AggregateFunctionNode;
|
|
19
|
-
create(aggregateFunction: AggregateFunction,
|
|
20
|
+
create(aggregateFunction: AggregateFunction, aggregated: SimpleReferenceExpressionNode | SelectAllNode): AggregateFunctionNode;
|
|
20
21
|
cloneWithDistinct(aggregateFunctionNode: AggregateFunctionNode): AggregateFunctionNode;
|
|
21
22
|
cloneWithFilter(aggregateFunctionNode: AggregateFunctionNode, filter: OperationNode): AggregateFunctionNode;
|
|
22
23
|
cloneWithOrFilter(aggregateFunctionNode: AggregateFunctionNode, filter: OperationNode): AggregateFunctionNode;
|
|
@@ -8,11 +8,11 @@ export const AggregateFunctionNode = freeze({
|
|
|
8
8
|
is(node) {
|
|
9
9
|
return node.kind === 'AggregateFunctionNode';
|
|
10
10
|
},
|
|
11
|
-
create(aggregateFunction,
|
|
11
|
+
create(aggregateFunction, aggregated) {
|
|
12
12
|
return freeze({
|
|
13
13
|
kind: 'AggregateFunctionNode',
|
|
14
14
|
func: aggregateFunction,
|
|
15
|
-
|
|
15
|
+
aggregated,
|
|
16
16
|
});
|
|
17
17
|
},
|
|
18
18
|
cloneWithDistinct(aggregateFunctionNode) {
|
|
@@ -26,7 +26,7 @@ export interface DeleteQueryNode extends OperationNode {
|
|
|
26
26
|
*/
|
|
27
27
|
export declare const DeleteQueryNode: Readonly<{
|
|
28
28
|
is(node: OperationNode): node is DeleteQueryNode;
|
|
29
|
-
create(
|
|
29
|
+
create(fromItems: OperationNode[], withNode?: WithNode): DeleteQueryNode;
|
|
30
30
|
cloneWithOrderByItem(deleteNode: DeleteQueryNode, item: OrderByItemNode): DeleteQueryNode;
|
|
31
31
|
cloneWithLimit(deleteNode: DeleteQueryNode, limit: LimitNode): DeleteQueryNode;
|
|
32
32
|
cloneWithExplain(deleteNode: DeleteQueryNode, explain: ExplainNode): DeleteQueryNode;
|
|
@@ -10,10 +10,10 @@ export const DeleteQueryNode = freeze({
|
|
|
10
10
|
is(node) {
|
|
11
11
|
return node.kind === 'DeleteQueryNode';
|
|
12
12
|
},
|
|
13
|
-
create(
|
|
13
|
+
create(fromItems, withNode) {
|
|
14
14
|
return freeze({
|
|
15
15
|
kind: 'DeleteQueryNode',
|
|
16
|
-
from: FromNode.create(
|
|
16
|
+
from: FromNode.create(fromItems),
|
|
17
17
|
...(withNode && { with: withNode }),
|
|
18
18
|
});
|
|
19
19
|
},
|
|
@@ -649,7 +649,7 @@ export class OperationNodeTransformer {
|
|
|
649
649
|
transformAggregateFunction(node) {
|
|
650
650
|
return requireAllProps({
|
|
651
651
|
kind: 'AggregateFunctionNode',
|
|
652
|
-
|
|
652
|
+
aggregated: this.transformNode(node.aggregated),
|
|
653
653
|
distinct: node.distinct,
|
|
654
654
|
filter: this.transformNode(node.filter),
|
|
655
655
|
func: node.func,
|
|
@@ -693,7 +693,7 @@ export class OperationNodeTransformer {
|
|
|
693
693
|
transformUsing(node) {
|
|
694
694
|
return requireAllProps({
|
|
695
695
|
kind: 'UsingNode',
|
|
696
|
-
tables: node.tables,
|
|
696
|
+
tables: this.transformNodeList(node.tables),
|
|
697
697
|
});
|
|
698
698
|
}
|
|
699
699
|
transformDataType(node) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="./expression-parser.d.ts" />
|
|
2
|
-
import { isExpression, } from '../expression/expression.js';
|
|
2
|
+
import { isAliasedExpression, isExpression, } from '../expression/expression.js';
|
|
3
3
|
import { isOperationNodeSource } from '../operation-node/operation-node-source.js';
|
|
4
4
|
import { isFunction } from '../util/object-utils.js';
|
|
5
5
|
import { createExpressionBuilder } from './parse-utils.js';
|
|
@@ -22,5 +22,5 @@ export function parseAliasedExpression(exp) {
|
|
|
22
22
|
throw new Error(`invalid aliased expression: ${JSON.stringify(exp)}`);
|
|
23
23
|
}
|
|
24
24
|
export function isExpressionOrFactory(obj) {
|
|
25
|
-
return isExpression(obj) || isFunction(obj);
|
|
25
|
+
return isExpression(obj) || isAliasedExpression(obj) || isFunction(obj);
|
|
26
26
|
}
|
|
@@ -6,6 +6,7 @@ import { AliasedExpression } from '../expression/expression.js';
|
|
|
6
6
|
export declare type TableExpression<DB, TB extends keyof DB> = TableReference<DB> | AliasedExpressionOrFactory<DB, TB>;
|
|
7
7
|
export declare type TableExpressionOrList<DB, TB extends keyof DB> = TableExpression<DB, TB> | ReadonlyArray<TableExpression<DB, TB>>;
|
|
8
8
|
export declare type TableReference<DB> = AnyAliasedTable<DB> | AnyTable<DB> | AliasedExpression<any, any>;
|
|
9
|
+
export declare type TableReferenceOrList<DB> = TableReference<DB> | ReadonlyArray<TableReference<DB>>;
|
|
9
10
|
export declare type From<DB, TE> = {
|
|
10
11
|
[C in keyof DB | ExtractAliasFromTableExpression<DB, TE>]: C extends ExtractAliasFromTableExpression<DB, TE> ? ExtractRowTypeFromTableExpression<DB, TE, C> : C extends keyof DB ? DB[C] : never;
|
|
11
12
|
};
|
|
@@ -26,6 +26,12 @@ export interface CamelCasePluginOptions {
|
|
|
26
26
|
* Defaults to false.
|
|
27
27
|
*/
|
|
28
28
|
underscoreBetweenUppercaseLetters?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* If true, nested object's keys will not be converted to camel case.
|
|
31
|
+
*
|
|
32
|
+
* Defaults to false.
|
|
33
|
+
*/
|
|
34
|
+
maintainNestedObjectKeys?: boolean;
|
|
29
35
|
}
|
|
30
36
|
/**
|
|
31
37
|
* A plugin that converts snake_case identifiers in the database into
|
|
@@ -93,6 +99,7 @@ export interface CamelCasePluginOptions {
|
|
|
93
99
|
*/
|
|
94
100
|
export declare class CamelCasePlugin implements KyselyPlugin {
|
|
95
101
|
#private;
|
|
102
|
+
readonly opt: CamelCasePluginOptions;
|
|
96
103
|
constructor(opt?: CamelCasePluginOptions);
|
|
97
104
|
/**
|
|
98
105
|
* This is called for each query before it is executed. You can modify the query by
|
|
@@ -67,10 +67,12 @@ import { createCamelCaseMapper, createSnakeCaseMapper, } from './camel-case.js';
|
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
69
|
export class CamelCasePlugin {
|
|
70
|
+
opt;
|
|
70
71
|
#camelCase;
|
|
71
72
|
#snakeCase;
|
|
72
73
|
#snakeCaseTransformer;
|
|
73
74
|
constructor(opt = {}) {
|
|
75
|
+
this.opt = opt;
|
|
74
76
|
this.#camelCase = createCamelCaseMapper(opt);
|
|
75
77
|
this.#snakeCase = createSnakeCaseMapper(opt);
|
|
76
78
|
this.#snakeCaseTransformer = new SnakeCaseTransformer(this.snakeCase.bind(this));
|
|
@@ -91,9 +93,9 @@ export class CamelCasePlugin {
|
|
|
91
93
|
return Object.keys(row).reduce((obj, key) => {
|
|
92
94
|
let value = row[key];
|
|
93
95
|
if (Array.isArray(value)) {
|
|
94
|
-
value = value.map((it) => (canMap(it) ? this.mapRow(it) : it));
|
|
96
|
+
value = value.map((it) => (canMap(it, this.opt) ? this.mapRow(it) : it));
|
|
95
97
|
}
|
|
96
|
-
else if (canMap(value)) {
|
|
98
|
+
else if (canMap(value, this.opt)) {
|
|
97
99
|
value = this.mapRow(value);
|
|
98
100
|
}
|
|
99
101
|
obj[this.camelCase(key)] = value;
|
|
@@ -107,6 +109,10 @@ export class CamelCasePlugin {
|
|
|
107
109
|
return this.#camelCase(str);
|
|
108
110
|
}
|
|
109
111
|
}
|
|
110
|
-
function canMap(obj) {
|
|
111
|
-
return (isObject(obj) &&
|
|
112
|
+
function canMap(obj, opt) {
|
|
113
|
+
return (isObject(obj) &&
|
|
114
|
+
!isDate(obj) &&
|
|
115
|
+
!isBuffer(obj) &&
|
|
116
|
+
!isArrayBufferOrView(obj) &&
|
|
117
|
+
!opt?.maintainNestedObjectKeys);
|
|
112
118
|
}
|
|
@@ -5,7 +5,7 @@ import { From, FromTables, TableExpression } from '../parser/table-parser.js';
|
|
|
5
5
|
import { SelectExpression } from '../parser/select-parser.js';
|
|
6
6
|
import { ReturningRow } from '../parser/returning-parser.js';
|
|
7
7
|
import { ReferenceExpression } from '../parser/reference-parser.js';
|
|
8
|
-
import { MergePartial, Nullable,
|
|
8
|
+
import { MergePartial, Nullable, SimplifyResult, SimplifySingleResult } from '../util/type-utils.js';
|
|
9
9
|
import { Compilable } from '../util/compilable.js';
|
|
10
10
|
import { QueryExecutor } from '../query-executor/query-executor.js';
|
|
11
11
|
import { QueryId } from '../util/query-id.js';
|
|
@@ -878,18 +878,18 @@ export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
878
878
|
*/
|
|
879
879
|
withPlugin(plugin: KyselyPlugin): DeleteQueryBuilder<DB, TB, O>;
|
|
880
880
|
toOperationNode(): DeleteQueryNode;
|
|
881
|
-
compile(): CompiledQuery<O
|
|
881
|
+
compile(): CompiledQuery<SimplifyResult<O>>;
|
|
882
882
|
/**
|
|
883
883
|
* Executes the query and returns an array of rows.
|
|
884
884
|
*
|
|
885
885
|
* Also see the {@link executeTakeFirst} and {@link executeTakeFirstOrThrow} methods.
|
|
886
886
|
*/
|
|
887
|
-
execute(): Promise<O[]>;
|
|
887
|
+
execute(): Promise<SimplifyResult<O>[]>;
|
|
888
888
|
/**
|
|
889
889
|
* Executes the query and returns the first result or undefined if
|
|
890
890
|
* the query returned no result.
|
|
891
891
|
*/
|
|
892
|
-
executeTakeFirst(): Promise<
|
|
892
|
+
executeTakeFirst(): Promise<SimplifySingleResult<O>>;
|
|
893
893
|
/**
|
|
894
894
|
* Executes the query and returns the first result or throws if
|
|
895
895
|
* the query returned no result.
|
|
@@ -898,7 +898,7 @@ export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
898
898
|
* provide a custom error class as the only argument to throw a different
|
|
899
899
|
* error.
|
|
900
900
|
*/
|
|
901
|
-
executeTakeFirstOrThrow(errorConstructor?: NoResultErrorConstructor): Promise<O
|
|
901
|
+
executeTakeFirstOrThrow(errorConstructor?: NoResultErrorConstructor): Promise<SimplifyResult<O>>;
|
|
902
902
|
/**
|
|
903
903
|
* Executes query with `explain` statement before `delete` keyword.
|
|
904
904
|
*
|
|
@@ -352,7 +352,7 @@ export class DeleteQueryBuilder {
|
|
|
352
352
|
return [
|
|
353
353
|
new DeleteResult(
|
|
354
354
|
// TODO: remove numUpdatedOrDeletedRows.
|
|
355
|
-
|
|
355
|
+
result.numAffectedRows ?? result.numUpdatedOrDeletedRows ?? 0n),
|
|
356
356
|
];
|
|
357
357
|
}
|
|
358
358
|
/**
|