kysely 0.16.6 → 0.16.7

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 (74) hide show
  1. package/README.md +118 -5
  2. package/dist/cjs/dialect/mysql/mysql-dialect.js +2 -1
  3. package/dist/cjs/dialect/mysql/mysql-driver.js +1 -1
  4. package/dist/cjs/dialect/postgres/postgres-dialect.js +2 -1
  5. package/dist/cjs/dialect/postgres/postgres-driver.js +1 -1
  6. package/dist/cjs/dialect/sqlite/sqlite-dialect.js +2 -1
  7. package/dist/cjs/dialect/sqlite/sqlite-driver.js +1 -1
  8. package/dist/cjs/driver/dummy-driver.d.ts +28 -0
  9. package/dist/cjs/driver/dummy-driver.js +31 -3
  10. package/dist/cjs/index-nodeless.d.ts +1 -0
  11. package/dist/cjs/index-nodeless.js +1 -0
  12. package/dist/cjs/kysely.d.ts +8 -6
  13. package/dist/cjs/kysely.js +8 -6
  14. package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-plugin.d.ts +48 -0
  15. package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-plugin.js +19 -0
  16. package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +9 -0
  17. package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-transformer.js +42 -0
  18. package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.d.ts +0 -0
  19. package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.js +0 -0
  20. package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.d.ts +0 -0
  21. package/dist/cjs/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.js +0 -0
  22. package/dist/cjs/query-builder/delete-query-builder.d.ts +51 -9
  23. package/dist/cjs/query-builder/delete-query-builder.js +56 -8
  24. package/dist/cjs/query-builder/function-builder.d.ts +29 -5
  25. package/dist/cjs/query-builder/function-builder.js +31 -7
  26. package/dist/cjs/query-builder/insert-query-builder.d.ts +53 -11
  27. package/dist/cjs/query-builder/insert-query-builder.js +58 -10
  28. package/dist/cjs/query-builder/select-query-builder.d.ts +58 -16
  29. package/dist/cjs/query-builder/select-query-builder.js +64 -15
  30. package/dist/cjs/query-builder/update-query-builder.d.ts +52 -9
  31. package/dist/cjs/query-builder/update-query-builder.js +57 -8
  32. package/dist/cjs/query-creator.d.ts +2 -2
  33. package/dist/cjs/query-creator.js +2 -2
  34. package/dist/cjs/schema/create-view-builder.js +1 -1
  35. package/dist/cjs/util/object-utils.d.ts +1 -0
  36. package/dist/cjs/util/object-utils.js +50 -1
  37. package/dist/cjs/util/type-utils.d.ts +21 -0
  38. package/dist/esm/dialect/mysql/mysql-dialect.js +2 -1
  39. package/dist/esm/dialect/mysql/mysql-driver.js +2 -2
  40. package/dist/esm/dialect/postgres/postgres-dialect.js +2 -1
  41. package/dist/esm/dialect/postgres/postgres-driver.js +2 -2
  42. package/dist/esm/dialect/sqlite/sqlite-dialect.js +2 -1
  43. package/dist/esm/dialect/sqlite/sqlite-driver.js +2 -2
  44. package/dist/esm/driver/dummy-driver.d.ts +28 -0
  45. package/dist/esm/driver/dummy-driver.js +31 -3
  46. package/dist/esm/index-nodeless.d.ts +1 -0
  47. package/dist/esm/index-nodeless.js +1 -0
  48. package/dist/esm/kysely.d.ts +8 -6
  49. package/dist/esm/kysely.js +8 -6
  50. package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-plugin.d.ts +48 -0
  51. package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-plugin.js +16 -0
  52. package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-transformer.d.ts +9 -0
  53. package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-transformer.js +39 -0
  54. package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.d.ts +0 -0
  55. package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-plugin.js +0 -0
  56. package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.d.ts +0 -0
  57. package/dist/esm/plugin/{immediate-value.ts → immediate-value}/immediate-value-transformer.js +0 -0
  58. package/dist/esm/query-builder/delete-query-builder.d.ts +51 -9
  59. package/dist/esm/query-builder/delete-query-builder.js +56 -8
  60. package/dist/esm/query-builder/function-builder.d.ts +29 -5
  61. package/dist/esm/query-builder/function-builder.js +31 -7
  62. package/dist/esm/query-builder/insert-query-builder.d.ts +53 -11
  63. package/dist/esm/query-builder/insert-query-builder.js +58 -10
  64. package/dist/esm/query-builder/select-query-builder.d.ts +58 -16
  65. package/dist/esm/query-builder/select-query-builder.js +64 -15
  66. package/dist/esm/query-builder/update-query-builder.d.ts +52 -9
  67. package/dist/esm/query-builder/update-query-builder.js +57 -8
  68. package/dist/esm/query-creator.d.ts +2 -2
  69. package/dist/esm/query-creator.js +2 -2
  70. package/dist/esm/schema/create-view-builder.js +1 -1
  71. package/dist/esm/util/object-utils.d.ts +1 -0
  72. package/dist/esm/util/object-utils.js +48 -0
  73. package/dist/esm/util/type-utils.d.ts +21 -0
  74. package/package.json +4 -2
