kysely 0.28.6 → 0.28.8

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.
@@ -50,6 +50,8 @@ class PostgresIntrospector {
50
50
  .where('ns.nspname', '!=', 'information_schema')
51
51
  // Filter out internal cockroachdb schema
52
52
  .where('ns.nspname', '!=', 'crdb_internal')
53
+ // Only schemas where we are allowed access
54
+ .where((0, sql_js_1.sql) `has_schema_privilege(ns.nspname, 'USAGE')`)
53
55
  // No system columns
54
56
  .where('a.attnum', '>=', 0)
55
57
  .where('a.attisdropped', '!=', true)
@@ -108,7 +108,7 @@ export interface ExpressionBuilder<DB, TB extends keyof DB> {
108
108
  * )
109
109
  * ```
110
110
  */
111
- <RE extends ReferenceExpression<DB, TB>, OP extends BinaryOperatorExpression, VE extends OperandValueExpressionOrList<DB, TB, RE>>(lhs: RE, op: OP, rhs: VE): ExpressionWrapper<DB, TB, OP extends ComparisonOperator ? SqlBool : ExtractTypeFromReferenceExpression<DB, TB, RE>>;
111
+ <RE extends ReferenceExpression<DB, TB>, OP extends BinaryOperatorExpression, VE extends OperandValueExpressionOrList<DB, TB, RE>>(lhs: RE, op: OP, rhs: VE): ExpressionWrapper<DB, TB, OP extends ComparisonOperator ? SqlBool : OP extends Expression<infer T> ? unknown extends T ? SqlBool : T : ExtractTypeFromReferenceExpression<DB, TB, RE>>;
112
112
  /**
113
113
  * Returns a copy of `this` expression builder, for destructuring purposes.
114
114
  *
@@ -50,6 +50,8 @@ export * from './schema/refresh-materialized-view-builder.js';
50
50
  export * from './schema/drop-view-builder.js';
51
51
  export * from './schema/alter-column-builder.js';
52
52
  export * from './dynamic/dynamic.js';
53
+ export * from './dynamic/dynamic-reference-builder.js';
54
+ export * from './dynamic/dynamic-table-builder.js';
53
55
  export * from './driver/driver.js';
54
56
  export * from './driver/database-connection.js';
55
57
  export * from './driver/connection-provider.js';
package/dist/cjs/index.js CHANGED
@@ -68,6 +68,8 @@ __exportStar(require("./schema/refresh-materialized-view-builder.js"), exports);
68
68
  __exportStar(require("./schema/drop-view-builder.js"), exports);
69
69
  __exportStar(require("./schema/alter-column-builder.js"), exports);
70
70
  __exportStar(require("./dynamic/dynamic.js"), exports);
71
+ __exportStar(require("./dynamic/dynamic-reference-builder.js"), exports);
72
+ __exportStar(require("./dynamic/dynamic-table-builder.js"), exports);
71
73
  __exportStar(require("./driver/driver.js"), exports);
72
74
  __exportStar(require("./driver/database-connection.js"), exports);
73
75
  __exportStar(require("./driver/connection-provider.js"), exports);
@@ -570,14 +570,18 @@ class TransactionBuilder {
570
570
  ...kyselyProps,
571
571
  executor,
572
572
  });
573
+ let transactionBegun = false;
573
574
  try {
574
575
  await this.#props.driver.beginTransaction(connection, settings);
576
+ transactionBegun = true;
575
577
  const result = await callback(transaction);
576
578
  await this.#props.driver.commitTransaction(connection);
577
579
  return result;
578
580
  }
579
581
  catch (error) {
580
- await this.#props.driver.rollbackTransaction(connection);
582
+ if (transactionBegun) {
583
+ await this.#props.driver.rollbackTransaction(connection);
584
+ }
581
585
  throw error;
582
586
  }
583
587
  });
@@ -340,12 +340,12 @@ export interface MigrationResult {
340
340
  * The execution status.
341
341
  *
342
342
  * - `Success` means the migration was successfully executed. Note that
343
- * if any of the later migrations in the {@link MigrationResult.results}
343
+ * if any of the later migrations in the {@link MigrationResultSet.results}
344
344
  * list failed (have status `Error`) AND the dialect supports transactional
345
345
  * DDL, even the successfull migrations were rolled back.
346
346
  *
347
347
  * - `Error` means the migration failed. In this case the
348
- * {@link MigrationResult.error} contains the error.
348
+ * {@link MigrationResultSet.error} contains the error.
349
349
  *
350
350
  * - `NotExecuted` means that the migration was supposed to be executed
351
351
  * but wasn't because an earlier migration failed.
@@ -6,11 +6,11 @@ const insert_query_node_js_1 = require("../operation-node/insert-query-node.js")
6
6
  const operation_node_visitor_js_1 = require("../operation-node/operation-node-visitor.js");
7
7
  const operator_node_js_1 = require("../operation-node/operator-node.js");
8
8
  const parens_node_js_1 = require("../operation-node/parens-node.js");
9
- const query_node_js_1 = require("../operation-node/query-node.js");
9
+ const raw_node_js_1 = require("../operation-node/raw-node.js");
10
10
  const object_utils_js_1 = require("../util/object-utils.js");
11
11
  const create_view_node_js_1 = require("../operation-node/create-view-node.js");
12
12
  const set_operation_node_js_1 = require("../operation-node/set-operation-node.js");
13
- const merge_query_node_js_1 = require("../operation-node/merge-query-node.js");
13
+ const when_node_js_1 = require("../operation-node/when-node.js");
14
14
  const log_once_js_1 = require("../util/log-once.js");
15
15
  const LIT_WRAP_REGEX = /'/g;
16
16
  class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisitor {
@@ -150,13 +150,15 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
150
150
  this.visitNode(node.having);
151
151
  }
152
152
  visitInsertQuery(node) {
153
- const rootQueryNode = this.nodeStack.find(query_node_js_1.QueryNode.is);
154
- const isSubQuery = rootQueryNode !== node;
155
- if (!isSubQuery && node.explain) {
153
+ const wrapInParens = this.parentNode !== undefined &&
154
+ !parens_node_js_1.ParensNode.is(this.parentNode) &&
155
+ !raw_node_js_1.RawNode.is(this.parentNode) &&
156
+ !when_node_js_1.WhenNode.is(this.parentNode);
157
+ if (this.parentNode === undefined && node.explain) {
156
158
  this.visitNode(node.explain);
157
159
  this.append(' ');
158
160
  }
159
- if (isSubQuery && !merge_query_node_js_1.MergeQueryNode.is(rootQueryNode)) {
161
+ if (wrapInParens) {
160
162
  this.append('(');
161
163
  }
162
164
  if (node.with) {
@@ -210,7 +212,7 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
210
212
  this.append(' ');
211
213
  this.visitNode(node.returning);
212
214
  }
213
- if (isSubQuery && !merge_query_node_js_1.MergeQueryNode.is(rootQueryNode)) {
215
+ if (wrapInParens) {
214
216
  this.append(')');
215
217
  }
216
218
  if (node.endModifiers?.length) {
@@ -223,12 +225,14 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
223
225
  this.compileList(node.values);
224
226
  }
225
227
  visitDeleteQuery(node) {
226
- const isSubQuery = this.nodeStack.find(query_node_js_1.QueryNode.is) !== node;
227
- if (!isSubQuery && node.explain) {
228
+ const wrapInParens = this.parentNode !== undefined &&
229
+ !parens_node_js_1.ParensNode.is(this.parentNode) &&
230
+ !raw_node_js_1.RawNode.is(this.parentNode);
231
+ if (this.parentNode === undefined && node.explain) {
228
232
  this.visitNode(node.explain);
229
233
  this.append(' ');
230
234
  }
231
- if (isSubQuery) {
235
+ if (wrapInParens) {
232
236
  this.append('(');
233
237
  }
234
238
  if (node.with) {
@@ -269,7 +273,7 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
269
273
  this.append(' ');
270
274
  this.visitNode(node.returning);
271
275
  }
272
- if (isSubQuery) {
276
+ if (wrapInParens) {
273
277
  this.append(')');
274
278
  }
275
279
  if (node.endModifiers?.length) {
@@ -530,13 +534,15 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
530
534
  this.visitNode(node.groupBy);
531
535
  }
532
536
  visitUpdateQuery(node) {
533
- const rootQueryNode = this.nodeStack.find(query_node_js_1.QueryNode.is);
534
- const isSubQuery = rootQueryNode !== node;
535
- if (!isSubQuery && node.explain) {
537
+ const wrapInParens = this.parentNode !== undefined &&
538
+ !parens_node_js_1.ParensNode.is(this.parentNode) &&
539
+ !raw_node_js_1.RawNode.is(this.parentNode) &&
540
+ !when_node_js_1.WhenNode.is(this.parentNode);
541
+ if (this.parentNode === undefined && node.explain) {
536
542
  this.visitNode(node.explain);
537
543
  this.append(' ');
538
544
  }
539
- if (isSubQuery && !merge_query_node_js_1.MergeQueryNode.is(rootQueryNode)) {
545
+ if (wrapInParens) {
540
546
  this.append('(');
541
547
  }
542
548
  if (node.with) {
@@ -587,7 +593,7 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
587
593
  this.append(' ');
588
594
  this.visitNode(node.returning);
589
595
  }
590
- if (isSubQuery && !merge_query_node_js_1.MergeQueryNode.is(rootQueryNode)) {
596
+ if (wrapInParens) {
591
597
  this.append(')');
592
598
  }
593
599
  if (node.endModifiers?.length) {
@@ -48,6 +48,8 @@ export class PostgresIntrospector {
48
48
  .where('ns.nspname', '!=', 'information_schema')
49
49
  // Filter out internal cockroachdb schema
50
50
  .where('ns.nspname', '!=', 'crdb_internal')
51
+ // Only schemas where we are allowed access
52
+ .where(sql `has_schema_privilege(ns.nspname, 'USAGE')`)
51
53
  // No system columns
52
54
  .where('a.attnum', '>=', 0)
53
55
  .where('a.attisdropped', '!=', true)
@@ -108,7 +108,7 @@ export interface ExpressionBuilder<DB, TB extends keyof DB> {
108
108
  * )
109
109
  * ```
110
110
  */
111
- <RE extends ReferenceExpression<DB, TB>, OP extends BinaryOperatorExpression, VE extends OperandValueExpressionOrList<DB, TB, RE>>(lhs: RE, op: OP, rhs: VE): ExpressionWrapper<DB, TB, OP extends ComparisonOperator ? SqlBool : ExtractTypeFromReferenceExpression<DB, TB, RE>>;
111
+ <RE extends ReferenceExpression<DB, TB>, OP extends BinaryOperatorExpression, VE extends OperandValueExpressionOrList<DB, TB, RE>>(lhs: RE, op: OP, rhs: VE): ExpressionWrapper<DB, TB, OP extends ComparisonOperator ? SqlBool : OP extends Expression<infer T> ? unknown extends T ? SqlBool : T : ExtractTypeFromReferenceExpression<DB, TB, RE>>;
112
112
  /**
113
113
  * Returns a copy of `this` expression builder, for destructuring purposes.
114
114
  *
@@ -50,6 +50,8 @@ export * from './schema/refresh-materialized-view-builder.js';
50
50
  export * from './schema/drop-view-builder.js';
51
51
  export * from './schema/alter-column-builder.js';
52
52
  export * from './dynamic/dynamic.js';
53
+ export * from './dynamic/dynamic-reference-builder.js';
54
+ export * from './dynamic/dynamic-table-builder.js';
53
55
  export * from './driver/driver.js';
54
56
  export * from './driver/database-connection.js';
55
57
  export * from './driver/connection-provider.js';
package/dist/esm/index.js CHANGED
@@ -51,6 +51,8 @@ export * from './schema/refresh-materialized-view-builder.js';
51
51
  export * from './schema/drop-view-builder.js';
52
52
  export * from './schema/alter-column-builder.js';
53
53
  export * from './dynamic/dynamic.js';
54
+ export * from './dynamic/dynamic-reference-builder.js';
55
+ export * from './dynamic/dynamic-table-builder.js';
54
56
  export * from './driver/driver.js';
55
57
  export * from './driver/database-connection.js';
56
58
  export * from './driver/connection-provider.js';
@@ -564,14 +564,18 @@ export class TransactionBuilder {
564
564
  ...kyselyProps,
565
565
  executor,
566
566
  });
567
+ let transactionBegun = false;
567
568
  try {
568
569
  await this.#props.driver.beginTransaction(connection, settings);
570
+ transactionBegun = true;
569
571
  const result = await callback(transaction);
570
572
  await this.#props.driver.commitTransaction(connection);
571
573
  return result;
572
574
  }
573
575
  catch (error) {
574
- await this.#props.driver.rollbackTransaction(connection);
576
+ if (transactionBegun) {
577
+ await this.#props.driver.rollbackTransaction(connection);
578
+ }
575
579
  throw error;
576
580
  }
577
581
  });
@@ -340,12 +340,12 @@ export interface MigrationResult {
340
340
  * The execution status.
341
341
  *
342
342
  * - `Success` means the migration was successfully executed. Note that
343
- * if any of the later migrations in the {@link MigrationResult.results}
343
+ * if any of the later migrations in the {@link MigrationResultSet.results}
344
344
  * list failed (have status `Error`) AND the dialect supports transactional
345
345
  * DDL, even the successfull migrations were rolled back.
346
346
  *
347
347
  * - `Error` means the migration failed. In this case the
348
- * {@link MigrationResult.error} contains the error.
348
+ * {@link MigrationResultSet.error} contains the error.
349
349
  *
350
350
  * - `NotExecuted` means that the migration was supposed to be executed
351
351
  * but wasn't because an earlier migration failed.
@@ -4,11 +4,11 @@ import { InsertQueryNode } from '../operation-node/insert-query-node.js';
4
4
  import { OperationNodeVisitor } from '../operation-node/operation-node-visitor.js';
5
5
  import { OperatorNode } from '../operation-node/operator-node.js';
6
6
  import { ParensNode } from '../operation-node/parens-node.js';
7
- import { QueryNode } from '../operation-node/query-node.js';
7
+ import { RawNode } from '../operation-node/raw-node.js';
8
8
  import { freeze, isString, isNumber, isBoolean, isNull, isDate, isBigInt, } from '../util/object-utils.js';
9
9
  import { CreateViewNode } from '../operation-node/create-view-node.js';
10
10
  import { SetOperationNode } from '../operation-node/set-operation-node.js';
11
- import { MergeQueryNode } from '../operation-node/merge-query-node.js';
11
+ import { WhenNode } from '../operation-node/when-node.js';
12
12
  import { logOnce } from '../util/log-once.js';
13
13
  const LIT_WRAP_REGEX = /'/g;
14
14
  export class DefaultQueryCompiler extends OperationNodeVisitor {
@@ -148,13 +148,15 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
148
148
  this.visitNode(node.having);
149
149
  }
150
150
  visitInsertQuery(node) {
151
- const rootQueryNode = this.nodeStack.find(QueryNode.is);
152
- const isSubQuery = rootQueryNode !== node;
153
- if (!isSubQuery && node.explain) {
151
+ const wrapInParens = this.parentNode !== undefined &&
152
+ !ParensNode.is(this.parentNode) &&
153
+ !RawNode.is(this.parentNode) &&
154
+ !WhenNode.is(this.parentNode);
155
+ if (this.parentNode === undefined && node.explain) {
154
156
  this.visitNode(node.explain);
155
157
  this.append(' ');
156
158
  }
157
- if (isSubQuery && !MergeQueryNode.is(rootQueryNode)) {
159
+ if (wrapInParens) {
158
160
  this.append('(');
159
161
  }
160
162
  if (node.with) {
@@ -208,7 +210,7 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
208
210
  this.append(' ');
209
211
  this.visitNode(node.returning);
210
212
  }
211
- if (isSubQuery && !MergeQueryNode.is(rootQueryNode)) {
213
+ if (wrapInParens) {
212
214
  this.append(')');
213
215
  }
214
216
  if (node.endModifiers?.length) {
@@ -221,12 +223,14 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
221
223
  this.compileList(node.values);
222
224
  }
223
225
  visitDeleteQuery(node) {
224
- const isSubQuery = this.nodeStack.find(QueryNode.is) !== node;
225
- if (!isSubQuery && node.explain) {
226
+ const wrapInParens = this.parentNode !== undefined &&
227
+ !ParensNode.is(this.parentNode) &&
228
+ !RawNode.is(this.parentNode);
229
+ if (this.parentNode === undefined && node.explain) {
226
230
  this.visitNode(node.explain);
227
231
  this.append(' ');
228
232
  }
229
- if (isSubQuery) {
233
+ if (wrapInParens) {
230
234
  this.append('(');
231
235
  }
232
236
  if (node.with) {
@@ -267,7 +271,7 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
267
271
  this.append(' ');
268
272
  this.visitNode(node.returning);
269
273
  }
270
- if (isSubQuery) {
274
+ if (wrapInParens) {
271
275
  this.append(')');
272
276
  }
273
277
  if (node.endModifiers?.length) {
@@ -528,13 +532,15 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
528
532
  this.visitNode(node.groupBy);
529
533
  }
530
534
  visitUpdateQuery(node) {
531
- const rootQueryNode = this.nodeStack.find(QueryNode.is);
532
- const isSubQuery = rootQueryNode !== node;
533
- if (!isSubQuery && node.explain) {
535
+ const wrapInParens = this.parentNode !== undefined &&
536
+ !ParensNode.is(this.parentNode) &&
537
+ !RawNode.is(this.parentNode) &&
538
+ !WhenNode.is(this.parentNode);
539
+ if (this.parentNode === undefined && node.explain) {
534
540
  this.visitNode(node.explain);
535
541
  this.append(' ');
536
542
  }
537
- if (isSubQuery && !MergeQueryNode.is(rootQueryNode)) {
543
+ if (wrapInParens) {
538
544
  this.append('(');
539
545
  }
540
546
  if (node.with) {
@@ -585,7 +591,7 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
585
591
  this.append(' ');
586
592
  this.visitNode(node.returning);
587
593
  }
588
- if (isSubQuery && !MergeQueryNode.is(rootQueryNode)) {
594
+ if (wrapInParens) {
589
595
  this.append(')');
590
596
  }
591
597
  if (node.endModifiers?.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kysely",
3
- "version": "0.28.6",
3
+ "version": "0.28.8",
4
4
  "description": "Type safe SQL query builder",
5
5
  "repository": {
6
6
  "type": "git",
@@ -81,31 +81,31 @@
81
81
  "@types/chai": "^5.0.1",
82
82
  "@types/chai-as-promised": "^8.0.2",
83
83
  "@types/mocha": "^10.0.10",
84
- "@types/node": "^24.3.3",
84
+ "@types/node": "^24.7.0",
85
85
  "@types/pg": "^8.15.5",
86
86
  "@types/pg-cursor": "^2.7.2",
87
87
  "@types/semver": "^7.7.1",
88
88
  "@types/sinon": "^17.0.4",
89
- "better-sqlite3": "^12.2.0",
90
- "chai": "^6.0.1",
89
+ "better-sqlite3": "^12.4.1",
90
+ "chai": "^6.2.0",
91
91
  "chai-as-promised": "^8.0.2",
92
- "esbuild": "^0.25.9",
92
+ "esbuild": "^0.25.10",
93
93
  "lodash": "^4.17.21",
94
- "mocha": "^11.7.2",
95
- "mysql2": "^3.14.5",
94
+ "mocha": "^11.7.4",
95
+ "mysql2": "^3.15.1",
96
96
  "pathe": "^2.0.3",
97
97
  "pg": "^8.15.6",
98
98
  "pg-cursor": "^2.14.6",
99
99
  "pkg-types": "^2.3.0",
100
- "playwright": "^1.55.0",
100
+ "playwright": "^1.56.0",
101
101
  "prettier": "^3.5.3",
102
- "semver": "^7.7.1",
102
+ "semver": "^7.7.3",
103
103
  "sinon": "^21.0.0",
104
104
  "std-env": "^3.9.0",
105
105
  "tarn": "^3.0.2",
106
106
  "tedious": "^19.0.0",
107
107
  "tsd": "^0.33.0",
108
- "typescript": "~5.9.2"
108
+ "typescript": "~5.9.3"
109
109
  },
110
110
  "scripts": {
111
111
  "clean": "rm -rf dist & rm -rf test/node/dist & rm -rf test/browser/bundle.js & rm -rf helpers",