kysely 0.23.3 → 0.23.4

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.
Files changed (90) hide show
  1. package/README.md +22 -24
  2. package/dist/cjs/dialect/dialect-adapter-base.d.ts +32 -6
  3. package/dist/cjs/dialect/dialect-adapter.d.ts +50 -8
  4. package/dist/cjs/dialect/mysql/mysql-adapter.d.ts +32 -6
  5. package/dist/cjs/dialect/mysql/mysql-introspector.js +2 -2
  6. package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +32 -6
  7. package/dist/cjs/dialect/postgres/postgres-introspector.js +2 -2
  8. package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +32 -6
  9. package/dist/cjs/dialect/sqlite/sqlite-introspector.js +2 -2
  10. package/dist/cjs/index.d.ts +1 -0
  11. package/dist/cjs/index.js +1 -0
  12. package/dist/cjs/migration/migrator.d.ts +8 -3
  13. package/dist/cjs/migration/migrator.js +15 -5
  14. package/dist/cjs/operation-node/create-index-node.d.ts +1 -0
  15. package/dist/cjs/operation-node/delete-query-node.d.ts +3 -0
  16. package/dist/cjs/operation-node/delete-query-node.js +9 -0
  17. package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -0
  18. package/dist/cjs/operation-node/operation-node-transformer.js +9 -0
  19. package/dist/cjs/operation-node/operation-node-visitor.d.ts +2 -0
  20. package/dist/cjs/operation-node/operation-node-visitor.js +1 -0
  21. package/dist/cjs/operation-node/operation-node.d.ts +1 -1
  22. package/dist/cjs/operation-node/operator-node.d.ts +1 -1
  23. package/dist/cjs/operation-node/operator-node.js +1 -0
  24. package/dist/cjs/operation-node/using-node.d.ts +13 -0
  25. package/dist/cjs/operation-node/using-node.js +24 -0
  26. package/dist/cjs/parser/update-set-parser.d.ts +1 -1
  27. package/dist/cjs/query-builder/delete-query-builder.d.ts +98 -6
  28. package/dist/cjs/query-builder/delete-query-builder.js +39 -8
  29. package/dist/cjs/query-builder/insert-query-builder.d.ts +21 -5
  30. package/dist/cjs/query-builder/insert-query-builder.js +32 -8
  31. package/dist/cjs/query-builder/select-query-builder.d.ts +43 -27
  32. package/dist/cjs/query-builder/select-query-builder.js +53 -29
  33. package/dist/cjs/query-builder/update-query-builder.d.ts +21 -5
  34. package/dist/cjs/query-builder/update-query-builder.js +32 -8
  35. package/dist/cjs/query-compiler/default-query-compiler.d.ts +2 -0
  36. package/dist/cjs/query-compiler/default-query-compiler.js +11 -0
  37. package/dist/cjs/raw-builder/raw-builder.d.ts +4 -0
  38. package/dist/cjs/raw-builder/raw-builder.js +8 -2
  39. package/dist/cjs/schema/alter-table-builder.d.ts +5 -1
  40. package/dist/cjs/schema/alter-table-builder.js +8 -2
  41. package/dist/cjs/schema/create-index-builder.d.ts +6 -0
  42. package/dist/cjs/schema/create-index-builder.js +13 -0
  43. package/dist/cjs/schema/create-table-builder.d.ts +6 -2
  44. package/dist/cjs/schema/create-table-builder.js +9 -3
  45. package/dist/cjs/util/type-utils.d.ts +18 -0
  46. package/dist/esm/dialect/dialect-adapter-base.d.ts +32 -6
  47. package/dist/esm/dialect/dialect-adapter.d.ts +50 -8
  48. package/dist/esm/dialect/mysql/mysql-adapter.d.ts +32 -6
  49. package/dist/esm/dialect/mysql/mysql-introspector.js +2 -2
  50. package/dist/esm/dialect/postgres/postgres-adapter.d.ts +32 -6
  51. package/dist/esm/dialect/postgres/postgres-introspector.js +2 -2
  52. package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +32 -6
  53. package/dist/esm/dialect/sqlite/sqlite-introspector.js +2 -2
  54. package/dist/esm/index.d.ts +1 -0
  55. package/dist/esm/index.js +1 -0
  56. package/dist/esm/migration/migrator.d.ts +8 -3
  57. package/dist/esm/migration/migrator.js +15 -5
  58. package/dist/esm/operation-node/create-index-node.d.ts +1 -0
  59. package/dist/esm/operation-node/delete-query-node.d.ts +3 -0
  60. package/dist/esm/operation-node/delete-query-node.js +9 -0
  61. package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -0
  62. package/dist/esm/operation-node/operation-node-transformer.js +9 -0
  63. package/dist/esm/operation-node/operation-node-visitor.d.ts +2 -0
  64. package/dist/esm/operation-node/operation-node-visitor.js +1 -0
  65. package/dist/esm/operation-node/operation-node.d.ts +1 -1
  66. package/dist/esm/operation-node/operator-node.d.ts +1 -1
  67. package/dist/esm/operation-node/operator-node.js +1 -0
  68. package/dist/esm/operation-node/using-node.d.ts +13 -0
  69. package/dist/esm/operation-node/using-node.js +22 -0
  70. package/dist/esm/parser/update-set-parser.d.ts +1 -1
  71. package/dist/esm/query-builder/delete-query-builder.d.ts +98 -6
  72. package/dist/esm/query-builder/delete-query-builder.js +39 -8
  73. package/dist/esm/query-builder/insert-query-builder.d.ts +21 -5
  74. package/dist/esm/query-builder/insert-query-builder.js +33 -9
  75. package/dist/esm/query-builder/select-query-builder.d.ts +43 -27
  76. package/dist/esm/query-builder/select-query-builder.js +53 -29
  77. package/dist/esm/query-builder/update-query-builder.d.ts +21 -5
  78. package/dist/esm/query-builder/update-query-builder.js +32 -8
  79. package/dist/esm/query-compiler/default-query-compiler.d.ts +2 -0
  80. package/dist/esm/query-compiler/default-query-compiler.js +11 -0
  81. package/dist/esm/raw-builder/raw-builder.d.ts +4 -0
  82. package/dist/esm/raw-builder/raw-builder.js +8 -2
  83. package/dist/esm/schema/alter-table-builder.d.ts +5 -1
  84. package/dist/esm/schema/alter-table-builder.js +8 -2
  85. package/dist/esm/schema/create-index-builder.d.ts +6 -0
  86. package/dist/esm/schema/create-index-builder.js +13 -0
  87. package/dist/esm/schema/create-table-builder.d.ts +6 -2
  88. package/dist/esm/schema/create-table-builder.js +9 -3
  89. package/dist/esm/util/type-utils.d.ts +18 -0
  90. package/package.json +1 -1