@@ -7,7 +7,7 @@ import { SelectExpression, QueryBuilderWithSelection, SelectAllQueryBuilder } fr
7
7
  import { ExistsExpression, FilterOperator, FilterValueExpressionOrList, WhereGrouper, HavingGrouper } from '../parser/filter-parser.js';
8
8
  import { ReferenceExpression } from '../parser/reference-parser.js';
9
9
  import { SelectQueryNode } from '../operation-node/select-query-node.js';
10
- import { AnyRawBuilder, SingleResultType } from '../util/type-utils.js';
10
+ import { AnyRawBuilder, MergePartial, SingleResultType } from '../util/type-utils.js';
11
11
  import { OrderByDirectionExpression, OrderByExpression } from '../parser/order-by-parser.js';
12
12
  import { Compilable } from '../util/compilable.js';
13
13
  import { QueryExecutor } from '../query-executor/query-executor.js';
@@ -1116,27 +1116,15 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
1116
1116
  /**
1117
1117
  * Simply calls the given function passing `this` as the only argument.
1118
1118
  *
1119
- * This method can be useful when adding optional method calls:
1119
+ * If you want to conditionally call a method on `this`, see
1120
+ * the {@link if} method.
1120
1121
  *
1121
1122
  * ### Examples
1122
1123
  *
1123
- * ```ts
1124
- * db.selectFrom('person')
1125
- * .selectAll()
1126
- * .call((qb) => {
1127
- * if (something) {
1128
- * return qb.where('something', '=', something)
1129
- * } else {
1130
- * return qb.where('somethingElse', '=', somethingElse)
1131
- * }
1132
- * })
1133
- * .execute()
1134
- * ```
1135
- *
1136
1124
  * The next example uses a helper funtion `log` to log a query:
1137
1125
  *
1138
1126
  * ```ts
1139
- * function log<T extends AnyQueryBuilder>(qb: T): T {
1127
+ * function log<T extends Compilable>(qb: T): T {
1140
1128
  * console.log(qb.compile())
1141
1129
  * return qb
1142
1130
  * }
@@ -1148,6 +1136,57 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
1148
1136
  * ```
1149
1137
  */
1150
1138
  call<T>(func: (qb: this) => T): T;
