kysely 0.23.3 → 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 +25 -25
- package/dist/cjs/dialect/database-introspector.d.ts +4 -2
- package/dist/cjs/dialect/dialect-adapter-base.d.ts +32 -6
- package/dist/cjs/dialect/dialect-adapter.d.ts +50 -8
- package/dist/cjs/dialect/mysql/mysql-adapter.d.ts +32 -6
- package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-introspector.js +21 -15
- package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +32 -6
- package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +1 -1
- package/dist/cjs/dialect/postgres/postgres-introspector.js +5 -3
- package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +32 -6
- package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +8 -7
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/migration/migrator.d.ts +8 -3
- package/dist/cjs/migration/migrator.js +15 -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/create-index-node.d.ts +1 -0
- package/dist/cjs/operation-node/delete-query-node.d.ts +4 -1
- package/dist/cjs/operation-node/delete-query-node.js +11 -2
- package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-transformer.js +10 -1
- package/dist/cjs/operation-node/operation-node-visitor.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-visitor.js +1 -0
- package/dist/cjs/operation-node/operation-node.d.ts +1 -1
- package/dist/cjs/operation-node/operator-node.d.ts +1 -1
- package/dist/cjs/operation-node/operator-node.js +1 -0
- package/dist/cjs/operation-node/using-node.d.ts +13 -0
- package/dist/cjs/operation-node/using-node.js +24 -0
- package/dist/cjs/parser/expression-parser.js +1 -1
- package/dist/cjs/parser/table-parser.d.ts +1 -0
- package/dist/cjs/parser/update-set-parser.d.ts +1 -1
- 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 +103 -11
- package/dist/cjs/query-builder/delete-query-builder.js +40 -9
- 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 +25 -10
- package/dist/cjs/query-builder/insert-query-builder.js +32 -9
- package/dist/cjs/query-builder/select-query-builder.d.ts +51 -34
- package/dist/cjs/query-builder/select-query-builder.js +53 -29
- package/dist/cjs/query-builder/update-query-builder.d.ts +26 -10
- package/dist/cjs/query-builder/update-query-builder.js +33 -9
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +2 -0
- package/dist/cjs/query-compiler/default-query-compiler.js +12 -1
- package/dist/cjs/query-creator.d.ts +29 -0
- package/dist/cjs/query-creator.js +2 -21
- package/dist/cjs/raw-builder/raw-builder.d.ts +4 -0
- package/dist/cjs/raw-builder/raw-builder.js +8 -2
- package/dist/cjs/schema/alter-table-builder.d.ts +5 -1
- package/dist/cjs/schema/alter-table-builder.js +8 -2
- package/dist/cjs/schema/create-index-builder.d.ts +6 -0
- package/dist/cjs/schema/create-index-builder.js +13 -0
- package/dist/cjs/schema/create-table-builder.d.ts +6 -2
- package/dist/cjs/schema/create-table-builder.js +9 -3
- package/dist/cjs/util/type-utils.d.ts +20 -1
- package/dist/esm/dialect/database-introspector.d.ts +4 -2
- package/dist/esm/dialect/dialect-adapter-base.d.ts +32 -6
- package/dist/esm/dialect/dialect-adapter.d.ts +50 -8
- package/dist/esm/dialect/mysql/mysql-adapter.d.ts +32 -6
- package/dist/esm/dialect/mysql/mysql-introspector.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-introspector.js +21 -15
- package/dist/esm/dialect/postgres/postgres-adapter.d.ts +32 -6
- package/dist/esm/dialect/postgres/postgres-introspector.d.ts +1 -1
- package/dist/esm/dialect/postgres/postgres-introspector.js +5 -3
- package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +32 -6
- package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +1 -1
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +8 -7
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/migration/migrator.d.ts +8 -3
- package/dist/esm/migration/migrator.js +15 -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/create-index-node.d.ts +1 -0
- package/dist/esm/operation-node/delete-query-node.d.ts +4 -1
- package/dist/esm/operation-node/delete-query-node.js +11 -2
- package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-transformer.js +10 -1
- package/dist/esm/operation-node/operation-node-visitor.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-visitor.js +1 -0
- package/dist/esm/operation-node/operation-node.d.ts +1 -1
- package/dist/esm/operation-node/operator-node.d.ts +1 -1
- package/dist/esm/operation-node/operator-node.js +1 -0
- package/dist/esm/operation-node/using-node.d.ts +13 -0
- package/dist/esm/operation-node/using-node.js +22 -0
- package/dist/esm/parser/expression-parser.js +2 -2
- package/dist/esm/parser/table-parser.d.ts +1 -0
- package/dist/esm/parser/update-set-parser.d.ts +1 -1
- 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 +103 -11
- package/dist/esm/query-builder/delete-query-builder.js +40 -9
- 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 +25 -10
- package/dist/esm/query-builder/insert-query-builder.js +33 -10
- package/dist/esm/query-builder/select-query-builder.d.ts +51 -34
- package/dist/esm/query-builder/select-query-builder.js +53 -29
- package/dist/esm/query-builder/update-query-builder.d.ts +26 -10
- package/dist/esm/query-builder/update-query-builder.js +33 -9
- package/dist/esm/query-compiler/default-query-compiler.d.ts +2 -0
- package/dist/esm/query-compiler/default-query-compiler.js +12 -1
- package/dist/esm/query-creator.d.ts +29 -0
- package/dist/esm/query-creator.js +2 -21
- package/dist/esm/raw-builder/raw-builder.d.ts +4 -0
- package/dist/esm/raw-builder/raw-builder.js +8 -2
- package/dist/esm/schema/alter-table-builder.d.ts +5 -1
- package/dist/esm/schema/alter-table-builder.js +8 -2
- package/dist/esm/schema/create-index-builder.d.ts +6 -0
- package/dist/esm/schema/create-index-builder.js +13 -0
- package/dist/esm/schema/create-table-builder.d.ts +6 -2
- package/dist/esm/schema/create-table-builder.js +9 -3
- package/dist/esm/util/type-utils.d.ts +20 -1
- package/package.json +1 -1
|
@@ -18,12 +18,38 @@ export declare class SqliteAdapter implements DialectAdapterBase {
|
|
|
18
18
|
* Most dialects have explicit locks that can be used, like advisory locks
|
|
19
19
|
* in PostgreSQL and the get_lock function in MySQL.
|
|
20
20
|
*
|
|
21
|
-
* If the dialect doesn't have explicit locks the {@link
|
|
22
|
-
* created by Kysely can be used instead.
|
|
23
|
-
* has two columns `id` and `is_locked` and there's only one row in the
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
21
|
+
* If the dialect doesn't have explicit locks the {@link MigrationLockOptions.lockTable}
|
|
22
|
+
* created by Kysely can be used instead. You can access it through the `options` object.
|
|
23
|
+
* The lock table has two columns `id` and `is_locked` and there's only one row in the table
|
|
24
|
+
* whose id is {@link MigrationLockOptions.lockRowId}. `is_locked` is an integer. Kysely
|
|
25
|
+
* takes care of creating the lock table and inserting the one single row to it before this
|
|
26
|
+
* method is executed. If the dialect supports schemas and the user has specified a custom
|
|
27
|
+
* schema in their migration settings, the options object also contains the schema name in
|
|
28
|
+
* {@link MigrationLockOptions.lockTableSchema}.
|
|
29
|
+
*
|
|
30
|
+
* Here's an example of how you might implement this method for a dialect that doesn't
|
|
31
|
+
* have explicit locks but supports `FOR UPDATE` row locks and transactional DDL:
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* {
|
|
35
|
+
* async acquireMigrationLock(db, options): Promise<void> {
|
|
36
|
+
* const queryDb = options.lockTableSchema
|
|
37
|
+
* ? db.withSchema(options.lockTableSchema)
|
|
38
|
+
* : db
|
|
39
|
+
*
|
|
40
|
+
* // Since our imaginary dialect supports transactional DDL and has
|
|
41
|
+
* // row locks, we can simply take a row lock here and it will guarantee
|
|
42
|
+
* // all subsequent calls to this method from other transactions will
|
|
43
|
+
* // wait until this transaction finishes.
|
|
44
|
+
* await queryDb
|
|
45
|
+
* .selectFrom(options.lockTable)
|
|
46
|
+
* .selectAll()
|
|
47
|
+
* .where('id', '=', options.lockRowId)
|
|
48
|
+
* .forUpdate()
|
|
49
|
+
* .execute()
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
27
53
|
*
|
|
28
54
|
* If `supportsTransactionalDdl` is `true` then the `db` passed to this method
|
|
29
55
|
* is a transaction inside which the migrations will be executed. Otherwise
|
|
@@ -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,11 +13,11 @@ 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')
|
|
20
|
-
|
|
20
|
+
.$castTo();
|
|
21
21
|
if (!options.withInternalKyselyTables) {
|
|
22
22
|
query = query
|
|
23
23
|
.where('name', '!=', DEFAULT_MIGRATION_TABLE)
|
|
@@ -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')
|
|
41
|
-
|
|
42
|
-
.
|
|
40
|
+
.select(['sql', 'type'])
|
|
41
|
+
.$castTo()
|
|
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,
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -159,6 +159,7 @@ export * from './operation-node/partition-by-item-node.js';
|
|
|
159
159
|
export * from './operation-node/set-operation-node.js';
|
|
160
160
|
export * from './operation-node/binary-operation-node.js';
|
|
161
161
|
export * from './operation-node/unary-operation-node.js';
|
|
162
|
+
export * from './operation-node/using-node.js';
|
|
162
163
|
export * from './util/column-type.js';
|
|
163
164
|
export * from './util/compilable.js';
|
|
164
165
|
export * from './util/explainable.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -160,6 +160,7 @@ export * from './operation-node/partition-by-item-node.js';
|
|
|
160
160
|
export * from './operation-node/set-operation-node.js';
|
|
161
161
|
export * from './operation-node/binary-operation-node.js';
|
|
162
162
|
export * from './operation-node/unary-operation-node.js';
|
|
163
|
+
export * from './operation-node/using-node.js';
|
|
163
164
|
export * from './util/column-type.js';
|
|
164
165
|
export * from './util/compilable.js';
|
|
165
166
|
export * from './util/explainable.js';
|
|
@@ -24,12 +24,17 @@ export interface Migration {
|
|
|
24
24
|
* other way.
|
|
25
25
|
*
|
|
26
26
|
* ```ts
|
|
27
|
+
* import { promises as fs } from 'fs'
|
|
28
|
+
* import path from 'path'
|
|
29
|
+
*
|
|
27
30
|
* const migrator = new Migrator({
|
|
28
31
|
* db,
|
|
29
|
-
* provider: new FileMigrationProvider(
|
|
32
|
+
* provider: new FileMigrationProvider({
|
|
33
|
+
* fs,
|
|
34
|
+
* path,
|
|
30
35
|
* // Path to the folder that contains all your migrations.
|
|
31
|
-
* 'some/path/to/migrations'
|
|
32
|
-
* )
|
|
36
|
+
* migrationFolder: 'some/path/to/migrations'
|
|
37
|
+
* })
|
|
33
38
|
* })
|
|
34
39
|
* ```
|
|
35
40
|
*/
|
|
@@ -17,12 +17,17 @@ export const NO_MIGRATIONS = freeze({ __noMigrations__: true });
|
|
|
17
17
|
* other way.
|
|
18
18
|
*
|
|
19
19
|
* ```ts
|
|
20
|
+
* import { promises as fs } from 'fs'
|
|
21
|
+
* import path from 'path'
|
|
22
|
+
*
|
|
20
23
|
* const migrator = new Migrator({
|
|
21
24
|
* db,
|
|
22
|
-
* provider: new FileMigrationProvider(
|
|
25
|
+
* provider: new FileMigrationProvider({
|
|
26
|
+
* fs,
|
|
27
|
+
* path,
|
|
23
28
|
* // Path to the folder that contains all your migrations.
|
|
24
|
-
* 'some/path/to/migrations'
|
|
25
|
-
* )
|
|
29
|
+
* migrationFolder: 'some/path/to/migrations'
|
|
30
|
+
* })
|
|
26
31
|
* })
|
|
27
32
|
* ```
|
|
28
33
|
*/
|
|
@@ -316,9 +321,14 @@ export class Migrator {
|
|
|
316
321
|
}
|
|
317
322
|
async #runMigrations(getTargetMigrationIndex) {
|
|
318
323
|
const adapter = this.#props.db.getExecutor().adapter;
|
|
324
|
+
const lockOptions = freeze({
|
|
325
|
+
lockTable: this.#props.migrationLockTableName ?? DEFAULT_MIGRATION_LOCK_TABLE,
|
|
326
|
+
lockRowId: MIGRATION_LOCK_ID,
|
|
327
|
+
lockTableSchema: this.#props.migrationTableSchema,
|
|
328
|
+
});
|
|
319
329
|
const run = async (db) => {
|
|
320
330
|
try {
|
|
321
|
-
await adapter.acquireMigrationLock(db);
|
|
331
|
+
await adapter.acquireMigrationLock(db, lockOptions);
|
|
322
332
|
const state = await this.#getState(db);
|
|
323
333
|
if (state.migrations.length === 0) {
|
|
324
334
|
return { results: [] };
|
|
@@ -336,7 +346,7 @@ export class Migrator {
|
|
|
336
346
|
return { results: [] };
|
|
337
347
|
}
|
|
338
348
|
finally {
|
|
339
|
-
await adapter.releaseMigrationLock(db);
|
|
349
|
+
await adapter.releaseMigrationLock(db, lockOptions);
|
|
340
350
|
}
|
|
341
351
|
};
|
|
342
352
|
if (adapter.supportsTransactionalDdl) {
|
|
@@ -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) {
|
|
@@ -8,9 +8,11 @@ import { LimitNode } from './limit-node.js';
|
|
|
8
8
|
import { OrderByNode } from './order-by-node.js';
|
|
9
9
|
import { OrderByItemNode } from './order-by-item-node.js';
|
|
10
10
|
import { ExplainNode } from './explain-node.js';
|
|
11
|
+
import { UsingNode } from './using-node.js';
|
|
11
12
|
export interface DeleteQueryNode extends OperationNode {
|
|
12
13
|
readonly kind: 'DeleteQueryNode';
|
|
13
14
|
readonly from: FromNode;
|
|
15
|
+
readonly using?: UsingNode;
|
|
14
16
|
readonly joins?: ReadonlyArray<JoinNode>;
|
|
15
17
|
readonly where?: WhereNode;
|
|
16
18
|
readonly returning?: ReturningNode;
|
|
@@ -24,8 +26,9 @@ export interface DeleteQueryNode extends OperationNode {
|
|
|
24
26
|
*/
|
|
25
27
|
export declare const DeleteQueryNode: Readonly<{
|
|
26
28
|
is(node: OperationNode): node is DeleteQueryNode;
|
|
27
|
-
create(
|
|
29
|
+
create(fromItems: OperationNode[], withNode?: WithNode): DeleteQueryNode;
|
|
28
30
|
cloneWithOrderByItem(deleteNode: DeleteQueryNode, item: OrderByItemNode): DeleteQueryNode;
|
|
29
31
|
cloneWithLimit(deleteNode: DeleteQueryNode, limit: LimitNode): DeleteQueryNode;
|
|
30
32
|
cloneWithExplain(deleteNode: DeleteQueryNode, explain: ExplainNode): DeleteQueryNode;
|
|
33
|
+
cloneWithUsing(deleteNode: DeleteQueryNode, tables: OperationNode[]): DeleteQueryNode;
|
|
31
34
|
}>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { freeze } from '../util/object-utils.js';
|
|
3
3
|
import { FromNode } from './from-node.js';
|
|
4
4
|
import { OrderByNode } from './order-by-node.js';
|
|
5
|
+
import { UsingNode } from './using-node.js';
|
|
5
6
|
/**
|
|
6
7
|
* @internal
|
|
7
8
|
*/
|
|
@@ -9,10 +10,10 @@ export const DeleteQueryNode = freeze({
|
|
|
9
10
|
is(node) {
|
|
10
11
|
return node.kind === 'DeleteQueryNode';
|
|
11
12
|
},
|
|
12
|
-
create(
|
|
13
|
+
create(fromItems, withNode) {
|
|
13
14
|
return freeze({
|
|
14
15
|
kind: 'DeleteQueryNode',
|
|
15
|
-
from: FromNode.create(
|
|
16
|
+
from: FromNode.create(fromItems),
|
|
16
17
|
...(withNode && { with: withNode }),
|
|
17
18
|
});
|
|
18
19
|
},
|
|
@@ -36,4 +37,12 @@ export const DeleteQueryNode = freeze({
|
|
|
36
37
|
explain,
|
|
37
38
|
});
|
|
38
39
|
},
|
|
40
|
+
cloneWithUsing(deleteNode, tables) {
|
|
41
|
+
return freeze({
|
|
42
|
+
...deleteNode,
|
|
43
|
+
using: deleteNode.using !== undefined
|
|
44
|
+
? UsingNode.cloneWithTables(deleteNode.using, tables)
|
|
45
|
+
: UsingNode.create(tables),
|
|
46
|
+
});
|
|
47
|
+
},
|
|
39
48
|
});
|
|
@@ -76,6 +76,7 @@ import { PartitionByItemNode } from './partition-by-item-node.js';
|
|
|
76
76
|
import { SetOperationNode } from './set-operation-node.js';
|
|
77
77
|
import { BinaryOperationNode } from './binary-operation-node.js';
|
|
78
78
|
import { UnaryOperationNode } from './unary-operation-node.js';
|
|
79
|
+
import { UsingNode } from './using-node.js';
|
|
79
80
|
/**
|
|
80
81
|
* Transforms an operation node tree into another one.
|
|
81
82
|
*
|
|
@@ -181,6 +182,7 @@ export declare class OperationNodeTransformer {
|
|
|
181
182
|
protected transformPartitionByItem(node: PartitionByItemNode): PartitionByItemNode;
|
|
182
183
|
protected transformBinaryOperation(node: BinaryOperationNode): BinaryOperationNode;
|
|
183
184
|
protected transformUnaryOperation(node: UnaryOperationNode): UnaryOperationNode;
|
|
185
|
+
protected transformUsing(node: UsingNode): UsingNode;
|
|
184
186
|
protected transformDataType(node: DataTypeNode): DataTypeNode;
|
|
185
187
|
protected transformSelectAll(node: SelectAllNode): SelectAllNode;
|
|
186
188
|
protected transformIdentifier(node: IdentifierNode): IdentifierNode;
|
|
@@ -110,6 +110,7 @@ export class OperationNodeTransformer {
|
|
|
110
110
|
SetOperationNode: this.transformSetOperation.bind(this),
|
|
111
111
|
BinaryOperationNode: this.transformBinaryOperation.bind(this),
|
|
112
112
|
UnaryOperationNode: this.transformUnaryOperation.bind(this),
|
|
113
|
+
UsingNode: this.transformUsing.bind(this),
|
|
113
114
|
});
|
|
114
115
|
transformNode(node) {
|
|
115
116
|
if (!node) {
|
|
@@ -259,6 +260,7 @@ export class OperationNodeTransformer {
|
|
|
259
260
|
return requireAllProps({
|
|
260
261
|
kind: 'DeleteQueryNode',
|
|
261
262
|
from: this.transformNode(node.from),
|
|
263
|
+
using: this.transformNode(node.using),
|
|
262
264
|
joins: this.transformNodeList(node.joins),
|
|
263
265
|
where: this.transformNode(node.where),
|
|
264
266
|
returning: this.transformNode(node.returning),
|
|
@@ -402,6 +404,7 @@ export class OperationNodeTransformer {
|
|
|
402
404
|
expression: this.transformNode(node.expression),
|
|
403
405
|
unique: node.unique,
|
|
404
406
|
using: this.transformNode(node.using),
|
|
407
|
+
ifNotExists: node.ifNotExists,
|
|
405
408
|
});
|
|
406
409
|
}
|
|
407
410
|
transformList(node) {
|
|
@@ -646,7 +649,7 @@ export class OperationNodeTransformer {
|
|
|
646
649
|
transformAggregateFunction(node) {
|
|
647
650
|
return requireAllProps({
|
|
648
651
|
kind: 'AggregateFunctionNode',
|
|
649
|
-
|
|
652
|
+
aggregated: this.transformNode(node.aggregated),
|
|
650
653
|
distinct: node.distinct,
|
|
651
654
|
filter: this.transformNode(node.filter),
|
|
652
655
|
func: node.func,
|
|
@@ -687,6 +690,12 @@ export class OperationNodeTransformer {
|
|
|
687
690
|
operand: this.transformNode(node.operand),
|
|
688
691
|
});
|
|
689
692
|
}
|
|
693
|
+
transformUsing(node) {
|
|
694
|
+
return requireAllProps({
|
|
695
|
+
kind: 'UsingNode',
|
|
696
|
+
tables: this.transformNodeList(node.tables),
|
|
697
|
+
});
|
|
698
|
+
}
|
|
690
699
|
transformDataType(node) {
|
|
691
700
|
// An Object.freezed leaf node. No need to clone.
|
|
692
701
|
return node;
|
|
@@ -76,6 +76,7 @@ import { PartitionByItemNode } from './partition-by-item-node.js';
|
|
|
76
76
|
import { SetOperationNode } from './set-operation-node.js';
|
|
77
77
|
import { BinaryOperationNode } from './binary-operation-node.js';
|
|
78
78
|
import { UnaryOperationNode } from './unary-operation-node.js';
|
|
79
|
+
import { UsingNode } from './using-node.js';
|
|
79
80
|
export declare abstract class OperationNodeVisitor {
|
|
80
81
|
#private;
|
|
81
82
|
protected readonly nodeStack: OperationNode[];
|
|
@@ -158,4 +159,5 @@ export declare abstract class OperationNodeVisitor {
|
|
|
158
159
|
protected abstract visitSetOperation(node: SetOperationNode): void;
|
|
159
160
|
protected abstract visitBinaryOperation(node: BinaryOperationNode): void;
|
|
160
161
|
protected abstract visitUnaryOperation(node: UnaryOperationNode): void;
|
|
162
|
+
protected abstract visitUsing(node: UsingNode): void;
|
|
161
163
|
}
|
|
@@ -83,6 +83,7 @@ export class OperationNodeVisitor {
|
|
|
83
83
|
SetOperationNode: this.visitSetOperation.bind(this),
|
|
84
84
|
BinaryOperationNode: this.visitBinaryOperation.bind(this),
|
|
85
85
|
UnaryOperationNode: this.visitUnaryOperation.bind(this),
|
|
86
|
+
UsingNode: this.visitUsing.bind(this),
|
|
86
87
|
});
|
|
87
88
|
visitNode = (node) => {
|
|
88
89
|
this.nodeStack.push(node);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare type OperationNodeKind = 'IdentifierNode' | 'SchemableIdentifierNode' | 'RawNode' | 'SelectQueryNode' | 'SelectionNode' | 'ReferenceNode' | 'ColumnNode' | 'TableNode' | 'AliasNode' | 'FromNode' | 'SelectAllNode' | 'AndNode' | 'OrNode' | 'ParensNode' | 'ValueNode' | 'ValueListNode' | 'PrimitiveValueListNode' | 'JoinNode' | 'OperatorNode' | 'WhereNode' | 'InsertQueryNode' | 'DeleteQueryNode' | 'ReturningNode' | 'CreateTableNode' | 'ColumnDefinitionNode' | 'AddColumnNode' | 'DropTableNode' | 'DataTypeNode' | 'OrderByNode' | 'OrderByItemNode' | 'GroupByNode' | 'GroupByItemNode' | 'UpdateQueryNode' | 'ColumnUpdateNode' | 'LimitNode' | 'OffsetNode' | 'OnConflictNode' | 'OnDuplicateKeyNode' | 'CreateIndexNode' | 'DropIndexNode' | 'ListNode' | 'ReferencesNode' | 'PrimaryKeyConstraintNode' | 'UniqueConstraintNode' | 'CheckConstraintNode' | 'ForeignKeyConstraintNode' | 'WithNode' | 'CommonTableExpressionNode' | 'HavingNode' | 'CreateSchemaNode' | 'DropSchemaNode' | 'AlterTableNode' | 'ModifyColumnNode' | 'DropColumnNode' | 'RenameColumnNode' | 'AlterColumnNode' | 'AddConstraintNode' | 'DropConstraintNode' | 'CreateViewNode' | 'DropViewNode' | 'GeneratedNode' | 'DefaultValueNode' | 'OnNode' | 'ValuesNode' | 'CommonTableExpressionNameNode' | 'SelectModifierNode' | 'CreateTypeNode' | 'DropTypeNode' | 'ExplainNode' | 'DefaultInsertValueNode' | 'AggregateFunctionNode' | 'OverNode' | 'PartitionByNode' | 'PartitionByItemNode' | 'SetOperationNode' | 'BinaryOperationNode' | 'UnaryOperationNode';
|
|
1
|
+
export declare type OperationNodeKind = 'IdentifierNode' | 'SchemableIdentifierNode' | 'RawNode' | 'SelectQueryNode' | 'SelectionNode' | 'ReferenceNode' | 'ColumnNode' | 'TableNode' | 'AliasNode' | 'FromNode' | 'SelectAllNode' | 'AndNode' | 'OrNode' | 'ParensNode' | 'ValueNode' | 'ValueListNode' | 'PrimitiveValueListNode' | 'JoinNode' | 'OperatorNode' | 'WhereNode' | 'InsertQueryNode' | 'DeleteQueryNode' | 'ReturningNode' | 'CreateTableNode' | 'ColumnDefinitionNode' | 'AddColumnNode' | 'DropTableNode' | 'DataTypeNode' | 'OrderByNode' | 'OrderByItemNode' | 'GroupByNode' | 'GroupByItemNode' | 'UpdateQueryNode' | 'ColumnUpdateNode' | 'LimitNode' | 'OffsetNode' | 'OnConflictNode' | 'OnDuplicateKeyNode' | 'CreateIndexNode' | 'DropIndexNode' | 'ListNode' | 'ReferencesNode' | 'PrimaryKeyConstraintNode' | 'UniqueConstraintNode' | 'CheckConstraintNode' | 'ForeignKeyConstraintNode' | 'WithNode' | 'CommonTableExpressionNode' | 'HavingNode' | 'CreateSchemaNode' | 'DropSchemaNode' | 'AlterTableNode' | 'ModifyColumnNode' | 'DropColumnNode' | 'RenameColumnNode' | 'AlterColumnNode' | 'AddConstraintNode' | 'DropConstraintNode' | 'CreateViewNode' | 'DropViewNode' | 'GeneratedNode' | 'DefaultValueNode' | 'OnNode' | 'ValuesNode' | 'CommonTableExpressionNameNode' | 'SelectModifierNode' | 'CreateTypeNode' | 'DropTypeNode' | 'ExplainNode' | 'DefaultInsertValueNode' | 'AggregateFunctionNode' | 'OverNode' | 'PartitionByNode' | 'PartitionByItemNode' | 'SetOperationNode' | 'BinaryOperationNode' | 'UnaryOperationNode' | 'UsingNode';
|
|
2
2
|
export interface OperationNode {
|
|
3
3
|
readonly kind: OperationNodeKind;
|
|
4
4
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OperationNode } from './operation-node.js';
|
|
2
|
-
export declare const COMPARISON_OPERATORS: readonly ["=", "==", "!=", "<>", ">", ">=", "<", "<=", "in", "not in", "is", "is not", "like", "not like", "ilike", "not ilike", "@>", "<@", "?", "?&", "!<", "!>", "<=>", "!~", "~", "~*", "!~*", "&&", "||", "@@", "@@@", "!!", "<->"];
|
|
2
|
+
export declare const COMPARISON_OPERATORS: readonly ["=", "==", "!=", "<>", ">", ">=", "<", "<=", "in", "not in", "is", "is not", "like", "not like", "match", "ilike", "not ilike", "@>", "<@", "?", "?&", "!<", "!>", "<=>", "!~", "~", "~*", "!~*", "&&", "||", "@@", "@@@", "!!", "<->"];
|
|
3
3
|
export declare const UNARY_FILTER_OPERATORS: readonly ["exists", "not exists"];
|
|
4
4
|
export declare type ComparisonOperator = typeof COMPARISON_OPERATORS[number];
|
|
5
5
|
export declare type UnaryFilterOperator = typeof UNARY_FILTER_OPERATORS[number];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { OperationNode } from './operation-node.js';
|
|
2
|
+
export interface UsingNode extends OperationNode {
|
|
3
|
+
readonly kind: 'UsingNode';
|
|
4
|
+
readonly tables: ReadonlyArray<OperationNode>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare const UsingNode: Readonly<{
|
|
10
|
+
is(node: OperationNode): node is UsingNode;
|
|
11
|
+
create(tables: ReadonlyArray<OperationNode>): UsingNode;
|
|
12
|
+
cloneWithTables(using: UsingNode, tables: ReadonlyArray<OperationNode>): UsingNode;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="./using-node.d.ts" />
|
|
2
|
+
import { freeze } from '../util/object-utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export const UsingNode = freeze({
|
|
7
|
+
is(node) {
|
|
8
|
+
return node.kind === 'UsingNode';
|
|
9
|
+
},
|
|
10
|
+
create(tables) {
|
|
11
|
+
return freeze({
|
|
12
|
+
kind: 'UsingNode',
|
|
13
|
+
tables: freeze(tables),
|
|
14
|
+
});
|
|
15
|
+
},
|
|
16
|
+
cloneWithTables(using, tables) {
|
|
17
|
+
return freeze({
|
|
18
|
+
...using,
|
|
19
|
+
tables: freeze([...using.tables, ...tables]),
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
});
|
|
@@ -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
|
};
|
|
@@ -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 UpdateObject<DB, TB extends keyof DB, UT extends keyof DB> = {
|
|
4
|
+
export declare type UpdateObject<DB, TB extends keyof DB, UT extends keyof DB = TB> = {
|
|
5
5
|
[C in UpdateKeys<DB[UT]>]?: ValueExpression<DB, TB, UpdateType<DB[UT][C]>> | undefined;
|
|
6
6
|
};
|
|
7
7
|
export declare function parseUpdateObject(update: UpdateObject<any, any, any>): ReadonlyArray<ColumnUpdateNode>;
|
|
@@ -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
|
}
|