@@ -26,19 +26,45 @@ export interface DialectAdapter {
26
26
  * Most dialects have explicit locks that can be used, like advisory locks
27
27
  * in PostgreSQL and the get_lock function in MySQL.
28
28
  *
29
- * If the dialect doesn't have explicit locks the {@link MIGRATION_LOCK_TABLE}
30
- * created by Kysely can be used instead. {@link MIGRATION_LOCK_TABLE}
31
- * has two columns `id` and `is_locked` and there's only one row in the
32
- * table whose id is {@link MIGRATION_LOCK_ID}. `is_locked` is an integer.
33
- * Kysely takes care of creating the lock table and inserting the one single
34
- * row to it before this method is executed.
29
+ * If the dialect doesn't have explicit locks the {@link MigrationLockOptions.lockTable}
30
+ * created by Kysely can be used instead. You can access it through the `options` object.
31
+ * The lock table has two columns `id` and `is_locked` and there's only one row in the table
32
+ * whose id is {@link MigrationLockOptions.lockRowId}. `is_locked` is an integer. Kysely
33
+ * takes care of creating the lock table and inserting the one single row to it before this
34
+ * method is executed. If the dialect supports schemas and the user has specified a custom
35
+ * schema in their migration settings, the options object also contains the schema name in
36
+ * {@link MigrationLockOptions.lockTableSchema}.
37
+ *
38
+ * Here's an example of how you might implement this method for a dialect that doesn't
39
+ * have explicit locks but supports `FOR UPDATE` row locks and transactional DDL:
40
+ *
41
+ * ```ts
42
+ * {
43
+ * async acquireMigrationLock(db, options): Promise<void> {
44
+ * const queryDb = options.lockTableSchema
45
+ * ? db.withSchema(options.lockTableSchema)
46
+ * : db
47
+ *
48
+ * // Since our imaginary dialect supports transactional DDL and has
49
+ * // row locks, we can simply take a row lock here and it will guarantee
50
+ * // all subsequent calls to this method from other transactions will
51
+ * // wait until this transaction finishes.
52
+ * await queryDb
53
+ * .selectFrom(options.lockTable)
54
+ * .selectAll()
55
+ * .where('id', '=', options.lockRowId)
56
+ * .forUpdate()
57
+ * .execute()
58
+ * }
59
+ * }
60
+ * ```
35
61
  *
36
62
  * If `supportsTransactionalDdl` is `true` then the `db` passed to this method
37
63
  * is a transaction inside which the migrations will be executed. Otherwise
38
64
  * `db` is a single connection (session) that will be used to execute the
39
65
  * migrations.
40
66
  */
41
- acquireMigrationLock(db: Kysely<any>): Promise<void>;
67
+ acquireMigrationLock(db: Kysely<any>, options: MigrationLockOptions): Promise<void>;
42
68
  /**
43
69
  * Releases the migration lock. See {@link acquireMigrationLock}.
44
70
  *
@@ -47,5 +73,21 @@ export interface DialectAdapter {
47
73
  * is a single connection (session) that was used to execute the migrations
48
74
  * and the `acquireMigrationLock` call.
49
75
  */
50
- releaseMigrationLock(db: Kysely<any>): Promise<void>;
76
+ releaseMigrationLock(db: Kysely<any>, options: MigrationLockOptions): Promise<void>;
77
+ }
78
+ export interface MigrationLockOptions {
79
+ /**
80
+ * The name of the migration lock table.
81
+ */
82
+ readonly lockTable: string;
83
+ /**
84
+ * The id of the only row in the migration lock table.
85
+ */
86
+ readonly lockRowId: string;
87
+ /**
88
+ * The schema in which the migration lock table lives. This is only
89
+ * defined if the user has specified a custom schema in the migration
90
+ * settings.
91
+ */
92
+ readonly lockTableSchema?: string;
51
93
  }