1139
+ /**
1140
+ * Call `func(this)` if `condition` is true.
1141
+ *
1142
+ * This method is especially handy with optional selects. Any `select` or `selectAll`
1143
+ * method calls add columns as optional fields to the output type when called inside
1144
+ * the `func` callback. This is because we can't know if those selections were actually
1145
+ * made before running the code.
1146
+ *
1147
+ * Also see [this recipe](https://github.com/koskimas/kysely/tree/master/recipes/conditional-selects.md)
1148
+ *
1149
+ * ### Examples
1150
+ *
1151
+ * ```ts
1152
+ * async function getPerson(id: number, withLastName: boolean) {
1153
+ * return await db
1154
+ * .selectFrom('person')
1155
+ * .select(['id', 'first_name'])
1156
+ * .if(withLastName, (qb) => qb.select('last_name'))
1157
+ * .where('id', '=', id)
1158
+ * .executeTakeFirstOrThrow()
1159
+ * }
1160
+ * ```
1161
+ *
1162
+ * Any selections added inside the `if` callback will be added as optional fields to the
1163
+ * output type since we can't know if the selections were actually made before running
1164
+ * the code. In the example above the return type of the `getPerson` function is:
1165
+ *
1166
+ * ```ts
1167
+ * {
1168
+ * id: number
1169
+ * first_name: string
1170
+ * last_name?: string
1171
+ * }
1172
+ * ```
1173
+ *
1174
+ * You can also call any other methods inside the callback:
1175
+ *
1176
+ * ```ts
1177
+ * const { count } = db.fn
1178
+ *
1179
+ * db.selectFrom('person')
1180
+ * .select('person.id')
1181
+ * .if(filterByFirstName, (qb) => qb.where('first_name', '=', firstName))
1182
+ * .if(filterByPetCount, (qb) => qb
1183
+ * .innerJoin('pet', 'pet.owner_id', 'person.id')
1184
+ * .having(count('pet.id'), '>', petCountLimit)
1185
+ * .groupBy('person.id')
1186
+ * )
1187
+ * ```
1188
+ */
1189
+ if<O2 extends O>(condition: boolean, func: (qb: this) => SelectQueryBuilder<DB, TB, O2>): SelectQueryBuilder<DB, TB, MergePartial<O, O2>>;
1151
1190
  /**
1152
1191
  * Gives an alias for the query. This method is only useful for sub queries.
1153
1192
  *
@@ -1173,6 +1212,9 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
1173
1212
  * don't support your use case.
1174
1213
  */
1175
1214
  castTo<T>(): SelectQueryBuilder<DB, TB, T>;
1215
+ /**
1216
+ * Returns a copy of this SelectQueryBuilder instance with the given plugin installed.
1217
+ */
1176
1218
  withPlugin(plugin: KyselyPlugin): SelectQueryBuilder<DB, TB, O>;
1177
1219
  toOperationNode(): SelectQueryNode;
1178
1220
  compile(): CompiledQuery;
