kysely 0.28.9 → 0.28.11
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/index.d.ts +3 -1
- package/dist/cjs/kysely.js +4 -1
- package/dist/cjs/migration/migrator.d.ts +1 -1
- package/dist/cjs/migration/migrator.js +75 -68
- package/dist/cjs/query-compiler/default-query-compiler.js +4 -4
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/kysely.js +4 -1
- package/dist/esm/migration/migrator.d.ts +1 -1
- package/dist/esm/migration/migrator.js +75 -68
- package/dist/esm/query-compiler/default-query-compiler.js +4 -4
- package/package.json +16 -16
package/README.md
CHANGED
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
[](https://github.com/kysely-org/kysely/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc)
|
|
7
7
|
[](https://github.com/kysely-org/kysely/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-desc)
|
|
8
8
|

|
|
9
|
-
[](https://www.npmjs.com/package/kysely)
|
|
9
|
+
[](https://www.npmjs.com/package/kysely)
|
|
10
|
+
[](https://jsr.io/@kysely/kysely)
|
|
11
|
+
[](https://jsr.io/@kysely/kysely)
|
|
10
12
|
|
|
11
13
|
###### Join the discussion ⠀⠀⠀⠀⠀⠀⠀
|
|
12
14
|
[](https://discord.gg/xyBJ3GwvAm)
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -206,10 +206,11 @@ export * from './util/compilable.js';
|
|
|
206
206
|
export * from './util/explainable.js';
|
|
207
207
|
export * from './util/streamable.js';
|
|
208
208
|
export * from './util/log.js';
|
|
209
|
-
export type { AnyAliasedColumn, AnyAliasedColumnWithTable, AnyColumn, AnyColumnWithTable, Equals, UnknownRow, Simplify, SqlBool, Nullable, NumbersWhenDataTypeNotAvailable, NotNull, NumericString, ShallowDehydrateObject, ShallowDehydrateValue, StringsWhenDataTypeNotAvailable, } from './util/type-utils.js';
|
|
209
|
+
export type { AnyAliasedColumn, AnyAliasedColumnWithTable, AnyColumn, AnyColumnWithTable, DrainOuterGeneric, Equals, ExtractColumnType, UnknownRow, Simplify, SqlBool, Nullable, NumbersWhenDataTypeNotAvailable, NotNull, NumericString, ShallowDehydrateObject, ShallowDehydrateValue, SimplifyResult, SimplifySingleResult, StringsWhenDataTypeNotAvailable, } from './util/type-utils.js';
|
|
210
210
|
export * from './util/infer-result.js';
|
|
211
211
|
export { logOnce } from './util/log-once.js';
|
|
212
212
|
export { createQueryId, type QueryId } from './util/query-id.js';
|
|
213
|
+
export type { KyselyTypeError } from './util/type-error.js';
|
|
213
214
|
export type { SelectExpression, SelectCallback, SelectArg, Selection, CallbackSelection, } from './parser/select-parser.js';
|
|
214
215
|
export type { ReferenceExpression, ReferenceExpressionOrList, SimpleReferenceExpression, StringReference, ExtractTypeFromStringReference, ExtractTypeFromReferenceExpression, } from './parser/reference-parser.js';
|
|
215
216
|
export type { ValueExpression, ValueExpressionOrList, } from './parser/value-parser.js';
|
|
@@ -222,3 +223,4 @@ export type { ComparisonOperatorExpression, OperandValueExpression, OperandValue
|
|
|
222
223
|
export type { ExistsExpression } from './parser/unary-operation-parser.js';
|
|
223
224
|
export type { OperandExpression, ExpressionOrFactory, } from './parser/expression-parser.js';
|
|
224
225
|
export type { Collation } from './parser/collate-parser.js';
|
|
226
|
+
export type { QueryCreatorWithCommonTableExpression } from './parser/with-parser.js';
|
package/dist/cjs/kysely.js
CHANGED
|
@@ -565,7 +565,8 @@ class TransactionBuilder {
|
|
|
565
565
|
const settings = { isolationLevel, accessMode };
|
|
566
566
|
(0, driver_js_1.validateTransactionSettings)(settings);
|
|
567
567
|
return this.#props.executor.provideConnection(async (connection) => {
|
|
568
|
-
const
|
|
568
|
+
const state = { isCommitted: false, isRolledBack: false };
|
|
569
|
+
const executor = new NotCommittedOrRolledBackAssertingExecutor(this.#props.executor.withConnectionProvider(new single_connection_provider_js_1.SingleConnectionProvider(connection)), state);
|
|
569
570
|
const transaction = new Transaction({
|
|
570
571
|
...kyselyProps,
|
|
571
572
|
executor,
|
|
@@ -576,11 +577,13 @@ class TransactionBuilder {
|
|
|
576
577
|
transactionBegun = true;
|
|
577
578
|
const result = await callback(transaction);
|
|
578
579
|
await this.#props.driver.commitTransaction(connection);
|
|
580
|
+
state.isCommitted = true;
|
|
579
581
|
return result;
|
|
580
582
|
}
|
|
581
583
|
catch (error) {
|
|
582
584
|
if (transactionBegun) {
|
|
583
585
|
await this.#props.driver.rollbackTransaction(connection);
|
|
586
|
+
state.isRolledBack = true;
|
|
584
587
|
}
|
|
585
588
|
throw error;
|
|
586
589
|
}
|
|
@@ -263,7 +263,7 @@ export interface MigratorProps {
|
|
|
263
263
|
* the project, to the end of time or prepare to manually migrate the migration
|
|
264
264
|
* tables.
|
|
265
265
|
*
|
|
266
|
-
* This only works on postgres.
|
|
266
|
+
* This only works on postgres and mssql.
|
|
267
267
|
*/
|
|
268
268
|
readonly migrationTableSchema?: string;
|
|
269
269
|
/**
|
|
@@ -58,7 +58,8 @@ class Migrator {
|
|
|
58
58
|
* The returned array is sorted by migration name.
|
|
59
59
|
*/
|
|
60
60
|
async getMigrations() {
|
|
61
|
-
const
|
|
61
|
+
const tableExists = await this.#doesTableExist(this.#migrationTable);
|
|
62
|
+
const executedMigrations = tableExists
|
|
62
63
|
? await this.#props.db
|
|
63
64
|
.withPlugin(this.#schemaPlugin)
|
|
64
65
|
.selectFrom(this.#migrationTable)
|
|
@@ -265,7 +266,10 @@ class Migrator {
|
|
|
265
266
|
}
|
|
266
267
|
async #migrate(getMigrationDirectionAndStep) {
|
|
267
268
|
try {
|
|
268
|
-
await this.#
|
|
269
|
+
await this.#ensureMigrationTableSchemaExists();
|
|
270
|
+
await this.#ensureMigrationTableExists();
|
|
271
|
+
await this.#ensureMigrationLockTableExists();
|
|
272
|
+
await this.#ensureLockRowExists();
|
|
269
273
|
return await this.#runMigrations(getMigrationDirectionAndStep);
|
|
270
274
|
}
|
|
271
275
|
catch (error) {
|
|
@@ -293,95 +297,98 @@ class Migrator {
|
|
|
293
297
|
}
|
|
294
298
|
return new noop_plugin_js_1.NoopPlugin();
|
|
295
299
|
}
|
|
296
|
-
async #ensureMigrationTablesExists() {
|
|
297
|
-
await this.#ensureMigrationTableSchemaExists();
|
|
298
|
-
await this.#ensureMigrationTableExists();
|
|
299
|
-
await this.#ensureMigrationLockTableExists();
|
|
300
|
-
await this.#ensureLockRowExists();
|
|
301
|
-
}
|
|
302
300
|
async #ensureMigrationTableSchemaExists() {
|
|
303
301
|
if (!this.#migrationTableSchema) {
|
|
304
302
|
// Use default schema. Nothing to do.
|
|
305
303
|
return;
|
|
306
304
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
305
|
+
const schemaExists = await this.#doesSchemaExist();
|
|
306
|
+
if (schemaExists) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
try {
|
|
310
|
+
await this.#createIfNotExists(this.#props.db.schema.createSchema(this.#migrationTableSchema));
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
const schemaExists = await this.#doesSchemaExist();
|
|
314
|
+
// At least on PostgreSQL, `if not exists` doesn't guarantee the `create schema`
|
|
315
|
+
// query doesn't throw if the schema already exits. That's why we check if
|
|
316
|
+
// the schema exist here and ignore the error if it does.
|
|
317
|
+
if (!schemaExists) {
|
|
318
|
+
throw error;
|
|
318
319
|
}
|
|
319
320
|
}
|
|
320
321
|
}
|
|
321
322
|
async #ensureMigrationTableExists() {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
323
|
+
const tableExists = await this.#doesTableExist(this.#migrationTable);
|
|
324
|
+
if (tableExists) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
try {
|
|
328
|
+
await this.#createIfNotExists(this.#props.db.schema
|
|
329
|
+
.withPlugin(this.#schemaPlugin)
|
|
330
|
+
.createTable(this.#migrationTable)
|
|
331
|
+
.addColumn('name', 'varchar(255)', (col) => col.notNull().primaryKey())
|
|
332
|
+
// The migration run time as ISO string. This is not a real date type as we
|
|
333
|
+
// can't know which data type is supported by all future dialects.
|
|
334
|
+
.addColumn('timestamp', 'varchar(255)', (col) => col.notNull()));
|
|
335
|
+
}
|
|
336
|
+
catch (error) {
|
|
337
|
+
const tableExists = await this.#doesTableExist(this.#migrationTable);
|
|
338
|
+
// At least on PostgreSQL, `if not exists` doesn't guarantee the `create table`
|
|
339
|
+
// query doesn't throw if the table already exits. That's why we check if
|
|
340
|
+
// the table exist here and ignore the error if it does.
|
|
341
|
+
if (!tableExists) {
|
|
342
|
+
throw error;
|
|
342
343
|
}
|
|
343
344
|
}
|
|
344
345
|
}
|
|
345
346
|
async #ensureMigrationLockTableExists() {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
347
|
+
const tableExists = await this.#doesTableExist(this.#migrationLockTable);
|
|
348
|
+
if (tableExists) {
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
try {
|
|
352
|
+
await this.#createIfNotExists(this.#props.db.schema
|
|
353
|
+
.withPlugin(this.#schemaPlugin)
|
|
354
|
+
.createTable(this.#migrationLockTable)
|
|
355
|
+
.addColumn('id', 'varchar(255)', (col) => col.notNull().primaryKey())
|
|
356
|
+
.addColumn('is_locked', 'integer', (col) => col.notNull().defaultTo(0)));
|
|
357
|
+
}
|
|
358
|
+
catch (error) {
|
|
359
|
+
const tableExists = await this.#doesTableExist(this.#migrationLockTable);
|
|
360
|
+
// At least on PostgreSQL, `if not exists` doesn't guarantee the `create table`
|
|
361
|
+
// query doesn't throw if the table already exits. That's why we check if
|
|
362
|
+
// the table exist here and ignore the error if it does.
|
|
363
|
+
if (!tableExists) {
|
|
364
|
+
throw error;
|
|
361
365
|
}
|
|
362
366
|
}
|
|
363
367
|
}
|
|
364
368
|
async #ensureLockRowExists() {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
369
|
+
const lockRowExists = await this.#doesLockRowExists();
|
|
370
|
+
if (lockRowExists) {
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
try {
|
|
374
|
+
await this.#props.db
|
|
375
|
+
.withPlugin(this.#schemaPlugin)
|
|
376
|
+
.insertInto(this.#migrationLockTable)
|
|
377
|
+
.values({ id: exports.MIGRATION_LOCK_ID, is_locked: 0 })
|
|
378
|
+
.execute();
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
const lockRowExists = await this.#doesLockRowExists();
|
|
382
|
+
if (!lockRowExists) {
|
|
383
|
+
throw error;
|
|
377
384
|
}
|
|
378
385
|
}
|
|
379
386
|
}
|
|
380
|
-
async #
|
|
387
|
+
async #doesSchemaExist() {
|
|
381
388
|
const schemas = await this.#props.db.introspection.getSchemas();
|
|
382
389
|
return schemas.some((it) => it.name === this.#migrationTableSchema);
|
|
383
390
|
}
|
|
384
|
-
async #
|
|
391
|
+
async #doesTableExist(tableName) {
|
|
385
392
|
const schema = this.#migrationTableSchema;
|
|
386
393
|
const tables = await this.#props.db.introspection.getTables({
|
|
387
394
|
withInternalKyselyTables: true,
|
|
@@ -581,6 +581,10 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
581
581
|
this.append(' ');
|
|
582
582
|
this.visitNode(node.where);
|
|
583
583
|
}
|
|
584
|
+
if (node.returning) {
|
|
585
|
+
this.append(' ');
|
|
586
|
+
this.visitNode(node.returning);
|
|
587
|
+
}
|
|
584
588
|
if (node.orderBy) {
|
|
585
589
|
this.append(' ');
|
|
586
590
|
this.visitNode(node.orderBy);
|
|
@@ -589,10 +593,6 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
589
593
|
this.append(' ');
|
|
590
594
|
this.visitNode(node.limit);
|
|
591
595
|
}
|
|
592
|
-
if (node.returning) {
|
|
593
|
-
this.append(' ');
|
|
594
|
-
this.visitNode(node.returning);
|
|
595
|
-
}
|
|
596
596
|
if (wrapInParens) {
|
|
597
597
|
this.append(')');
|
|
598
598
|
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -206,10 +206,11 @@ export * from './util/compilable.js';
|
|
|
206
206
|
export * from './util/explainable.js';
|
|
207
207
|
export * from './util/streamable.js';
|
|
208
208
|
export * from './util/log.js';
|
|
209
|
-
export type { AnyAliasedColumn, AnyAliasedColumnWithTable, AnyColumn, AnyColumnWithTable, Equals, UnknownRow, Simplify, SqlBool, Nullable, NumbersWhenDataTypeNotAvailable, NotNull, NumericString, ShallowDehydrateObject, ShallowDehydrateValue, StringsWhenDataTypeNotAvailable, } from './util/type-utils.js';
|
|
209
|
+
export type { AnyAliasedColumn, AnyAliasedColumnWithTable, AnyColumn, AnyColumnWithTable, DrainOuterGeneric, Equals, ExtractColumnType, UnknownRow, Simplify, SqlBool, Nullable, NumbersWhenDataTypeNotAvailable, NotNull, NumericString, ShallowDehydrateObject, ShallowDehydrateValue, SimplifyResult, SimplifySingleResult, StringsWhenDataTypeNotAvailable, } from './util/type-utils.js';
|
|
210
210
|
export * from './util/infer-result.js';
|
|
211
211
|
export { logOnce } from './util/log-once.js';
|
|
212
212
|
export { createQueryId, type QueryId } from './util/query-id.js';
|
|
213
|
+
export type { KyselyTypeError } from './util/type-error.js';
|
|
213
214
|
export type { SelectExpression, SelectCallback, SelectArg, Selection, CallbackSelection, } from './parser/select-parser.js';
|
|
214
215
|
export type { ReferenceExpression, ReferenceExpressionOrList, SimpleReferenceExpression, StringReference, ExtractTypeFromStringReference, ExtractTypeFromReferenceExpression, } from './parser/reference-parser.js';
|
|
215
216
|
export type { ValueExpression, ValueExpressionOrList, } from './parser/value-parser.js';
|
|
@@ -222,3 +223,4 @@ export type { ComparisonOperatorExpression, OperandValueExpression, OperandValue
|
|
|
222
223
|
export type { ExistsExpression } from './parser/unary-operation-parser.js';
|
|
223
224
|
export type { OperandExpression, ExpressionOrFactory, } from './parser/expression-parser.js';
|
|
224
225
|
export type { Collation } from './parser/collate-parser.js';
|
|
226
|
+
export type { QueryCreatorWithCommonTableExpression } from './parser/with-parser.js';
|
package/dist/esm/kysely.js
CHANGED
|
@@ -559,7 +559,8 @@ export class TransactionBuilder {
|
|
|
559
559
|
const settings = { isolationLevel, accessMode };
|
|
560
560
|
validateTransactionSettings(settings);
|
|
561
561
|
return this.#props.executor.provideConnection(async (connection) => {
|
|
562
|
-
const
|
|
562
|
+
const state = { isCommitted: false, isRolledBack: false };
|
|
563
|
+
const executor = new NotCommittedOrRolledBackAssertingExecutor(this.#props.executor.withConnectionProvider(new SingleConnectionProvider(connection)), state);
|
|
563
564
|
const transaction = new Transaction({
|
|
564
565
|
...kyselyProps,
|
|
565
566
|
executor,
|
|
@@ -570,11 +571,13 @@ export class TransactionBuilder {
|
|
|
570
571
|
transactionBegun = true;
|
|
571
572
|
const result = await callback(transaction);
|
|
572
573
|
await this.#props.driver.commitTransaction(connection);
|
|
574
|
+
state.isCommitted = true;
|
|
573
575
|
return result;
|
|
574
576
|
}
|
|
575
577
|
catch (error) {
|
|
576
578
|
if (transactionBegun) {
|
|
577
579
|
await this.#props.driver.rollbackTransaction(connection);
|
|
580
|
+
state.isRolledBack = true;
|
|
578
581
|
}
|
|
579
582
|
throw error;
|
|
580
583
|
}
|
|
@@ -263,7 +263,7 @@ export interface MigratorProps {
|
|
|
263
263
|
* the project, to the end of time or prepare to manually migrate the migration
|
|
264
264
|
* tables.
|
|
265
265
|
*
|
|
266
|
-
* This only works on postgres.
|
|
266
|
+
* This only works on postgres and mssql.
|
|
267
267
|
*/
|
|
268
268
|
readonly migrationTableSchema?: string;
|
|
269
269
|
/**
|
|
@@ -56,7 +56,8 @@ export class Migrator {
|
|
|
56
56
|
* The returned array is sorted by migration name.
|
|
57
57
|
*/
|
|
58
58
|
async getMigrations() {
|
|
59
|
-
const
|
|
59
|
+
const tableExists = await this.#doesTableExist(this.#migrationTable);
|
|
60
|
+
const executedMigrations = tableExists
|
|
60
61
|
? await this.#props.db
|
|
61
62
|
.withPlugin(this.#schemaPlugin)
|
|
62
63
|
.selectFrom(this.#migrationTable)
|
|
@@ -263,7 +264,10 @@ export class Migrator {
|
|
|
263
264
|
}
|
|
264
265
|
async #migrate(getMigrationDirectionAndStep) {
|
|
265
266
|
try {
|
|
266
|
-
await this.#
|
|
267
|
+
await this.#ensureMigrationTableSchemaExists();
|
|
268
|
+
await this.#ensureMigrationTableExists();
|
|
269
|
+
await this.#ensureMigrationLockTableExists();
|
|
270
|
+
await this.#ensureLockRowExists();
|
|
267
271
|
return await this.#runMigrations(getMigrationDirectionAndStep);
|
|
268
272
|
}
|
|
269
273
|
catch (error) {
|
|
@@ -291,95 +295,98 @@ export class Migrator {
|
|
|
291
295
|
}
|
|
292
296
|
return new NoopPlugin();
|
|
293
297
|
}
|
|
294
|
-
async #ensureMigrationTablesExists() {
|
|
295
|
-
await this.#ensureMigrationTableSchemaExists();
|
|
296
|
-
await this.#ensureMigrationTableExists();
|
|
297
|
-
await this.#ensureMigrationLockTableExists();
|
|
298
|
-
await this.#ensureLockRowExists();
|
|
299
|
-
}
|
|
300
298
|
async #ensureMigrationTableSchemaExists() {
|
|
301
299
|
if (!this.#migrationTableSchema) {
|
|
302
300
|
// Use default schema. Nothing to do.
|
|
303
301
|
return;
|
|
304
302
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
303
|
+
const schemaExists = await this.#doesSchemaExist();
|
|
304
|
+
if (schemaExists) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
try {
|
|
308
|
+
await this.#createIfNotExists(this.#props.db.schema.createSchema(this.#migrationTableSchema));
|
|
309
|
+
}
|
|
310
|
+
catch (error) {
|
|
311
|
+
const schemaExists = await this.#doesSchemaExist();
|
|
312
|
+
// At least on PostgreSQL, `if not exists` doesn't guarantee the `create schema`
|
|
313
|
+
// query doesn't throw if the schema already exits. That's why we check if
|
|
314
|
+
// the schema exist here and ignore the error if it does.
|
|
315
|
+
if (!schemaExists) {
|
|
316
|
+
throw error;
|
|
316
317
|
}
|
|
317
318
|
}
|
|
318
319
|
}
|
|
319
320
|
async #ensureMigrationTableExists() {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
321
|
+
const tableExists = await this.#doesTableExist(this.#migrationTable);
|
|
322
|
+
if (tableExists) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
try {
|
|
326
|
+
await this.#createIfNotExists(this.#props.db.schema
|
|
327
|
+
.withPlugin(this.#schemaPlugin)
|
|
328
|
+
.createTable(this.#migrationTable)
|
|
329
|
+
.addColumn('name', 'varchar(255)', (col) => col.notNull().primaryKey())
|
|
330
|
+
// The migration run time as ISO string. This is not a real date type as we
|
|
331
|
+
// can't know which data type is supported by all future dialects.
|
|
332
|
+
.addColumn('timestamp', 'varchar(255)', (col) => col.notNull()));
|
|
333
|
+
}
|
|
334
|
+
catch (error) {
|
|
335
|
+
const tableExists = await this.#doesTableExist(this.#migrationTable);
|
|
336
|
+
// At least on PostgreSQL, `if not exists` doesn't guarantee the `create table`
|
|
337
|
+
// query doesn't throw if the table already exits. That's why we check if
|
|
338
|
+
// the table exist here and ignore the error if it does.
|
|
339
|
+
if (!tableExists) {
|
|
340
|
+
throw error;
|
|
340
341
|
}
|
|
341
342
|
}
|
|
342
343
|
}
|
|
343
344
|
async #ensureMigrationLockTableExists() {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
345
|
+
const tableExists = await this.#doesTableExist(this.#migrationLockTable);
|
|
346
|
+
if (tableExists) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
try {
|
|
350
|
+
await this.#createIfNotExists(this.#props.db.schema
|
|
351
|
+
.withPlugin(this.#schemaPlugin)
|
|
352
|
+
.createTable(this.#migrationLockTable)
|
|
353
|
+
.addColumn('id', 'varchar(255)', (col) => col.notNull().primaryKey())
|
|
354
|
+
.addColumn('is_locked', 'integer', (col) => col.notNull().defaultTo(0)));
|
|
355
|
+
}
|
|
356
|
+
catch (error) {
|
|
357
|
+
const tableExists = await this.#doesTableExist(this.#migrationLockTable);
|
|
358
|
+
// At least on PostgreSQL, `if not exists` doesn't guarantee the `create table`
|
|
359
|
+
// query doesn't throw if the table already exits. That's why we check if
|
|
360
|
+
// the table exist here and ignore the error if it does.
|
|
361
|
+
if (!tableExists) {
|
|
362
|
+
throw error;
|
|
359
363
|
}
|
|
360
364
|
}
|
|
361
365
|
}
|
|
362
366
|
async #ensureLockRowExists() {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
367
|
+
const lockRowExists = await this.#doesLockRowExists();
|
|
368
|
+
if (lockRowExists) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
try {
|
|
372
|
+
await this.#props.db
|
|
373
|
+
.withPlugin(this.#schemaPlugin)
|
|
374
|
+
.insertInto(this.#migrationLockTable)
|
|
375
|
+
.values({ id: MIGRATION_LOCK_ID, is_locked: 0 })
|
|
376
|
+
.execute();
|
|
377
|
+
}
|
|
378
|
+
catch (error) {
|
|
379
|
+
const lockRowExists = await this.#doesLockRowExists();
|
|
380
|
+
if (!lockRowExists) {
|
|
381
|
+
throw error;
|
|
375
382
|
}
|
|
376
383
|
}
|
|
377
384
|
}
|
|
378
|
-
async #
|
|
385
|
+
async #doesSchemaExist() {
|
|
379
386
|
const schemas = await this.#props.db.introspection.getSchemas();
|
|
380
387
|
return schemas.some((it) => it.name === this.#migrationTableSchema);
|
|
381
388
|
}
|
|
382
|
-
async #
|
|
389
|
+
async #doesTableExist(tableName) {
|
|
383
390
|
const schema = this.#migrationTableSchema;
|
|
384
391
|
const tables = await this.#props.db.introspection.getTables({
|
|
385
392
|
withInternalKyselyTables: true,
|
|
@@ -579,6 +579,10 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
|
|
|
579
579
|
this.append(' ');
|
|
580
580
|
this.visitNode(node.where);
|
|
581
581
|
}
|
|
582
|
+
if (node.returning) {
|
|
583
|
+
this.append(' ');
|
|
584
|
+
this.visitNode(node.returning);
|
|
585
|
+
}
|
|
582
586
|
if (node.orderBy) {
|
|
583
587
|
this.append(' ');
|
|
584
588
|
this.visitNode(node.orderBy);
|
|
@@ -587,10 +591,6 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
|
|
|
587
591
|
this.append(' ');
|
|
588
592
|
this.visitNode(node.limit);
|
|
589
593
|
}
|
|
590
|
-
if (node.returning) {
|
|
591
|
-
this.append(' ');
|
|
592
|
-
this.visitNode(node.returning);
|
|
593
|
-
}
|
|
594
594
|
if (wrapInParens) {
|
|
595
595
|
this.append(')');
|
|
596
596
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kysely",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.11",
|
|
4
4
|
"description": "Type safe SQL query builder",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -76,35 +76,35 @@
|
|
|
76
76
|
],
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
79
|
-
"@ark/attest": "^0.
|
|
79
|
+
"@ark/attest": "^0.56.0",
|
|
80
80
|
"@types/better-sqlite3": "^7.6.13",
|
|
81
81
|
"@types/chai": "^5.2.3",
|
|
82
82
|
"@types/chai-as-promised": "^8.0.2",
|
|
83
83
|
"@types/mocha": "^10.0.10",
|
|
84
84
|
"@types/node": "^24.10.1",
|
|
85
|
-
"@types/pg": "^8.
|
|
85
|
+
"@types/pg": "^8.16.0",
|
|
86
86
|
"@types/pg-cursor": "^2.7.2",
|
|
87
87
|
"@types/semver": "^7.7.1",
|
|
88
|
-
"@types/sinon": "^
|
|
89
|
-
"better-sqlite3": "^12.
|
|
90
|
-
"chai": "^6.2.
|
|
88
|
+
"@types/sinon": "^21.0.0",
|
|
89
|
+
"better-sqlite3": "^12.6.2",
|
|
90
|
+
"chai": "^6.2.2",
|
|
91
91
|
"chai-as-promised": "^8.0.2",
|
|
92
|
-
"esbuild": "^0.27.
|
|
93
|
-
"jsr": "^0.
|
|
94
|
-
"lodash": "^4.17.
|
|
92
|
+
"esbuild": "^0.27.2",
|
|
93
|
+
"jsr": "^0.14.1",
|
|
94
|
+
"lodash": "^4.17.23",
|
|
95
95
|
"mocha": "^11.7.5",
|
|
96
|
-
"mysql2": "^3.
|
|
96
|
+
"mysql2": "^3.16.2",
|
|
97
97
|
"pathe": "^2.0.3",
|
|
98
|
-
"pg": "^8.
|
|
99
|
-
"pg-cursor": "^2.
|
|
98
|
+
"pg": "^8.17.2",
|
|
99
|
+
"pg-cursor": "^2.16.2",
|
|
100
100
|
"pkg-types": "^2.3.0",
|
|
101
|
-
"playwright": "^1.
|
|
102
|
-
"prettier": "^3.
|
|
101
|
+
"playwright": "^1.58.0",
|
|
102
|
+
"prettier": "^3.8.1",
|
|
103
103
|
"semver": "^7.7.3",
|
|
104
|
-
"sinon": "^21.0.
|
|
104
|
+
"sinon": "^21.0.1",
|
|
105
105
|
"std-env": "^3.10.0",
|
|
106
106
|
"tarn": "^3.0.2",
|
|
107
|
-
"tedious": "^19.
|
|
107
|
+
"tedious": "^19.2.0",
|
|
108
108
|
"tsd": "^0.33.0",
|
|
109
109
|
"typescript": "~5.9.3"
|
|
110
110
|
},
|