@@ -19,12 +19,38 @@ export declare class MysqlAdapter extends DialectAdapterBase {
19
19
  * Most dialects have explicit locks that can be used, like advisory locks
20
20
  * in PostgreSQL and the get_lock function in MySQL.
21
21
  *
22
- * If the dialect doesn't have explicit locks the {@link MIGRATION_LOCK_TABLE}
23
- * created by Kysely can be used instead. {@link MIGRATION_LOCK_TABLE}
24
- * has two columns `id` and `is_locked` and there's only one row in the
25
- * table whose id is {@link MIGRATION_LOCK_ID}. `is_locked` is an integer.
26
- * Kysely takes care of creating the lock table and inserting the one single
27
- * row to it before this method is executed.
22
+ * If the dialect doesn't have explicit locks the {@link MigrationLockOptions.lockTable}
23
+ * created by Kysely can be used instead. You can access it through the `options` object.
24
+ * The lock table has two columns `id` and `is_locked` and there's only one row in the table
25
+ * whose id is {@link MigrationLockOptions.lockRowId}. `is_locked` is an integer. Kysely
26
+ * takes care of creating the lock table and inserting the one single row to it before this
27
+ * method is executed. If the dialect supports schemas and the user has specified a custom
28
+ * schema in their migration settings, the options object also contains the schema name in
29
+ * {@link MigrationLockOptions.lockTableSchema}.
30
+ *
31
+ * Here's an example of how you might implement this method for a dialect that doesn't
32
+ * have explicit locks but supports `FOR UPDATE` row locks and transactional DDL:
33
+ *
34
+ * ```ts
35
+ * {
36
+ * async acquireMigrationLock(db, options): Promise<void> {
37
+ * const queryDb = options.lockTableSchema
38
+ * ? db.withSchema(options.lockTableSchema)
39
+ * : db
40
+ *
41
+ * // Since our imaginary dialect supports transactional DDL and has
42
+ * // row locks, we can simply take a row lock here and it will guarantee
43
+ * // all subsequent calls to this method from other transactions will
44
+ * // wait until this transaction finishes.
45
+ * await queryDb
46
+ * .selectFrom(options.lockTable)
47
+ * .selectAll()
48
+ * .where('id', '=', options.lockRowId)
49
+ * .forUpdate()
50
+ * .execute()
51
+ * }
52
+ * }
53
+ * ```
28
54
  *
29
55
  * If `supportsTransactionalDdl` is `true` then the `db` passed to this method
30
56
  * is a transaction inside which the migrations will be executed. Otherwise
@@ -11,7 +11,7 @@ export class MysqlIntrospector {
11
11
  let rawSchemas = await this.#db
12
12
  .selectFrom('information_schema.schemata')
13
13
  .select('schema_name')
14
- .castTo()
14
+ .$castTo()
15
15
  .execute();
16
16
  return rawSchemas.map((it) => ({ name: it.SCHEMA_NAME }));
17
17
  }
@@ -30,7 +30,7 @@ export class MysqlIntrospector {
30
30
  .where('table_schema', '=', sql `database()`)
31
31
  .orderBy('table_name')
32
32
  .orderBy('ordinal_position')
33
- .castTo();
33
+ .$castTo();
34
34
  if (!options.withInternalKyselyTables) {
35
35
  query = query
36
36
  .where('table_name', '!=', DEFAULT_MIGRATION_TABLE)
@@ -19,12 +19,38 @@ export declare class PostgresAdapter extends DialectAdapterBase {
19
19
  * Most dialects have explicit locks that can be used, like advisory locks
20
20
  * in PostgreSQL and the get_lock function in MySQL.
21
21
  *
22
- * If the dialect doesn't have explicit locks the {@link MIGRATION_LOCK_TABLE}
23
- * created by Kysely can be used instead. {@link MIGRATION_LOCK_TABLE}
24
- * has two columns `id` and `is_locked` and there's only one row in the
25
- * table whose id is {@link MIGRATION_LOCK_ID}. `is_locked` is an integer.
26
- * Kysely takes care of creating the lock table and inserting the one single
27
- * row to it before this method is executed.
22
+ * If the dialect doesn't have explicit locks the {@link MigrationLockOptions.lockTable}
23
+ * created by Kysely can be used instead. You can access it through the `options` object.
24
+ * The lock table has two columns `id` and `is_locked` and there's only one row in the table
25
+ * whose id is {@link MigrationLockOptions.lockRowId}. `is_locked` is an integer. Kysely
26
+ * takes care of creating the lock table and inserting the one single row to it before this
27
+ * method is executed. If the dialect supports schemas and the user has specified a custom
28
+ * schema in their migration settings, the options object also contains the schema name in
29
+ * {@link MigrationLockOptions.lockTableSchema}.
30
+ *
31
+ * Here's an example of how you might implement this method for a dialect that doesn't
32
+ * have explicit locks but supports `FOR UPDATE` row locks and transactional DDL:
33
+ *
34
+ * ```ts
35
+ * {
36
+ * async acquireMigrationLock(db, options): Promise<void> {
37
+ * const queryDb = options.lockTableSchema
38
+ * ? db.withSchema(options.lockTableSchema)
39
+ * : db
40
+ *
41
+ * // Since our imaginary dialect supports transactional DDL and has
42
+ * // row locks, we can simply take a row lock here and it will guarantee
43
+ * // all subsequent calls to this method from other transactions will
44
+ * // wait until this transaction finishes.
45
+ * await queryDb
46
+ * .selectFrom(options.lockTable)
47
+ * .selectAll()
48
+ * .where('id', '=', options.lockRowId)
49
+ * .forUpdate()
50
+ * .execute()
51
+ * }
52
+ * }
53
+ * ```
28
54
  *
29
55
  * If `supportsTransactionalDdl` is `true` then the `db` passed to this method
30
56
  * is a transaction inside which the migrations will be executed. Otherwise
@@ -11,7 +11,7 @@ export class PostgresIntrospector {
11
11
  let rawSchemas = await this.#db
12
12
  .selectFrom('pg_catalog.pg_namespace')
13
13
  .select('nspname')
14
- .castTo()
14
+ .$castTo()
15
15
  .execute();
16
16
  return rawSchemas.map((it) => ({ name: it.nspname }));
17
17
  }
@@ -56,7 +56,7 @@ export class PostgresIntrospector {
56
56
  .orderBy('ns.nspname')
57
57
  .orderBy('c.relname')
58
58
  .orderBy('a.attnum')
59
- .castTo();
59
+ .$castTo();
60
60
  if (!options.withInternalKyselyTables) {
61
61
  query = query
62
62
  .where('c.relname', '!=', DEFAULT_MIGRATION_TABLE)
@@ -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 MIGRATION_LOCK_TABLE}
22
- * created by Kysely can be used instead. {@link MIGRATION_LOCK_TABLE}
23
- * has two columns `id` and `is_locked` and there's only one row in the
24
- * table whose id is {@link MIGRATION_LOCK_ID}. `is_locked` is an integer.
25
- * Kysely takes care of creating the lock table and inserting the one single
26
- * row to it before this method is executed.
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
@@ -17,7 +17,7 @@ export class SqliteIntrospector {
17
17
  .where('name', 'not like', 'sqlite_%')
18
18
  .select('name')
19
19
  .orderBy('name')
20
- .castTo();
20
+ .$castTo();
21
21
  if (!options.withInternalKyselyTables) {
22
22
  query = query
23
23
  .where('name', '!=', DEFAULT_MIGRATION_TABLE)
@@ -38,7 +38,7 @@ export class SqliteIntrospector {
38
38
  .selectFrom('sqlite_master')
39
39
  .where('name', '=', table)
40
40
  .select('sql')
41
- .castTo()
41
+ .$castTo()
42
42
  .execute();
43
43
  // Try to find the name of the column that has `autoincrement` 🤦
44
44
  const autoIncrementCol = createSql[0]?.sql
@@ -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) {
@@ -11,6 +11,7 @@ export interface CreateIndexNode extends OperationNode {
11
11
  readonly expression?: OperationNode;
12
12
  readonly unique?: boolean;
13
13
  readonly using?: RawNode;
14
+ readonly ifNotExists?: boolean;
14
15
  }
15
16
  /**
16
17
  * @internal
@@ -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;
@@ -28,4 +30,5 @@ export declare const DeleteQueryNode: Readonly<{
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
  */
@@ -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) {
@@ -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: 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];
@@ -15,6 +15,7 @@ export const COMPARISON_OPERATORS = [
15
15
  'is not',
16
16
  'like',
17
17
  'not like',
18
+ 'match',
18
19
  'ilike',
19
20
  'not ilike',
20
21
  '@>',
@@ -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,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>;