@@ -425,27 +425,15 @@ export class SelectQueryBuilder {
425
425
  /**
426
426
  * Simply calls the given function passing `this` as the only argument.
427
427
  *
428
- * This method can be useful when adding optional method calls:
428
+ * If you want to conditionally call a method on `this`, see
429
+ * the {@link if} method.
429
430
  *
430
431
  * ### Examples
431
432
  *
432
- * ```ts
433
- * db.selectFrom('person')
434
- * .selectAll()
435
- * .call((qb) => {
436
- * if (something) {
437
- * return qb.where('something', '=', something)
438
- * } else {
439
- * return qb.where('somethingElse', '=', somethingElse)
440
- * }
441
- * })
442
- * .execute()
443
- * ```
444
- *
445
433
  * The next example uses a helper funtion `log` to log a query:
446
434
  *
447
435
  * ```ts
448
- * function log<T extends AnyQueryBuilder>(qb: T): T {
436
+ * function log<T extends Compilable>(qb: T): T {
449
437
  * console.log(qb.compile())
450
438
  * return qb
451
439
  * }
@@ -459,6 +447,64 @@ export class SelectQueryBuilder {
459
447
  call(func) {
460
448
  return func(this);
461
449
  }
450
+ /**
451
+ * Call `func(this)` if `condition` is true.
452
+ *
453
+ * This method is especially handy with optional selects. Any `select` or `selectAll`
454
+ * method calls add columns as optional fields to the output type when called inside
455
+ * the `func` callback. This is because we can't know if those selections were actually
456
+ * made before running the code.
457
+ *
458
+ * Also see [this recipe](https://github.com/koskimas/kysely/tree/master/recipes/conditional-selects.md)
459
+ *
460
+ * ### Examples
461
+ *
462
+ * ```ts
463
+ * async function getPerson(id: number, withLastName: boolean) {
464
+ * return await db
465
+ * .selectFrom('person')
466
+ * .select(['id', 'first_name'])
467
+ * .if(withLastName, (qb) => qb.select('last_name'))
468
+ * .where('id', '=', id)
469
+ * .executeTakeFirstOrThrow()
470
+ * }
471
+ * ```
472
+ *
473
+ * Any selections added inside the `if` callback will be added as optional fields to the
474
+ * output type since we can't know if the selections were actually made before running
475
+ * the code. In the example above the return type of the `getPerson` function is:
476
+ *
477
+ * ```ts
478
+ * {
479
+ * id: number
480
+ * first_name: string
481
+ * last_name?: string
482
+ * }
483
+ * ```
484
+ *
485
+ * You can also call any other methods inside the callback:
486
+ *
487
+ * ```ts
488
+ * const { count } = db.fn
489
+ *
490
+ * db.selectFrom('person')
491
+ * .select('person.id')
492
+ * .if(filterByFirstName, (qb) => qb.where('first_name', '=', firstName))
493
+ * .if(filterByPetCount, (qb) => qb
494
+ * .innerJoin('pet', 'pet.owner_id', 'person.id')
495
+ * .having(count('pet.id'), '>', petCountLimit)
496
+ * .groupBy('person.id')
497
+ * )
498
+ * ```
499
+ */
500
+ if(condition, func) {
501
+ if (condition) {
502
+ return func(this);
503
+ }
504
+ return new SelectQueryBuilder({
505
+ ...this.#props,
506
+ });
507
+ }
462
508
  /**
463
509
  * Gives an alias for the query. This method is only useful for sub queries.
464
510
  *
@@ -488,6 +534,9 @@ export class SelectQueryBuilder {
488
534
  castTo() {
489
535
  return new SelectQueryBuilder(this.#props);
490
536
  }
537
+ /**
538
+ * Returns a copy of this SelectQueryBuilder instance with the given plugin installed.
539
+ */
491
540
  withPlugin(plugin) {
492
541
  return new SelectQueryBuilder({
493
542
  ...this.#props,
@@ -6,13 +6,14 @@ import { SelectExpression } from '../parser/select-parser.js';
6
6
  import { ExistsExpression, FilterOperator, FilterValueExpressionOrList, WhereGrouper } from '../parser/filter-parser.js';
7
7
  import { ReturningRow } from '../parser/returning-parser.js';
8
8
  import { ReferenceExpression } from '../parser/reference-parser.js';
9
- import { AnyRawBuilder, SingleResultType } from '../util/type-utils.js';
9
+ import { AnyRawBuilder, MergePartial, SingleResultType } from '../util/type-utils.js';
10
10
  import { UpdateQueryNode } from '../operation-node/update-query-node.js';
11
11
  import { MutationObject } from '../parser/update-set-parser.js';
12
12
  import { Compilable } from '../util/compilable.js';
13
13
  import { QueryExecutor } from '../query-executor/query-executor.js';
14
14
  import { QueryId } from '../util/query-id.js';
15
15
  import { ParseContext } from '../parser/parse-context.js';
16
+ import { UpdateResult } from './update-result.js';
16
17
  import { KyselyPlugin } from '../plugin/kysely-plugin.js';
17
18
  import { WhereInterface } from './where-interface.js';
18
19
  import { JoinInterface } from './join-interface.js';
@@ -676,24 +677,63 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
676
677
  /**
677
678
  * Simply calls the given function passing `this` as the only argument.
678
679
  *
679
- * This method can be useful when adding optional method calls:
680
+ * If you want to conditionally call a method on `this`, see
681
+ * the {@link if} method.
680
682
  *
681
683
  * ### Examples
682
684
  *
685
+ * The next example uses a helper funtion `log` to log a query:
686
+ *
683
687
  * ```ts
688
+ * function log<T extends Compilable>(qb: T): T {
689
+ * console.log(qb.compile())
690
+ * return qb
691
+ * }
692
+ *
684
693
  * db.updateTable('person')
685
694
  * .set(values)
686
- * .call((qb) => {
687
- * if (something) {
688
- * return qb.where('something', '=', something)
689
- * } else {
690
- * return qb.where('somethingElse', '=', somethingElse)
691
- * }
692
- * })
695
+ * .call(log)
693
696
  * .execute()
694
697
  * ```
695
698
  */
696
699
  call<T>(func: (qb: this) => T): T;
700
+ /**
701
+ * Call `func(this)` if `condition` is true.
702
+ *
703
+ * This method is especially handy with optional selects. Any `returning` or `returningAll`
704
+ * method calls add columns as optional fields to the output type when called inside
705
+ * the `func` callback. This is because we can't know if those selections were actually
706
+ * made before running the code.
707
+ *
708
+ * You can also call any other methods inside the callback.
709
+ *
710
+ * ### Examples
711
+ *
712
+ * ```ts
713
+ * async function updatePerson(id: number, updates: UpdateablePerson, returnLastName: boolean) {
714
+ * return await db
715
+ * .updateTable('person')
716
+ * .set(updates)
717
+ * .where('id', '=', id)
718
+ * .returning(['id', 'first_name'])
719
+ * .if(returnLastName, (qb) => qb.returning('last_name'))
720
+ * .executeTakeFirstOrThrow()
721
+ * }
722
+ * ```
723
+ *
724
+ * Any selections added inside the `if` callback will be added as optional fields to the
725
+ * output type since we can't know if the selections were actually made before running
726
+ * the code. In the example above the return type of the `updatePerson` function is:
727
+ *
728
+ * ```ts
729
+ * {
730
+ * id: number
731
+ * first_name: string
732
+ * last_name?: string
733
+ * }
734
+ * ```
735
+ */
736
+ if<O2>(condition: boolean, func: (qb: this) => UpdateQueryBuilder<DB, TB, O2>): UpdateQueryBuilder<DB, TB, O2 extends UpdateResult ? UpdateResult : O extends UpdateResult ? Partial<O2> : MergePartial<O, O2>>;
697
737
  /**
698
738
  * Change the output type of the query.
699
739
  *
@@ -701,6 +741,9 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
701
741
  * don't support your use case.
702
742
  */
703
743
  castTo<T>(): UpdateQueryBuilder<DB, TB, T>;
744
+ /**
745
+ * Returns a copy of this UpdateQueryBuilder instance with the given plugin installed.
746
+ */
704
747
  withPlugin(plugin: KyselyPlugin): UpdateQueryBuilder<DB, TB, O>;
705
748
  toOperationNode(): UpdateQueryNode;
706
749
  compile(): CompiledQuery;
@@ -192,26 +192,72 @@ export class UpdateQueryBuilder {
192
192
  /**
193
193
  * Simply calls the given function passing `this` as the only argument.
194
194
  *
195
- * This method can be useful when adding optional method calls:
195
+ * If you want to conditionally call a method on `this`, see
196
+ * the {@link if} method.
196
197
  *
197
198
  * ### Examples
198
199
  *
200
+ * The next example uses a helper funtion `log` to log a query:
201
+ *
199
202
  * ```ts
203
+ * function log<T extends Compilable>(qb: T): T {
204
+ * console.log(qb.compile())
205
+ * return qb
206
+ * }
207
+ *
200
208
  * db.updateTable('person')
201
209
  * .set(values)
202
- * .call((qb) => {
203
- * if (something) {
204
- * return qb.where('something', '=', something)
205
- * } else {
206
- * return qb.where('somethingElse', '=', somethingElse)
207
- * }
208
- * })
210
+ * .call(log)
209
211
  * .execute()
210
212
  * ```
211
213
  */
212
214
  call(func) {
213
215
  return func(this);
214
216
  }
217
+ /**
218
+ * Call `func(this)` if `condition` is true.
219
+ *
220
+ * This method is especially handy with optional selects. Any `returning` or `returningAll`
221
+ * method calls add columns as optional fields to the output type when called inside
222
+ * the `func` callback. This is because we can't know if those selections were actually
223
+ * made before running the code.
224
+ *
225
+ * You can also call any other methods inside the callback.
226
+ *
227
+ * ### Examples
228
+ *
229
+ * ```ts
230
+ * async function updatePerson(id: number, updates: UpdateablePerson, returnLastName: boolean) {
231
+ * return await db
232
+ * .updateTable('person')
233
+ * .set(updates)
234
+ * .where('id', '=', id)
235
+ * .returning(['id', 'first_name'])
236
+ * .if(returnLastName, (qb) => qb.returning('last_name'))
237
+ * .executeTakeFirstOrThrow()
238
+ * }
239
+ * ```
240
+ *
241
+ * Any selections added inside the `if` callback will be added as optional fields to the
242
+ * output type since we can't know if the selections were actually made before running
243
+ * the code. In the example above the return type of the `updatePerson` function is:
244
+ *
245
+ * ```ts
246
+ * {
247
+ * id: number
248
+ * first_name: string
249
+ * last_name?: string
250
+ * }
251
+ * ```
252
+ */
253
+ if(condition, func) {
254
+ if (condition) {
255
+ return func(this);
256
+ }
257
+ return new UpdateQueryBuilder({
258
+ ...this.#props,
259
+ });
260
+ }
215
261
  /**
216
262
  * Change the output type of the query.
217
263
  *
@@ -221,6 +267,9 @@ export class UpdateQueryBuilder {
221
267
  castTo() {
222
268
  return new UpdateQueryBuilder(this.#props);
223
269
  }
270
+ /**
271
+ * Returns a copy of this UpdateQueryBuilder instance with the given plugin installed.
272
+ */
224
273
  withPlugin(plugin) {
225
274
  return new UpdateQueryBuilder({
226
275
  ...this.#props,
@@ -162,7 +162,7 @@ export declare class QueryCreator<DB> {
162
162
  /**
163
163
  * Creates a delete query.
164
164
  *
165
- * See the {@link WhereInterface.where} method for examples on how to specify
165
+ * See the {@link DeleteQueryBuilder.where} method for examples on how to specify
166
166
  * a where clause for the delete operation.
167
167
  *
168
168
  * The return value of the query is an instance of {@link DeleteResult}.
@@ -182,7 +182,7 @@ export declare class QueryCreator<DB> {
182
182
  /**
183
183
  * Creates an update query.
184
184
  *
185
- * See the {@link WhereInterface.where} method for examples on how to specify
185
+ * See the {@link UpdateQueryBuilder.where} method for examples on how to specify
186
186
  * a where clause for the update operation.
187
187
  *
188
188
  * See the {@link UpdateQueryBuilder.set} method for examples on how to
@@ -76,7 +76,7 @@ export class QueryCreator {
76
76
  /**
77
77
  * Creates a delete query.
78
78
  *
79
- * See the {@link WhereInterface.where} method for examples on how to specify
79
+ * See the {@link DeleteQueryBuilder.where} method for examples on how to specify
80
80
  * a where clause for the delete operation.
81
81
  *
82
82
  * The return value of the query is an instance of {@link DeleteResult}.
@@ -103,7 +103,7 @@ export class QueryCreator {
103
103
  /**
104
104
  * Creates an update query.
105
105
  *
106
- * See the {@link WhereInterface.where} method for examples on how to specify
106
+ * See the {@link UpdateQueryBuilder.where} method for examples on how to specify
107
107
  * a where clause for the update operation.
108
108
  *
109
109
  * See the {@link UpdateQueryBuilder.set} method for examples on how to
@@ -3,7 +3,7 @@ import { preventAwait } from '../util/prevent-await.js';
3
3
  import { freeze } from '../util/object-utils.js';
4
4
  import { CreateViewNode } from '../operation-node/create-view-node.js';
5
5
  import { parseColumnName } from '../parser/reference-parser.js';
6
- import { ImmediateValuePlugin } from '../plugin/immediate-value.ts/immediate-value-plugin.js';
6
+ import { ImmediateValuePlugin } from '../plugin/immediate-value/immediate-value-plugin.js';
7
7
  export class CreateViewBuilder {
8
8
  #props;
9
9
  constructor(props) {
@@ -16,3 +16,4 @@ export declare function asArray<T>(arg: T | T[]): T[];
16
16
  export declare function asReadonlyArray<T>(arg: T | ReadonlyArray<T>): ReadonlyArray<T>;
17
17
  export declare function isReadonlyArray(arg: unknown): arg is ReadonlyArray<unknown>;
18
18
  export declare function noop<T>(obj: T): T;
19
+ export declare function compare(obj1: unknown, obj2: unknown): boolean;
@@ -65,3 +65,51 @@ export function isReadonlyArray(arg) {
65
65
  export function noop(obj) {
66
66
  return obj;
67
67
  }
68
+ export function compare(obj1, obj2) {
69
+ if (isReadonlyArray(obj1) && isReadonlyArray(obj2)) {
70
+ return compareArrays(obj1, obj2);
71
+ }
72
+ else if (isObject(obj1) && isObject(obj2)) {
73
+ return compareObjects(obj1, obj2);
74
+ }
75
+ return obj1 === obj2;
76
+ }
77
+ function compareArrays(arr1, arr2) {
78
+ if (arr1.length !== arr2.length) {
79
+ return false;
80
+ }
81
+ for (let i = 0; i < arr1.length; ++i) {
82
+ if (!compare(arr1[i], arr2[i])) {
83
+ return false;
84
+ }
85
+ }
86
+ return true;
87
+ }
88
+ function compareObjects(obj1, obj2) {
89
+ if (isBuffer(obj1) && isBuffer(obj2)) {
90
+ return compareBuffers(obj1, obj2);
91
+ }
92
+ else if (isDate(obj1) && isDate(obj2)) {
93
+ return compareDates(obj1, obj2);
94
+ }
95
+ return compareGenericObjects(obj1, obj2);
96
+ }
97
+ function compareBuffers(buf1, buf2) {
98
+ return Buffer.compare(buf1, buf2) === 0;
99
+ }
100
+ function compareDates(date1, date2) {
101
+ return date1.getTime() === date2.getTime();
102
+ }
103
+ function compareGenericObjects(obj1, obj2) {
104
+ const keys1 = Object.keys(obj1);
105
+ const keys2 = Object.keys(obj2);
106
+ if (keys1.length !== keys2.length) {
107
+ return false;
108
+ }
109
+ for (const key of keys1) {
110
+ if (!compare(obj1[key], obj2[key])) {
111
+ return false;
112
+ }
113
+ }
114
+ return true;
115
+ }
@@ -111,3 +111,24 @@ export declare type UnknownRow = Record<string, unknown>;
111
111
  export declare type Nullable<T> = {
112
112
  [P in keyof T]: T[P] | null;
113
113
  };
114
+ /**
115
+ * Takes all properties from T1 and merges all properties from T2
116
+ * that don't exist in T1 as optional properties.
117
+ *
118
+ * Example:
119
+ *
120
+ * interface Person {
121
+ * name: string
122
+ * age: number
123
+ * }
124
+ *
125
+ * interface Pet {
126
+ * name: string
127
+ * species: 'cat' | 'dog'
128
+ * }
129
+ *
130
+ * type Merged = MergePartial<Person, Pet>
131
+ *
132
+ * // { name: string, age: number, species?: 'cat' | 'dog' }
133
+ */
134
+ export declare type MergePartial<T1, T2> = T1 & Partial<Omit<T2, keyof T1>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kysely",
3
- "version": "0.16.6",
3
+ "version": "0.16.7",
4
4
  "description": "Type safe SQL query builder",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,9 +25,11 @@
25
25
  "test:node:build": "rm -rf test/node/dist && tsc -p test/node",
26
26
  "test:node": "mocha --timeout 15000 test/node/dist/**/*.test.js",
27
27
  "test:browser:build": "rm -rf test/browser/bundle.js && esbuild test/browser/main.ts --bundle --outfile=test/browser/bundle.js",
28
- "test:browser": "npm run clean && npm run build:esm && npm run test:browser:build && node test/browser/test.js",
28
+ "test:browser": "npm run build && npm run test:browser:build && node test/browser/test.js",
29
+ "test:deno": "npm run build && deno run test/deno/local.test.ts && deno run test/deno/cdn.test.ts",
29
30
  "test:typings": "tsd test/typings",
30
31
  "test:esmimports": "node scripts/check-esm-imports.js",
32
+ "test:esbuild": "esbuild --bundle --platform=node --external:pg-native dist/esm/index.js --outfile=/dev/null",
31
33
  "prettier": "prettier --write src/**/*.ts test/**/*.ts",
32
34
  "build": "npm run clean && npm run build:esm && npm run build:cjs && npm run script:module-fixup && npm run script:copy-interface-doc",
33
35
  "build:esm": "tsc -p tsconfig.json && npm run script:add-deno-type-references",