kysely 0.28.14 → 0.28.15

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.
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ var _a;
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.UpdateQueryBuilder = void 0;
4
5
  const join_parser_js_1 = require("../parser/join-parser.js");
@@ -21,19 +22,19 @@ class UpdateQueryBuilder {
21
22
  this.#props = (0, object_utils_js_1.freeze)(props);
22
23
  }
23
24
  where(...args) {
24
- return new UpdateQueryBuilder({
25
+ return new _a({
25
26
  ...this.#props,
26
27
  queryNode: query_node_js_1.QueryNode.cloneWithWhere(this.#props.queryNode, (0, binary_operation_parser_js_1.parseValueBinaryOperationOrExpression)(args)),
27
28
  });
28
29
  }
29
30
  whereRef(lhs, op, rhs) {
30
- return new UpdateQueryBuilder({
31
+ return new _a({
31
32
  ...this.#props,
32
33
  queryNode: query_node_js_1.QueryNode.cloneWithWhere(this.#props.queryNode, (0, binary_operation_parser_js_1.parseReferentialBinaryOperation)(lhs, op, rhs)),
33
34
  });
34
35
  }
35
36
  clearWhere() {
36
- return new UpdateQueryBuilder({
37
+ return new _a({
37
38
  ...this.#props,
38
39
  queryNode: query_node_js_1.QueryNode.cloneWithoutWhere(this.#props.queryNode),
39
40
  });
@@ -78,13 +79,13 @@ class UpdateQueryBuilder {
78
79
  * ```
79
80
  */
80
81
  top(expression, modifiers) {
81
- return new UpdateQueryBuilder({
82
+ return new _a({
82
83
  ...this.#props,
83
84
  queryNode: query_node_js_1.QueryNode.cloneWithTop(this.#props.queryNode, (0, top_parser_js_1.parseTop)(expression, modifiers)),
84
85
  });
85
86
  }
86
87
  from(from) {
87
- return new UpdateQueryBuilder({
88
+ return new _a({
88
89
  ...this.#props,
89
90
  queryNode: update_query_node_js_1.UpdateQueryNode.cloneWithFromItems(this.#props.queryNode, (0, table_parser_js_1.parseTableExpressionOrList)(from)),
90
91
  });
@@ -102,19 +103,19 @@ class UpdateQueryBuilder {
102
103
  return this.#join('FullJoin', args);
103
104
  }
104
105
  #join(joinType, args) {
105
- return new UpdateQueryBuilder({
106
+ return new _a({
106
107
  ...this.#props,
107
108
  queryNode: query_node_js_1.QueryNode.cloneWithJoin(this.#props.queryNode, (0, join_parser_js_1.parseJoin)(joinType, args)),
108
109
  });
109
110
  }
110
111
  orderBy(...args) {
111
- return new UpdateQueryBuilder({
112
+ return new _a({
112
113
  ...this.#props,
113
114
  queryNode: query_node_js_1.QueryNode.cloneWithOrderByItems(this.#props.queryNode, (0, order_by_parser_js_1.parseOrderBy)(args)),
114
115
  });
115
116
  }
116
117
  clearOrderBy() {
117
- return new UpdateQueryBuilder({
118
+ return new _a({
118
119
  ...this.#props,
119
120
  queryNode: query_node_js_1.QueryNode.cloneWithoutOrderBy(this.#props.queryNode),
120
121
  });
@@ -141,37 +142,37 @@ class UpdateQueryBuilder {
141
142
  * ```
142
143
  */
143
144
  limit(limit) {
144
- return new UpdateQueryBuilder({
145
+ return new _a({
145
146
  ...this.#props,
146
147
  queryNode: update_query_node_js_1.UpdateQueryNode.cloneWithLimit(this.#props.queryNode, limit_node_js_1.LimitNode.create((0, value_parser_js_1.parseValueExpression)(limit))),
147
148
  });
148
149
  }
149
150
  set(...args) {
150
- return new UpdateQueryBuilder({
151
+ return new _a({
151
152
  ...this.#props,
152
153
  queryNode: update_query_node_js_1.UpdateQueryNode.cloneWithUpdates(this.#props.queryNode, (0, update_set_parser_js_1.parseUpdate)(...args)),
153
154
  });
154
155
  }
155
156
  returning(selection) {
156
- return new UpdateQueryBuilder({
157
+ return new _a({
157
158
  ...this.#props,
158
159
  queryNode: query_node_js_1.QueryNode.cloneWithReturning(this.#props.queryNode, (0, select_parser_js_1.parseSelectArg)(selection)),
159
160
  });
160
161
  }
161
162
  returningAll(table) {
162
- return new UpdateQueryBuilder({
163
+ return new _a({
163
164
  ...this.#props,
164
165
  queryNode: query_node_js_1.QueryNode.cloneWithReturning(this.#props.queryNode, (0, select_parser_js_1.parseSelectAll)(table)),
165
166
  });
166
167
  }
167
168
  output(args) {
168
- return new UpdateQueryBuilder({
169
+ return new _a({
169
170
  ...this.#props,
170
171
  queryNode: query_node_js_1.QueryNode.cloneWithOutput(this.#props.queryNode, (0, select_parser_js_1.parseSelectArg)(args)),
171
172
  });
172
173
  }
173
174
  outputAll(table) {
174
- return new UpdateQueryBuilder({
175
+ return new _a({
175
176
  ...this.#props,
176
177
  queryNode: query_node_js_1.QueryNode.cloneWithOutput(this.#props.queryNode, (0, select_parser_js_1.parseSelectAll)(table)),
177
178
  });
@@ -200,7 +201,7 @@ class UpdateQueryBuilder {
200
201
  * ```
201
202
  */
202
203
  modifyEnd(modifier) {
203
- return new UpdateQueryBuilder({
204
+ return new _a({
204
205
  ...this.#props,
205
206
  queryNode: query_node_js_1.QueryNode.cloneWithEndModifier(this.#props.queryNode, modifier.toOperationNode()),
206
207
  });
@@ -225,7 +226,7 @@ class UpdateQueryBuilder {
225
226
  * ```
226
227
  */
227
228
  clearReturning() {
228
- return new UpdateQueryBuilder({
229
+ return new _a({
229
230
  ...this.#props,
230
231
  queryNode: query_node_js_1.QueryNode.cloneWithoutReturning(this.#props.queryNode),
231
232
  });
@@ -305,7 +306,7 @@ class UpdateQueryBuilder {
305
306
  if (condition) {
306
307
  return func(this);
307
308
  }
308
- return new UpdateQueryBuilder({
309
+ return new _a({
309
310
  ...this.#props,
310
311
  });
311
312
  }
@@ -316,7 +317,7 @@ class UpdateQueryBuilder {
316
317
  * returns a copy of this `UpdateQueryBuilder` with a new output type.
317
318
  */
318
319
  $castTo() {
319
- return new UpdateQueryBuilder(this.#props);
320
+ return new _a(this.#props);
320
321
  }
321
322
  /**
322
323
  * Narrows (parts of) the output type of the query.
@@ -377,7 +378,7 @@ class UpdateQueryBuilder {
377
378
  * ```
378
379
  */
379
380
  $narrowType() {
380
- return new UpdateQueryBuilder(this.#props);
381
+ return new _a(this.#props);
381
382
  }
382
383
  /**
383
384
  * Asserts that query's output row type equals the given type `T`.
@@ -434,13 +435,13 @@ class UpdateQueryBuilder {
434
435
  * ```
435
436
  */
436
437
  $assertType() {
437
- return new UpdateQueryBuilder(this.#props);
438
+ return new _a(this.#props);
438
439
  }
439
440
  /**
440
441
  * Returns a copy of this UpdateQueryBuilder instance with the given plugin installed.
441
442
  */
442
443
  withPlugin(plugin) {
443
- return new UpdateQueryBuilder({
444
+ return new _a({
444
445
  ...this.#props,
445
446
  executor: this.#props.executor.withPlugin(plugin),
446
447
  });
@@ -503,7 +504,7 @@ class UpdateQueryBuilder {
503
504
  }
504
505
  }
505
506
  async explain(format, options) {
506
- const builder = new UpdateQueryBuilder({
507
+ const builder = new _a({
507
508
  ...this.#props,
508
509
  queryNode: query_node_js_1.QueryNode.cloneWithExplain(this.#props.queryNode, format, options),
509
510
  });
@@ -511,3 +512,4 @@ class UpdateQueryBuilder {
511
512
  }
512
513
  }
513
514
  exports.UpdateQueryBuilder = UpdateQueryBuilder;
515
+ _a = UpdateQueryBuilder;
@@ -172,4 +172,58 @@ export type Insertable<R> = DrainOuterGeneric<object & {
172
172
  export type Updateable<R> = DrainOuterGeneric<{
173
173
  [K in UpdateKeys<R>]?: UpdateType<R[K]>;
174
174
  }>;
175
+ /**
176
+ * Wrap your column type to opt-out from dehydration by {@link ShallowDehydrateValue},
177
+ * when used by JSON functions, such as the ones used by the relational helpers.
178
+ *
179
+ * Why need this?
180
+ *
181
+ * An edge case surfaced in issues where a numeric string column type was actually
182
+ * not a numeric data type column, but text - and thus shouldn't be dehydrated
183
+ * to `number`.
184
+ *
185
+ * Another use case would be, when someone finds a way to keep nested columns hydrated
186
+ * at runtime, e.g. via a plugin, and wants to prevent dehydration of such columns
187
+ * at the type level.
188
+ *
189
+ * ### Examples
190
+ *
191
+ * ```ts
192
+ * import type { NonDehydrateable } from 'kysely'
193
+ * import { jsonArrayFrom } from 'kysely/helpers/postgres'
194
+ *
195
+ * const result = await db
196
+ * .withTables<{
197
+ * my_table: {
198
+ * a_column: '1' | '2' | '3',
199
+ * another_column: NonDehydrateable<'1' | '2' | '3'>,
200
+ * column_too: NonDehydrateable<ColumnType<'1' | '2' | '3'>>
201
+ * }
202
+ * }>()
203
+ * .selectFrom('person')
204
+ * .select((eb) => [
205
+ * 'id',
206
+ * jsonArrayFrom(
207
+ * eb.selectFrom('my_table')
208
+ * .select(['a_column', 'another_column', 'column_too'])
209
+ * ).as('related')
210
+ * ])
211
+ * .execute()
212
+ * ```
213
+ *
214
+ * In the example above, "a_column" will be dehydrated to `number`
215
+ * given it is a numeric string - which is normally a numeric data type column
216
+ * that gets output as a string by underlying database drivers to avoid
217
+ * precision loss or overflow.
218
+ *
219
+ * "another_column" and "column_too" will remain as `'1' | '2' | '3'`, given they're
220
+ * wrapped in `NonDehydrateable`, which prevents their dehydration.
221
+ */
222
+ export type NonDehydrateable<T> = [T] extends [
223
+ ColumnType<infer S, infer I, infer U>
224
+ ] ? ColumnType<S & {
225
+ __kysely_dehydrate__?: false;
226
+ }, I, U> : T & {
227
+ __kysely_dehydrate__?: false;
228
+ };
175
229
  export {};
@@ -183,7 +183,7 @@ export type ShallowDehydrateObject<O> = {
183
183
  * For now, we catch anything in {@link StringsWhenDataTypeNotAvailable} and convert it to `string`,
184
184
  * and anything in {@link NumbersWhenDataTypeNotAvailable} and convert it to `number`.
185
185
  */
186
- export type ShallowDehydrateValue<T> = T extends null | undefined ? T : T extends (infer U)[] | null | undefined ? Array<ShallowDehydrateValue<U>> | Extract<T, null | undefined> : Exclude<T, StringsWhenDataTypeNotAvailable | NumbersWhenDataTypeNotAvailable> | ([Extract<T, NumbersWhenDataTypeNotAvailable>] extends [never] ? never : number) | ([Extract<T, StringsWhenDataTypeNotAvailable>] extends [never] ? never : string);
186
+ export type ShallowDehydrateValue<T> = T extends null | undefined ? T : '__kysely_dehydrate__' extends keyof NonNullable<T> ? T : T extends (infer U)[] | null | undefined ? Array<ShallowDehydrateValue<U>> | Extract<T, null | undefined> : Exclude<T, StringsWhenDataTypeNotAvailable | NumbersWhenDataTypeNotAvailable> | ([Extract<T, NumbersWhenDataTypeNotAvailable>] extends [never] ? never : number) | ([Extract<T, StringsWhenDataTypeNotAvailable>] extends [never] ? never : string);
187
187
  export type StringsWhenDataTypeNotAvailable = Date | Uint8Array;
188
188
  export type NumbersWhenDataTypeNotAvailable = bigint | NumericString;
189
189
  export type NumericString = `${number}`;
@@ -71,27 +71,29 @@ export class PostgresIntrospector {
71
71
  };
72
72
  }
73
73
  #parseTableMetadata(columns) {
74
- return columns.reduce((tables, it) => {
75
- let table = tables.find((tbl) => tbl.name === it.table && tbl.schema === it.schema);
76
- if (!table) {
77
- table = freeze({
78
- name: it.table,
79
- isView: it.table_type === 'v',
80
- schema: it.schema,
74
+ const tableDictionary = new Map();
75
+ for (let i = 0, len = columns.length; i < len; i++) {
76
+ const column = columns[i];
77
+ const { schema, table } = column;
78
+ const tableKey = `schema:${schema};table:${table}`;
79
+ if (!tableDictionary.has(tableKey)) {
80
+ tableDictionary.set(tableKey, freeze({
81
81
  columns: [],
82
- });
83
- tables.push(table);
82
+ isView: column.table_type === 'v',
83
+ name: table,
84
+ schema,
85
+ }));
84
86
  }
85
- table.columns.push(freeze({
86
- name: it.column,
87
- dataType: it.type,
88
- dataTypeSchema: it.type_schema,
89
- isNullable: !it.not_null,
90
- isAutoIncrementing: it.auto_incrementing !== null,
91
- hasDefaultValue: it.has_default,
92
- comment: it.column_description ?? undefined,
87
+ tableDictionary.get(tableKey).columns.push(freeze({
88
+ comment: column.column_description ?? undefined,
89
+ dataType: column.type,
90
+ dataTypeSchema: column.type_schema,
91
+ hasDefaultValue: column.has_default,
92
+ isAutoIncrementing: column.auto_incrementing !== null,
93
+ isNullable: !column.not_null,
94
+ name: column.column,
93
95
  }));
94
- return tables;
95
- }, []);
96
+ }
97
+ return Array.from(tableDictionary.values());
96
98
  }
97
99
  }
@@ -1,4 +1,5 @@
1
1
  /// <reference types="./delete-query-builder.d.ts" />
2
+ var _a;
2
3
  import { parseJoin, } from '../parser/join-parser.js';
3
4
  import { parseTableExpressionOrList, } from '../parser/table-parser.js';
4
5
  import { parseSelectArg, parseSelectAll, } from '../parser/select-parser.js';
@@ -18,19 +19,19 @@ export class DeleteQueryBuilder {
18
19
  this.#props = freeze(props);
19
20
  }
20
21
  where(...args) {
21
- return new DeleteQueryBuilder({
22
+ return new _a({
22
23
  ...this.#props,
23
24
  queryNode: QueryNode.cloneWithWhere(this.#props.queryNode, parseValueBinaryOperationOrExpression(args)),
24
25
  });
25
26
  }
26
27
  whereRef(lhs, op, rhs) {
27
- return new DeleteQueryBuilder({
28
+ return new _a({
28
29
  ...this.#props,
29
30
  queryNode: QueryNode.cloneWithWhere(this.#props.queryNode, parseReferentialBinaryOperation(lhs, op, rhs)),
30
31
  });
31
32
  }
32
33
  clearWhere() {
33
- return new DeleteQueryBuilder({
34
+ return new _a({
34
35
  ...this.#props,
35
36
  queryNode: QueryNode.cloneWithoutWhere(this.#props.queryNode),
36
37
  });
@@ -75,13 +76,13 @@ export class DeleteQueryBuilder {
75
76
  * ```
76
77
  */
77
78
  top(expression, modifiers) {
78
- return new DeleteQueryBuilder({
79
+ return new _a({
79
80
  ...this.#props,
80
81
  queryNode: QueryNode.cloneWithTop(this.#props.queryNode, parseTop(expression, modifiers)),
81
82
  });
82
83
  }
83
84
  using(tables) {
84
- return new DeleteQueryBuilder({
85
+ return new _a({
85
86
  ...this.#props,
86
87
  queryNode: DeleteQueryNode.cloneWithUsing(this.#props.queryNode, parseTableExpressionOrList(tables)),
87
88
  });
@@ -99,31 +100,31 @@ export class DeleteQueryBuilder {
99
100
  return this.#join('FullJoin', args);
100
101
  }
101
102
  #join(joinType, args) {
102
- return new DeleteQueryBuilder({
103
+ return new _a({
103
104
  ...this.#props,
104
105
  queryNode: QueryNode.cloneWithJoin(this.#props.queryNode, parseJoin(joinType, args)),
105
106
  });
106
107
  }
107
108
  returning(selection) {
108
- return new DeleteQueryBuilder({
109
+ return new _a({
109
110
  ...this.#props,
110
111
  queryNode: QueryNode.cloneWithReturning(this.#props.queryNode, parseSelectArg(selection)),
111
112
  });
112
113
  }
113
114
  returningAll(table) {
114
- return new DeleteQueryBuilder({
115
+ return new _a({
115
116
  ...this.#props,
116
117
  queryNode: QueryNode.cloneWithReturning(this.#props.queryNode, parseSelectAll(table)),
117
118
  });
118
119
  }
119
120
  output(args) {
120
- return new DeleteQueryBuilder({
121
+ return new _a({
121
122
  ...this.#props,
122
123
  queryNode: QueryNode.cloneWithOutput(this.#props.queryNode, parseSelectArg(args)),
123
124
  });
124
125
  }
125
126
  outputAll(table) {
126
- return new DeleteQueryBuilder({
127
+ return new _a({
127
128
  ...this.#props,
128
129
  queryNode: QueryNode.cloneWithOutput(this.#props.queryNode, parseSelectAll(table)),
129
130
  });
@@ -148,7 +149,7 @@ export class DeleteQueryBuilder {
148
149
  * ```
149
150
  */
150
151
  clearReturning() {
151
- return new DeleteQueryBuilder({
152
+ return new _a({
152
153
  ...this.#props,
153
154
  queryNode: QueryNode.cloneWithoutReturning(this.#props.queryNode),
154
155
  });
@@ -174,19 +175,19 @@ export class DeleteQueryBuilder {
174
175
  * ```
175
176
  */
176
177
  clearLimit() {
177
- return new DeleteQueryBuilder({
178
+ return new _a({
178
179
  ...this.#props,
179
180
  queryNode: DeleteQueryNode.cloneWithoutLimit(this.#props.queryNode),
180
181
  });
181
182
  }
182
183
  orderBy(...args) {
183
- return new DeleteQueryBuilder({
184
+ return new _a({
184
185
  ...this.#props,
185
186
  queryNode: QueryNode.cloneWithOrderByItems(this.#props.queryNode, parseOrderBy(args)),
186
187
  });
187
188
  }
188
189
  clearOrderBy() {
189
- return new DeleteQueryBuilder({
190
+ return new _a({
190
191
  ...this.#props,
191
192
  queryNode: QueryNode.cloneWithoutOrderBy(this.#props.queryNode),
192
193
  });
@@ -216,7 +217,7 @@ export class DeleteQueryBuilder {
216
217
  * ```
217
218
  */
218
219
  limit(limit) {
219
- return new DeleteQueryBuilder({
220
+ return new _a({
220
221
  ...this.#props,
221
222
  queryNode: DeleteQueryNode.cloneWithLimit(this.#props.queryNode, LimitNode.create(parseValueExpression(limit))),
222
223
  });
@@ -243,7 +244,7 @@ export class DeleteQueryBuilder {
243
244
  * ```
244
245
  */
245
246
  modifyEnd(modifier) {
246
- return new DeleteQueryBuilder({
247
+ return new _a({
247
248
  ...this.#props,
248
249
  queryNode: QueryNode.cloneWithEndModifier(this.#props.queryNode, modifier.toOperationNode()),
249
250
  });
@@ -314,7 +315,7 @@ export class DeleteQueryBuilder {
314
315
  if (condition) {
315
316
  return func(this);
316
317
  }
317
- return new DeleteQueryBuilder({
318
+ return new _a({
318
319
  ...this.#props,
319
320
  });
320
321
  }
@@ -325,7 +326,7 @@ export class DeleteQueryBuilder {
325
326
  * returns a copy of this `DeleteQueryBuilder` with a new output type.
326
327
  */
327
328
  $castTo() {
328
- return new DeleteQueryBuilder(this.#props);
329
+ return new _a(this.#props);
329
330
  }
330
331
  /**
331
332
  * Narrows (parts of) the output type of the query.
@@ -377,7 +378,7 @@ export class DeleteQueryBuilder {
377
378
  * ```
378
379
  */
379
380
  $narrowType() {
380
- return new DeleteQueryBuilder(this.#props);
381
+ return new _a(this.#props);
381
382
  }
382
383
  /**
383
384
  * Asserts that query's output row type equals the given type `T`.
@@ -425,13 +426,13 @@ export class DeleteQueryBuilder {
425
426
  * ```
426
427
  */
427
428
  $assertType() {
428
- return new DeleteQueryBuilder(this.#props);
429
+ return new _a(this.#props);
429
430
  }
430
431
  /**
431
432
  * Returns a copy of this DeleteQueryBuilder instance with the given plugin installed.
432
433
  */
433
434
  withPlugin(plugin) {
434
- return new DeleteQueryBuilder({
435
+ return new _a({
435
436
  ...this.#props,
436
437
  executor: this.#props.executor.withPlugin(plugin),
437
438
  });
@@ -492,10 +493,11 @@ export class DeleteQueryBuilder {
492
493
  }
493
494
  }
494
495
  async explain(format, options) {
495
- const builder = new DeleteQueryBuilder({
496
+ const builder = new _a({
496
497
  ...this.#props,
497
498
  queryNode: QueryNode.cloneWithExplain(this.#props.queryNode, format, options),
498
499
  });
499
500
  return await builder.execute();
500
501
  }
501
502
  }
503
+ _a = DeleteQueryBuilder;