kysely 0.11.1 → 0.11.2

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.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SqliteDriver = void 0;
4
4
  const compiled_query_js_1 = require("../../query-compiler/compiled-query.js");
5
5
  const dynamic_import_js_1 = require("../../util/dynamic-import.js");
6
+ const object_utils_js_1 = require("../../util/object-utils.js");
6
7
  class SqliteDriver {
7
8
  #config;
8
9
  #connectionMutex = new ConnectionMutex();
@@ -19,16 +20,16 @@ class SqliteDriver {
19
20
  // into javascript. You can check the built javascript code.
20
21
  const DatabaseConstructor = await importBetterSqlite3Database();
21
22
  const options = {};
22
- if (typeof this.#config.readonly === 'boolean') {
23
+ if ((0, object_utils_js_1.isBoolean)(this.#config.readonly)) {
23
24
  options.readonly = this.#config.readonly;
24
25
  }
25
- if (typeof this.#config.fileMustExist === 'boolean') {
26
+ if ((0, object_utils_js_1.isBoolean)(this.#config.fileMustExist)) {
26
27
  options.fileMustExist = this.#config.fileMustExist;
27
28
  }
28
- if (typeof this.#config.timeout === 'number') {
29
+ if ((0, object_utils_js_1.isNumber)(this.#config.timeout)) {
29
30
  options.timeout = this.#config.timeout;
30
31
  }
31
- if (typeof this.#config.verbose === 'function') {
32
+ if ((0, object_utils_js_1.isFunction)(this.#config.verbose)) {
32
33
  options.verbose = this.#config.verbose;
33
34
  }
34
35
  this.#db = new DatabaseConstructor(this.#config.databasePath, options);
@@ -38,8 +39,8 @@ class SqliteDriver {
38
39
  }
39
40
  }
40
41
  async acquireConnection() {
41
- // sqlite effectively only has one single connection. We use a mutex
42
- // here to wait until the single connection has been released.
42
+ // SQLite only has one single connection. We use a mutex here to wait
43
+ // until the single connection has been released.
43
44
  await this.#connectionMutex.lock();
44
45
  return this.#connection;
45
46
  }
@@ -65,7 +66,6 @@ async function importBetterSqlite3Database() {
65
66
  return await (0, dynamic_import_js_1.importFunction)('better-sqlite3');
66
67
  }
67
68
  catch (error) {
68
- console.error(error);
69
69
  throw new Error('SQLite client not installed. Please run `npm install better-sqlite3`');
70
70
  }
71
71
  }
@@ -51,35 +51,8 @@ export * from './migration/migration.js';
51
51
  export * from './dialect/dialect.js';
52
52
  export * from './dialect/dialect-adapter.js';
53
53
  export * from './dialect/dialect-adapter-base.js';
54
- export * from './operation-node/operation-node-transformer.js';
55
- export * from './operation-node/operation-node-visitor.js';
56
54
  export * from './plugin/kysely-plugin.js';
57
55
  export * from './plugin/camel-case/camel-case-plugin.js';
58
- export * from './operation-node/operation-node-transformer.js';
59
- export * from './operation-node/operation-node-visitor.js';
60
- export * from './operation-node/operator-node.js';
61
- export * from './operation-node/or-node.js';
62
- export * from './operation-node/order-by-item-node.js';
63
- export * from './operation-node/order-by-node.js';
64
- export * from './operation-node/parens-node.js';
65
- export * from './operation-node/primary-constraint-node.js';
66
- export * from './operation-node/primitive-value-list-node.js';
67
- export * from './operation-node/query-node.js';
68
- export * from './operation-node/raw-node.js';
69
- export * from './operation-node/reference-node.js';
70
- export * from './operation-node/references-node.js';
71
- export * from './operation-node/rename-column-node.js';
72
- export * from './operation-node/returning-node.js';
73
- export * from './operation-node/select-all-node.js';
74
- export * from './operation-node/select-query-node.js';
75
- export * from './operation-node/selection-node.js';
76
- export * from './operation-node/table-node.js';
77
- export * from './operation-node/unique-constraint-node.js';
78
- export * from './operation-node/update-query-node.js';
79
- export * from './operation-node/value-list-node.js';
80
- export * from './operation-node/value-node.js';
81
- export * from './operation-node/where-node.js';
82
- export * from './operation-node/with-node.js';
83
56
  export * from './operation-node/add-column-node.js';
84
57
  export * from './operation-node/add-constraint-node.js';
85
58
  export * from './operation-node/alias-node.js';
@@ -95,16 +68,20 @@ export * from './operation-node/constraint-node.js';
95
68
  export * from './operation-node/create-index-node.js';
96
69
  export * from './operation-node/create-schema-node.js';
97
70
  export * from './operation-node/create-table-node.js';
71
+ export * from './operation-node/create-view-node.js';
98
72
  export * from './operation-node/data-type-node.js';
73
+ export * from './operation-node/default-value-node.js';
99
74
  export * from './operation-node/delete-query-node.js';
100
75
  export * from './operation-node/drop-column-node.js';
101
76
  export * from './operation-node/drop-constraint-node.js';
102
77
  export * from './operation-node/drop-index-node.js';
103
78
  export * from './operation-node/drop-schema-node.js';
104
79
  export * from './operation-node/drop-table-node.js';
80
+ export * from './operation-node/drop-view-node.js';
105
81
  export * from './operation-node/filter-node.js';
106
82
  export * from './operation-node/foreign-key-constraint-node.js';
107
83
  export * from './operation-node/from-node.js';
84
+ export * from './operation-node/generated-always-as-node.js';
108
85
  export * from './operation-node/group-by-item-node.js';
109
86
  export * from './operation-node/group-by-node.js';
110
87
  export * from './operation-node/having-node.js';
@@ -113,11 +90,41 @@ export * from './operation-node/insert-query-node.js';
113
90
  export * from './operation-node/join-node.js';
114
91
  export * from './operation-node/limit-node.js';
115
92
  export * from './operation-node/list-node.js';
93
+ export * from './operation-node/modify-column-node.js';
116
94
  export * from './operation-node/offset-node.js';
117
- export * from './operation-node//on-conflict-node.js';
118
- export * from './operation-node/operation-node.js';
95
+ export * from './operation-node/on-conflict-node.js';
96
+ export * from './operation-node/on-duplicate-key-node.js';
97
+ export * from './operation-node/on-node.js';
119
98
  export * from './operation-node/operation-node-source.js';
99
+ export * from './operation-node/operation-node-transformer.js';
100
+ export * from './operation-node/operation-node-utils.js';
101
+ export * from './operation-node/operation-node-visitor.js';
102
+ export * from './operation-node/operation-node.js';
103
+ export * from './operation-node/operator-node.js';
104
+ export * from './operation-node/or-node.js';
105
+ export * from './operation-node/order-by-item-node.js';
120
106
  export * from './operation-node/order-by-node.js';
107
+ export * from './operation-node/parens-node.js';
108
+ export * from './operation-node/primary-constraint-node.js';
109
+ export * from './operation-node/primitive-value-list-node.js';
110
+ export * from './operation-node/query-node.js';
111
+ export * from './operation-node/raw-node.js';
112
+ export * from './operation-node/reference-node.js';
113
+ export * from './operation-node/references-node.js';
114
+ export * from './operation-node/rename-column-node.js';
115
+ export * from './operation-node/returning-node.js';
116
+ export * from './operation-node/select-all-node.js';
117
+ export * from './operation-node/select-query-node.js';
118
+ export * from './operation-node/select-query-node.js';
119
+ export * from './operation-node/selection-node.js';
120
+ export * from './operation-node/table-node.js';
121
+ export * from './operation-node/union-node.js';
122
+ export * from './operation-node/unique-constraint-node.js';
123
+ export * from './operation-node/update-query-node.js';
124
+ export * from './operation-node/value-list-node.js';
125
+ export * from './operation-node/value-node.js';
126
+ export * from './operation-node/where-node.js';
127
+ export * from './operation-node/with-node.js';
121
128
  export * from './introspection/database-introspector.js';
122
129
  export * from './util/compilable.js';
123
130
  export { AnyColumn, UnknownRow, AnyQueryBuilder } from './util/type-utils.js';
@@ -125,7 +132,7 @@ export { SelectExpression, SelectExpressionOrList, } from './parser/select-parse
125
132
  export { ReferenceExpression, ReferenceExpressionOrList, } from './parser/reference-parser.js';
126
133
  export { ValueExpression, ValueExpressionOrList, } from './parser/value-parser.js';
127
134
  export { ExistsExpression, FilterOperator } from './parser/filter-parser.js';
128
- export { TableExpression } from './parser/table-parser.js';
135
+ export { TableExpression, TableExpressionOrList, } from './parser/table-parser.js';
129
136
  export { JoinReferenceExpression, JoinCallbackExpression, } from './parser/join-parser.js';
130
137
  export { InsertObject } from './parser/insert-values-parser.js';
131
138
  export { MutationObject } from './parser/update-set-parser.js';
package/dist/cjs/index.js CHANGED
@@ -63,35 +63,8 @@ __exportStar(require("./migration/migration.js"), exports);
63
63
  __exportStar(require("./dialect/dialect.js"), exports);
64
64
  __exportStar(require("./dialect/dialect-adapter.js"), exports);
65
65
  __exportStar(require("./dialect/dialect-adapter-base.js"), exports);
66
- __exportStar(require("./operation-node/operation-node-transformer.js"), exports);
67
- __exportStar(require("./operation-node/operation-node-visitor.js"), exports);
68
66
  __exportStar(require("./plugin/kysely-plugin.js"), exports);
69
67
  __exportStar(require("./plugin/camel-case/camel-case-plugin.js"), exports);
70
- __exportStar(require("./operation-node/operation-node-transformer.js"), exports);
71
- __exportStar(require("./operation-node/operation-node-visitor.js"), exports);
72
- __exportStar(require("./operation-node/operator-node.js"), exports);
73
- __exportStar(require("./operation-node/or-node.js"), exports);
74
- __exportStar(require("./operation-node/order-by-item-node.js"), exports);
75
- __exportStar(require("./operation-node/order-by-node.js"), exports);
76
- __exportStar(require("./operation-node/parens-node.js"), exports);
77
- __exportStar(require("./operation-node/primary-constraint-node.js"), exports);
78
- __exportStar(require("./operation-node/primitive-value-list-node.js"), exports);
79
- __exportStar(require("./operation-node/query-node.js"), exports);
80
- __exportStar(require("./operation-node/raw-node.js"), exports);
81
- __exportStar(require("./operation-node/reference-node.js"), exports);
82
- __exportStar(require("./operation-node/references-node.js"), exports);
83
- __exportStar(require("./operation-node/rename-column-node.js"), exports);
84
- __exportStar(require("./operation-node/returning-node.js"), exports);
85
- __exportStar(require("./operation-node/select-all-node.js"), exports);
86
- __exportStar(require("./operation-node/select-query-node.js"), exports);
87
- __exportStar(require("./operation-node/selection-node.js"), exports);
88
- __exportStar(require("./operation-node/table-node.js"), exports);
89
- __exportStar(require("./operation-node/unique-constraint-node.js"), exports);
90
- __exportStar(require("./operation-node/update-query-node.js"), exports);
91
- __exportStar(require("./operation-node/value-list-node.js"), exports);
92
- __exportStar(require("./operation-node/value-node.js"), exports);
93
- __exportStar(require("./operation-node/where-node.js"), exports);
94
- __exportStar(require("./operation-node/with-node.js"), exports);
95
68
  __exportStar(require("./operation-node/add-column-node.js"), exports);
96
69
  __exportStar(require("./operation-node/add-constraint-node.js"), exports);
97
70
  __exportStar(require("./operation-node/alias-node.js"), exports);
@@ -107,16 +80,20 @@ __exportStar(require("./operation-node/constraint-node.js"), exports);
107
80
  __exportStar(require("./operation-node/create-index-node.js"), exports);
108
81
  __exportStar(require("./operation-node/create-schema-node.js"), exports);
109
82
  __exportStar(require("./operation-node/create-table-node.js"), exports);
83
+ __exportStar(require("./operation-node/create-view-node.js"), exports);
110
84
  __exportStar(require("./operation-node/data-type-node.js"), exports);
85
+ __exportStar(require("./operation-node/default-value-node.js"), exports);
111
86
  __exportStar(require("./operation-node/delete-query-node.js"), exports);
112
87
  __exportStar(require("./operation-node/drop-column-node.js"), exports);
113
88
  __exportStar(require("./operation-node/drop-constraint-node.js"), exports);
114
89
  __exportStar(require("./operation-node/drop-index-node.js"), exports);
115
90
  __exportStar(require("./operation-node/drop-schema-node.js"), exports);
116
91
  __exportStar(require("./operation-node/drop-table-node.js"), exports);
92
+ __exportStar(require("./operation-node/drop-view-node.js"), exports);
117
93
  __exportStar(require("./operation-node/filter-node.js"), exports);
118
94
  __exportStar(require("./operation-node/foreign-key-constraint-node.js"), exports);
119
95
  __exportStar(require("./operation-node/from-node.js"), exports);
96
+ __exportStar(require("./operation-node/generated-always-as-node.js"), exports);
120
97
  __exportStar(require("./operation-node/group-by-item-node.js"), exports);
121
98
  __exportStar(require("./operation-node/group-by-node.js"), exports);
122
99
  __exportStar(require("./operation-node/having-node.js"), exports);
@@ -125,10 +102,40 @@ __exportStar(require("./operation-node/insert-query-node.js"), exports);
125
102
  __exportStar(require("./operation-node/join-node.js"), exports);
126
103
  __exportStar(require("./operation-node/limit-node.js"), exports);
127
104
  __exportStar(require("./operation-node/list-node.js"), exports);
105
+ __exportStar(require("./operation-node/modify-column-node.js"), exports);
128
106
  __exportStar(require("./operation-node/offset-node.js"), exports);
129
- __exportStar(require("./operation-node//on-conflict-node.js"), exports);
130
- __exportStar(require("./operation-node/operation-node.js"), exports);
107
+ __exportStar(require("./operation-node/on-conflict-node.js"), exports);
108
+ __exportStar(require("./operation-node/on-duplicate-key-node.js"), exports);
109
+ __exportStar(require("./operation-node/on-node.js"), exports);
131
110
  __exportStar(require("./operation-node/operation-node-source.js"), exports);
111
+ __exportStar(require("./operation-node/operation-node-transformer.js"), exports);
112
+ __exportStar(require("./operation-node/operation-node-utils.js"), exports);
113
+ __exportStar(require("./operation-node/operation-node-visitor.js"), exports);
114
+ __exportStar(require("./operation-node/operation-node.js"), exports);
115
+ __exportStar(require("./operation-node/operator-node.js"), exports);
116
+ __exportStar(require("./operation-node/or-node.js"), exports);
117
+ __exportStar(require("./operation-node/order-by-item-node.js"), exports);
132
118
  __exportStar(require("./operation-node/order-by-node.js"), exports);
119
+ __exportStar(require("./operation-node/parens-node.js"), exports);
120
+ __exportStar(require("./operation-node/primary-constraint-node.js"), exports);
121
+ __exportStar(require("./operation-node/primitive-value-list-node.js"), exports);
122
+ __exportStar(require("./operation-node/query-node.js"), exports);
123
+ __exportStar(require("./operation-node/raw-node.js"), exports);
124
+ __exportStar(require("./operation-node/reference-node.js"), exports);
125
+ __exportStar(require("./operation-node/references-node.js"), exports);
126
+ __exportStar(require("./operation-node/rename-column-node.js"), exports);
127
+ __exportStar(require("./operation-node/returning-node.js"), exports);
128
+ __exportStar(require("./operation-node/select-all-node.js"), exports);
129
+ __exportStar(require("./operation-node/select-query-node.js"), exports);
130
+ __exportStar(require("./operation-node/select-query-node.js"), exports);
131
+ __exportStar(require("./operation-node/selection-node.js"), exports);
132
+ __exportStar(require("./operation-node/table-node.js"), exports);
133
+ __exportStar(require("./operation-node/union-node.js"), exports);
134
+ __exportStar(require("./operation-node/unique-constraint-node.js"), exports);
135
+ __exportStar(require("./operation-node/update-query-node.js"), exports);
136
+ __exportStar(require("./operation-node/value-list-node.js"), exports);
137
+ __exportStar(require("./operation-node/value-node.js"), exports);
138
+ __exportStar(require("./operation-node/where-node.js"), exports);
139
+ __exportStar(require("./operation-node/with-node.js"), exports);
133
140
  __exportStar(require("./introspection/database-introspector.js"), exports);
134
141
  __exportStar(require("./util/compilable.js"), exports);
@@ -5,7 +5,7 @@ import { RawNode } from './raw-node.js';
5
5
  import { ReferenceNode } from './reference-node.js';
6
6
  import { SelectQueryNode } from './select-query-node.js';
7
7
  import { TableNode } from './table-node.js';
8
- export declare type AliasNodeChild = ColumnNode | ReferenceNode | TableNode | RawNode | SelectQueryNode;
8
+ export declare type AliasNodeChild = ColumnNode | ReferenceNode | TableNode | SelectQueryNode | RawNode;
9
9
  export interface AliasNode extends OperationNode {
10
10
  readonly kind: 'AliasNode';
11
11
  readonly node: AliasNodeChild;
@@ -14,4 +14,4 @@ import { ValueNode } from './value-node.js';
14
14
  export declare type ReferenceExpressionNode = ColumnNode | ReferenceNode | SelectQueryNode | RawNode;
15
15
  export declare type ValueExpressionNode = ValueNode | ValueListNode | PrimitiveValueListNode | ReferenceExpressionNode;
16
16
  export declare type TableExpressionNode = TableNode | AliasNode;
17
- export declare type FilterExpressionNode = FilterNode | AndNode | OrNode | ParensNode;
17
+ export declare type FilterExpressionNode = FilterNode | AndNode | OrNode | ParensNode | RawNode;
@@ -12,3 +12,4 @@ export declare function parseOnFilter(ctx: ParseContext, args: any[]): FilterExp
12
12
  export declare function parseReferenceFilter(ctx: ParseContext, lhs: ReferenceExpression<any, any>, op: FilterOperator, rhs: ReferenceExpression<any, any>): FilterNode;
13
13
  export declare function parseExistFilter(ctx: ParseContext, arg: ExistsExpression<any, any>): FilterNode;
14
14
  export declare function parseNotExistFilter(ctx: ParseContext, arg: ExistsExpression<any, any>): FilterNode;
15
+ export declare function parseFilter(ctx: ParseContext, type: 'where' | 'having' | 'on', args: any[]): FilterExpressionNode;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseNotExistFilter = exports.parseExistFilter = exports.parseReferenceFilter = exports.parseOnFilter = exports.parseHavingFilter = exports.parseWhereFilter = void 0;
3
+ exports.parseFilter = exports.parseNotExistFilter = exports.parseExistFilter = exports.parseReferenceFilter = exports.parseOnFilter = exports.parseHavingFilter = exports.parseWhereFilter = void 0;
4
4
  const filter_node_js_1 = require("../operation-node/filter-node.js");
5
5
  const object_utils_js_1 = require("../util/object-utils.js");
6
6
  const operation_node_source_js_1 = require("../operation-node/operation-node-source.js");
@@ -12,39 +12,15 @@ const value_parser_js_1 = require("./value-parser.js");
12
12
  const select_query_node_js_1 = require("../operation-node/select-query-node.js");
13
13
  const value_node_js_1 = require("../operation-node/value-node.js");
14
14
  function parseWhereFilter(ctx, args) {
15
- if (args.length === 3) {
16
- return parseThreeArgFilter(ctx, args[0], args[1], args[2]);
17
- }
18
- else if (args.length === 1 && (0, object_utils_js_1.isFunction)(args[0])) {
19
- return parseWhereGroup(ctx, args[0]);
20
- }
21
- else {
22
- throw new Error(`invalid arguments passed to a where method ${JSON.stringify(args)}`);
23
- }
15
+ return parseFilter(ctx, 'where', args);
24
16
  }
25
17
  exports.parseWhereFilter = parseWhereFilter;
26
18
  function parseHavingFilter(ctx, args) {
27
- if (args.length === 3) {
28
- return parseThreeArgFilter(ctx, args[0], args[1], args[2]);
29
- }
30
- else if (args.length === 1 && (0, object_utils_js_1.isFunction)(args[0])) {
31
- return parseHavingGroup(ctx, args[0]);
32
- }
33
- else {
34
- throw new Error(`invalid arguments passed to a having method ${JSON.stringify(args)}`);
35
- }
19
+ return parseFilter(ctx, 'having', args);
36
20
  }
37
21
  exports.parseHavingFilter = parseHavingFilter;
38
22
  function parseOnFilter(ctx, args) {
39
- if (args.length === 3) {
40
- return parseThreeArgFilter(ctx, args[0], args[1], args[2]);
41
- }
42
- else if (args.length === 1 && (0, object_utils_js_1.isFunction)(args[0])) {
43
- return parseOnGroup(ctx, args[0]);
44
- }
45
- else {
46
- throw new Error(`invalid arguments passed to an on method ${JSON.stringify(args)}`);
47
- }
23
+ return parseFilter(ctx, 'on', args);
48
24
  }
49
25
  exports.parseOnFilter = parseOnFilter;
50
26
  function parseReferenceFilter(ctx, lhs, op, rhs) {
@@ -59,6 +35,25 @@ function parseNotExistFilter(ctx, arg) {
59
35
  return parseExistExpression(ctx, 'not exists', arg);
60
36
  }
61
37
  exports.parseNotExistFilter = parseNotExistFilter;
38
+ function parseFilter(ctx, type, args) {
39
+ if (args.length === 3) {
40
+ return parseThreeArgFilter(ctx, args[0], args[1], args[2]);
41
+ }
42
+ else if (args.length === 1) {
43
+ const arg = args[0];
44
+ if ((0, object_utils_js_1.isFunction)(arg)) {
45
+ return GROUP_PARSERS[type](ctx, arg);
46
+ }
47
+ else if ((0, operation_node_source_js_1.isOperationNodeSource)(arg)) {
48
+ const node = arg.toOperationNode();
49
+ if (raw_node_js_1.RawNode.is(node)) {
50
+ return node;
51
+ }
52
+ }
53
+ }
54
+ throw new Error(`invalid arguments passed to a '${type}' method: ${JSON.stringify(args)}`);
55
+ }
56
+ exports.parseFilter = parseFilter;
62
57
  function parseThreeArgFilter(ctx, left, op, right) {
63
58
  if ((op === 'is' || op === 'is not') && ((0, object_utils_js_1.isNull)(right) || (0, object_utils_js_1.isBoolean)(right))) {
64
59
  return parseIsFilter(ctx, left, op, right);
@@ -79,30 +74,6 @@ function parseFilterOperator(op) {
79
74
  }
80
75
  throw new Error(`invalid comparison operator ${JSON.stringify(op)} passed to a filter method`);
81
76
  }
82
- function parseWhereGroup(ctx, callback) {
83
- const query = callback(ctx.createSelectQueryBuilder([]));
84
- const queryNode = query.toOperationNode();
85
- if (!queryNode.where) {
86
- throw new Error('no `where*` methods called insided a group callback');
87
- }
88
- return parens_node_js_1.ParensNode.create(queryNode.where.where);
89
- }
90
- function parseHavingGroup(ctx, callback) {
91
- const query = callback(ctx.createSelectQueryBuilder([]));
92
- const queryNode = query.toOperationNode();
93
- if (!queryNode.having) {
94
- throw new Error('no `having*` methods called insided a group callback');
95
- }
96
- return parens_node_js_1.ParensNode.create(queryNode.having.having);
97
- }
98
- function parseOnGroup(ctx, callback) {
99
- const joinBuilder = callback(ctx.createJoinBuilder('InnerJoin', 'table'));
100
- const joinNode = joinBuilder.toOperationNode();
101
- if (!joinNode.on) {
102
- throw new Error('no `on*` methods called insided a group callback');
103
- }
104
- return parens_node_js_1.ParensNode.create(joinNode.on.on);
105
- }
106
77
  function parseExistExpression(ctx, type, arg) {
107
78
  const node = (0, object_utils_js_1.isFunction)(arg)
108
79
  ? arg(ctx.createExpressionBuilder()).toOperationNode()
@@ -112,3 +83,29 @@ function parseExistExpression(ctx, type, arg) {
112
83
  }
113
84
  return filter_node_js_1.FilterNode.create(undefined, operator_node_js_1.OperatorNode.create(type), node);
114
85
  }
86
+ const GROUP_PARSERS = (0, object_utils_js_1.freeze)({
87
+ where(ctx, callback) {
88
+ const query = callback(ctx.createSelectQueryBuilder([]));
89
+ const queryNode = query.toOperationNode();
90
+ if (!queryNode.where) {
91
+ throw new Error('no `where` methods called insided a group callback');
92
+ }
93
+ return parens_node_js_1.ParensNode.create(queryNode.where.where);
94
+ },
95
+ having(ctx, callback) {
96
+ const query = callback(ctx.createSelectQueryBuilder([]));
97
+ const queryNode = query.toOperationNode();
98
+ if (!queryNode.having) {
99
+ throw new Error('no `having` methods called insided a group callback');
100
+ }
101
+ return parens_node_js_1.ParensNode.create(queryNode.having.having);
102
+ },
103
+ on(ctx, callback) {
104
+ const joinBuilder = callback(ctx.createJoinBuilder('InnerJoin', 'table'));
105
+ const joinNode = joinBuilder.toOperationNode();
106
+ if (!joinNode.on) {
107
+ throw new Error('no `on` methods called insided a group callback');
108
+ }
109
+ return parens_node_js_1.ParensNode.create(joinNode.on.on);
110
+ },
111
+ });
@@ -4,6 +4,7 @@ import { ExistsExpression, FilterOperator } from '../parser/filter-parser.js';
4
4
  import { ParseContext } from '../parser/parse-context.js';
5
5
  import { ReferenceExpression } from '../parser/reference-parser.js';
6
6
  import { ValueExpressionOrList } from '../parser/value-parser.js';
7
+ import { AnyRawBuilder } from '../util/type-utils.js';
7
8
  export declare class JoinBuilder<DB, TB extends keyof DB> implements OperationNodeSource {
8
9
  #private;
9
10
  constructor(props: JoinBuilderProps);
@@ -15,6 +16,7 @@ export declare class JoinBuilder<DB, TB extends keyof DB> implements OperationNo
15
16
  */
16
17
  on<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: ValueExpressionOrList<DB, TB, RE>): JoinBuilder<DB, TB>;
17
18
  on(grouper: (qb: JoinBuilder<DB, TB>) => JoinBuilder<DB, TB>): JoinBuilder<DB, TB>;
19
+ on(raw: AnyRawBuilder): JoinBuilder<DB, TB>;
18
20
  /**
19
21
  * Just like {@link QueryBuilder.orWhere} but adds an item to the join's
20
22
  * `on` clause instead.
@@ -23,6 +25,7 @@ export declare class JoinBuilder<DB, TB extends keyof DB> implements OperationNo
23
25
  */
24
26
  orOn<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: ValueExpressionOrList<DB, TB, RE>): JoinBuilder<DB, TB>;
25
27
  orOn(grouper: (qb: JoinBuilder<DB, TB>) => JoinBuilder<DB, TB>): JoinBuilder<DB, TB>;
28
+ orOn(raw: AnyRawBuilder): JoinBuilder<DB, TB>;
26
29
  /**
27
30
  * Just like {@link QueryBuilder.whereRef} but adds an item to the join's
28
31
  * `on` clause instead.
@@ -10,7 +10,7 @@ import { QueryBuilderWithReturning } from '../parser/returning-parser.js';
10
10
  import { ReferenceExpression } from '../parser/reference-parser.js';
11
11
  import { ValueExpressionOrList } from '../parser/value-parser.js';
12
12
  import { QueryNode } from '../operation-node/query-node.js';
13
- import { AnyColumn, SingleResultType } from '../util/type-utils.js';
13
+ import { AnyColumn, AnyRawBuilder, SingleResultType } from '../util/type-utils.js';
14
14
  import { OrderByDirectionExpression, OrderByExpression } from '../parser/order-by-parser.js';
15
15
  import { MutationObject } from '../parser/update-set-parser.js';
16
16
  import { Compilable } from '../util/compilable.js';
@@ -220,6 +220,7 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
220
220
  */
221
221
  where<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: ValueExpressionOrList<DB, TB, RE>): QueryBuilder<DB, TB, O>;
222
222
  where(grouper: (qb: QueryBuilder<DB, TB, O>) => QueryBuilder<DB, TB, O>): QueryBuilder<DB, TB, O>;
223
+ where(raw: AnyRawBuilder): QueryBuilder<DB, TB, O>;
223
224
  /**
224
225
  * Adds a `where` clause where both sides of the operator are references
225
226
  * to columns.
@@ -339,6 +340,7 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
339
340
  */
340
341
  orWhere<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: ValueExpressionOrList<DB, TB, RE>): QueryBuilder<DB, TB, O>;
341
342
  orWhere(grouper: (qb: QueryBuilder<DB, TB, O>) => QueryBuilder<DB, TB, O>): QueryBuilder<DB, TB, O>;
343
+ orWhere(raw: AnyRawBuilder): QueryBuilder<DB, TB, O>;
342
344
  /**
343
345
  * Adds an `or where` clause to the query. Otherwise works just like
344
346
  * {@link QueryBuilder.whereRef | whereRef}.
@@ -424,6 +426,7 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
424
426
  */
425
427
  having<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: ValueExpressionOrList<DB, TB, RE>): QueryBuilder<DB, TB, O>;
426
428
  having(grouper: (qb: QueryBuilder<DB, TB, O>) => QueryBuilder<DB, TB, O>): QueryBuilder<DB, TB, O>;
429
+ having(raw: AnyRawBuilder): QueryBuilder<DB, TB, O>;
427
430
  /**
428
431
  * Just like {@link QueryBuilder.whereRef | whereRef} but adds a `having` statement
429
432
  * instead of a `where` statement.
@@ -435,6 +438,7 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
435
438
  */
436
439
  orHaving<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: ValueExpressionOrList<DB, TB, RE>): QueryBuilder<DB, TB, O>;
437
440
  orHaving(grouper: (qb: QueryBuilder<DB, TB, O>) => QueryBuilder<DB, TB, O>): QueryBuilder<DB, TB, O>;
441
+ orHaving(raw: AnyRawBuilder): QueryBuilder<DB, TB, O>;
438
442
  /**
439
443
  * Just like {@link QueryBuilder.orWhereRef | orWhereRef} but adds a `having` statement
440
444
  * instead of a `where` statement.
@@ -4,7 +4,7 @@ exports.importNamedFunction = exports.importFunction = void 0;
4
4
  const object_utils_js_1 = require("./object-utils.js");
5
5
  async function importFunction(modulePath) {
6
6
  const module = await Promise.resolve().then(() => require(modulePath));
7
- const errorMessage = `module "${modulePath}" doesn export a function`;
7
+ const errorMessage = `module "${modulePath}" doesn't export a function`;
8
8
  if ((0, object_utils_js_1.isFunction)(module)) {
9
9
  return module;
10
10
  }
@@ -1,5 +1,6 @@
1
1
  import { CompiledQuery } from '../../query-compiler/compiled-query.js';
2
2
  import { importFunction } from '../../util/dynamic-import.js';
3
+ import { isBoolean, isFunction, isNumber } from '../../util/object-utils.js';
3
4
  export class SqliteDriver {
4
5
  #config;
5
6
  #connectionMutex = new ConnectionMutex();
@@ -16,16 +17,16 @@ export class SqliteDriver {
16
17
  // into javascript. You can check the built javascript code.
17
18
  const DatabaseConstructor = await importBetterSqlite3Database();
18
19
  const options = {};
19
- if (typeof this.#config.readonly === 'boolean') {
20
+ if (isBoolean(this.#config.readonly)) {
20
21
  options.readonly = this.#config.readonly;
21
22
  }
22
- if (typeof this.#config.fileMustExist === 'boolean') {
23
+ if (isBoolean(this.#config.fileMustExist)) {
23
24
  options.fileMustExist = this.#config.fileMustExist;
24
25
  }
25
- if (typeof this.#config.timeout === 'number') {
26
+ if (isNumber(this.#config.timeout)) {
26
27
  options.timeout = this.#config.timeout;
27
28
  }
28
- if (typeof this.#config.verbose === 'function') {
29
+ if (isFunction(this.#config.verbose)) {
29
30
  options.verbose = this.#config.verbose;
30
31
  }
31
32
  this.#db = new DatabaseConstructor(this.#config.databasePath, options);
@@ -35,8 +36,8 @@ export class SqliteDriver {
35
36
  }
36
37
  }
37
38
  async acquireConnection() {
38
- // sqlite effectively only has one single connection. We use a mutex
39
- // here to wait until the single connection has been released.
39
+ // SQLite only has one single connection. We use a mutex here to wait
40
+ // until the single connection has been released.
40
41
  await this.#connectionMutex.lock();
41
42
  return this.#connection;
42
43
  }
@@ -61,7 +62,6 @@ async function importBetterSqlite3Database() {
61
62
  return await importFunction('better-sqlite3');
62
63
  }
63
64
  catch (error) {
64
- console.error(error);
65
65
  throw new Error('SQLite client not installed. Please run `npm install better-sqlite3`');
66
66
  }
67
67
  }
@@ -51,35 +51,8 @@ export * from './migration/migration.js';
51
51
  export * from './dialect/dialect.js';
52
52
  export * from './dialect/dialect-adapter.js';
53
53
  export * from './dialect/dialect-adapter-base.js';
54
- export * from './operation-node/operation-node-transformer.js';
55
- export * from './operation-node/operation-node-visitor.js';
56
54
  export * from './plugin/kysely-plugin.js';
57
55
  export * from './plugin/camel-case/camel-case-plugin.js';
58
- export * from './operation-node/operation-node-transformer.js';
59
- export * from './operation-node/operation-node-visitor.js';
60
- export * from './operation-node/operator-node.js';
61
- export * from './operation-node/or-node.js';
62
- export * from './operation-node/order-by-item-node.js';
63
- export * from './operation-node/order-by-node.js';
64
- export * from './operation-node/parens-node.js';
65
- export * from './operation-node/primary-constraint-node.js';
66
- export * from './operation-node/primitive-value-list-node.js';
67
- export * from './operation-node/query-node.js';
68
- export * from './operation-node/raw-node.js';
69
- export * from './operation-node/reference-node.js';
70
- export * from './operation-node/references-node.js';
71
- export * from './operation-node/rename-column-node.js';
72
- export * from './operation-node/returning-node.js';
73
- export * from './operation-node/select-all-node.js';
74
- export * from './operation-node/select-query-node.js';
75
- export * from './operation-node/selection-node.js';
76
- export * from './operation-node/table-node.js';
77
- export * from './operation-node/unique-constraint-node.js';
78
- export * from './operation-node/update-query-node.js';
79
- export * from './operation-node/value-list-node.js';
80
- export * from './operation-node/value-node.js';
81
- export * from './operation-node/where-node.js';
82
- export * from './operation-node/with-node.js';
83
56
  export * from './operation-node/add-column-node.js';
84
57
  export * from './operation-node/add-constraint-node.js';
85
58
  export * from './operation-node/alias-node.js';
@@ -95,16 +68,20 @@ export * from './operation-node/constraint-node.js';
95
68
  export * from './operation-node/create-index-node.js';
96
69
  export * from './operation-node/create-schema-node.js';
97
70
  export * from './operation-node/create-table-node.js';
71
+ export * from './operation-node/create-view-node.js';
98
72
  export * from './operation-node/data-type-node.js';
73
+ export * from './operation-node/default-value-node.js';
99
74
  export * from './operation-node/delete-query-node.js';
100
75
  export * from './operation-node/drop-column-node.js';
101
76
  export * from './operation-node/drop-constraint-node.js';
102
77
  export * from './operation-node/drop-index-node.js';
103
78
  export * from './operation-node/drop-schema-node.js';
104
79
  export * from './operation-node/drop-table-node.js';
80
+ export * from './operation-node/drop-view-node.js';
105
81
  export * from './operation-node/filter-node.js';
106
82
  export * from './operation-node/foreign-key-constraint-node.js';
107
83
  export * from './operation-node/from-node.js';
84
+ export * from './operation-node/generated-always-as-node.js';
108
85
  export * from './operation-node/group-by-item-node.js';
109
86
  export * from './operation-node/group-by-node.js';
110
87
  export * from './operation-node/having-node.js';
@@ -113,11 +90,41 @@ export * from './operation-node/insert-query-node.js';
113
90
  export * from './operation-node/join-node.js';
114
91
  export * from './operation-node/limit-node.js';
115
92
  export * from './operation-node/list-node.js';
93
+ export * from './operation-node/modify-column-node.js';
116
94
  export * from './operation-node/offset-node.js';
117
- export * from './operation-node//on-conflict-node.js';
118
- export * from './operation-node/operation-node.js';
95
+ export * from './operation-node/on-conflict-node.js';
96
+ export * from './operation-node/on-duplicate-key-node.js';
97
+ export * from './operation-node/on-node.js';
119
98
  export * from './operation-node/operation-node-source.js';
99
+ export * from './operation-node/operation-node-transformer.js';
100
+ export * from './operation-node/operation-node-utils.js';
101
+ export * from './operation-node/operation-node-visitor.js';
102
+ export * from './operation-node/operation-node.js';
103
+ export * from './operation-node/operator-node.js';
104
+ export * from './operation-node/or-node.js';
105
+ export * from './operation-node/order-by-item-node.js';
120
106
  export * from './operation-node/order-by-node.js';
107
+ export * from './operation-node/parens-node.js';
108
+ export * from './operation-node/primary-constraint-node.js';
109
+ export * from './operation-node/primitive-value-list-node.js';
110
+ export * from './operation-node/query-node.js';
111
+ export * from './operation-node/raw-node.js';
112
+ export * from './operation-node/reference-node.js';
113
+ export * from './operation-node/references-node.js';
114
+ export * from './operation-node/rename-column-node.js';
115
+ export * from './operation-node/returning-node.js';
116
+ export * from './operation-node/select-all-node.js';
117
+ export * from './operation-node/select-query-node.js';
118
+ export * from './operation-node/select-query-node.js';
119
+ export * from './operation-node/selection-node.js';
120
+ export * from './operation-node/table-node.js';
121
+ export * from './operation-node/union-node.js';
122
+ export * from './operation-node/unique-constraint-node.js';
123
+ export * from './operation-node/update-query-node.js';
124
+ export * from './operation-node/value-list-node.js';
125
+ export * from './operation-node/value-node.js';
126
+ export * from './operation-node/where-node.js';
127
+ export * from './operation-node/with-node.js';
121
128
  export * from './introspection/database-introspector.js';
122
129
  export * from './util/compilable.js';
123
130
  export { AnyColumn, UnknownRow, AnyQueryBuilder } from './util/type-utils.js';
@@ -125,7 +132,7 @@ export { SelectExpression, SelectExpressionOrList, } from './parser/select-parse
125
132
  export { ReferenceExpression, ReferenceExpressionOrList, } from './parser/reference-parser.js';
126
133
  export { ValueExpression, ValueExpressionOrList, } from './parser/value-parser.js';
127
134
  export { ExistsExpression, FilterOperator } from './parser/filter-parser.js';
128
- export { TableExpression } from './parser/table-parser.js';
135
+ export { TableExpression, TableExpressionOrList, } from './parser/table-parser.js';
129
136
  export { JoinReferenceExpression, JoinCallbackExpression, } from './parser/join-parser.js';
130
137
  export { InsertObject } from './parser/insert-values-parser.js';
131
138
  export { MutationObject } from './parser/update-set-parser.js';
package/dist/esm/index.js CHANGED
@@ -51,35 +51,8 @@ export * from './migration/migration.js';
51
51
  export * from './dialect/dialect.js';
52
52
  export * from './dialect/dialect-adapter.js';
53
53
  export * from './dialect/dialect-adapter-base.js';
54
- export * from './operation-node/operation-node-transformer.js';
55
- export * from './operation-node/operation-node-visitor.js';
56
54
  export * from './plugin/kysely-plugin.js';
57
55
  export * from './plugin/camel-case/camel-case-plugin.js';
58
- export * from './operation-node/operation-node-transformer.js';
59
- export * from './operation-node/operation-node-visitor.js';
60
- export * from './operation-node/operator-node.js';
61
- export * from './operation-node/or-node.js';
62
- export * from './operation-node/order-by-item-node.js';
63
- export * from './operation-node/order-by-node.js';
64
- export * from './operation-node/parens-node.js';
65
- export * from './operation-node/primary-constraint-node.js';
66
- export * from './operation-node/primitive-value-list-node.js';
67
- export * from './operation-node/query-node.js';
68
- export * from './operation-node/raw-node.js';
69
- export * from './operation-node/reference-node.js';
70
- export * from './operation-node/references-node.js';
71
- export * from './operation-node/rename-column-node.js';
72
- export * from './operation-node/returning-node.js';
73
- export * from './operation-node/select-all-node.js';
74
- export * from './operation-node/select-query-node.js';
75
- export * from './operation-node/selection-node.js';
76
- export * from './operation-node/table-node.js';
77
- export * from './operation-node/unique-constraint-node.js';
78
- export * from './operation-node/update-query-node.js';
79
- export * from './operation-node/value-list-node.js';
80
- export * from './operation-node/value-node.js';
81
- export * from './operation-node/where-node.js';
82
- export * from './operation-node/with-node.js';
83
56
  export * from './operation-node/add-column-node.js';
84
57
  export * from './operation-node/add-constraint-node.js';
85
58
  export * from './operation-node/alias-node.js';
@@ -95,16 +68,20 @@ export * from './operation-node/constraint-node.js';
95
68
  export * from './operation-node/create-index-node.js';
96
69
  export * from './operation-node/create-schema-node.js';
97
70
  export * from './operation-node/create-table-node.js';
71
+ export * from './operation-node/create-view-node.js';
98
72
  export * from './operation-node/data-type-node.js';
73
+ export * from './operation-node/default-value-node.js';
99
74
  export * from './operation-node/delete-query-node.js';
100
75
  export * from './operation-node/drop-column-node.js';
101
76
  export * from './operation-node/drop-constraint-node.js';
102
77
  export * from './operation-node/drop-index-node.js';
103
78
  export * from './operation-node/drop-schema-node.js';
104
79
  export * from './operation-node/drop-table-node.js';
80
+ export * from './operation-node/drop-view-node.js';
105
81
  export * from './operation-node/filter-node.js';
106
82
  export * from './operation-node/foreign-key-constraint-node.js';
107
83
  export * from './operation-node/from-node.js';
84
+ export * from './operation-node/generated-always-as-node.js';
108
85
  export * from './operation-node/group-by-item-node.js';
109
86
  export * from './operation-node/group-by-node.js';
110
87
  export * from './operation-node/having-node.js';
@@ -113,10 +90,40 @@ export * from './operation-node/insert-query-node.js';
113
90
  export * from './operation-node/join-node.js';
114
91
  export * from './operation-node/limit-node.js';
115
92
  export * from './operation-node/list-node.js';
93
+ export * from './operation-node/modify-column-node.js';
116
94
  export * from './operation-node/offset-node.js';
117
- export * from './operation-node//on-conflict-node.js';
118
- export * from './operation-node/operation-node.js';
95
+ export * from './operation-node/on-conflict-node.js';
96
+ export * from './operation-node/on-duplicate-key-node.js';
97
+ export * from './operation-node/on-node.js';
119
98
  export * from './operation-node/operation-node-source.js';
99
+ export * from './operation-node/operation-node-transformer.js';
100
+ export * from './operation-node/operation-node-utils.js';
101
+ export * from './operation-node/operation-node-visitor.js';
102
+ export * from './operation-node/operation-node.js';
103
+ export * from './operation-node/operator-node.js';
104
+ export * from './operation-node/or-node.js';
105
+ export * from './operation-node/order-by-item-node.js';
120
106
  export * from './operation-node/order-by-node.js';
107
+ export * from './operation-node/parens-node.js';
108
+ export * from './operation-node/primary-constraint-node.js';
109
+ export * from './operation-node/primitive-value-list-node.js';
110
+ export * from './operation-node/query-node.js';
111
+ export * from './operation-node/raw-node.js';
112
+ export * from './operation-node/reference-node.js';
113
+ export * from './operation-node/references-node.js';
114
+ export * from './operation-node/rename-column-node.js';
115
+ export * from './operation-node/returning-node.js';
116
+ export * from './operation-node/select-all-node.js';
117
+ export * from './operation-node/select-query-node.js';
118
+ export * from './operation-node/select-query-node.js';
119
+ export * from './operation-node/selection-node.js';
120
+ export * from './operation-node/table-node.js';
121
+ export * from './operation-node/union-node.js';
122
+ export * from './operation-node/unique-constraint-node.js';
123
+ export * from './operation-node/update-query-node.js';
124
+ export * from './operation-node/value-list-node.js';
125
+ export * from './operation-node/value-node.js';
126
+ export * from './operation-node/where-node.js';
127
+ export * from './operation-node/with-node.js';
121
128
  export * from './introspection/database-introspector.js';
122
129
  export * from './util/compilable.js';
@@ -5,7 +5,7 @@ import { RawNode } from './raw-node.js';
5
5
  import { ReferenceNode } from './reference-node.js';
6
6
  import { SelectQueryNode } from './select-query-node.js';
7
7
  import { TableNode } from './table-node.js';
8
- export declare type AliasNodeChild = ColumnNode | ReferenceNode | TableNode | RawNode | SelectQueryNode;
8
+ export declare type AliasNodeChild = ColumnNode | ReferenceNode | TableNode | SelectQueryNode | RawNode;
9
9
  export interface AliasNode extends OperationNode {
10
10
  readonly kind: 'AliasNode';
11
11
  readonly node: AliasNodeChild;
@@ -14,4 +14,4 @@ import { ValueNode } from './value-node.js';
14
14
  export declare type ReferenceExpressionNode = ColumnNode | ReferenceNode | SelectQueryNode | RawNode;
15
15
  export declare type ValueExpressionNode = ValueNode | ValueListNode | PrimitiveValueListNode | ReferenceExpressionNode;
16
16
  export declare type TableExpressionNode = TableNode | AliasNode;
17
- export declare type FilterExpressionNode = FilterNode | AndNode | OrNode | ParensNode;
17
+ export declare type FilterExpressionNode = FilterNode | AndNode | OrNode | ParensNode | RawNode;
@@ -12,3 +12,4 @@ export declare function parseOnFilter(ctx: ParseContext, args: any[]): FilterExp
12
12
  export declare function parseReferenceFilter(ctx: ParseContext, lhs: ReferenceExpression<any, any>, op: FilterOperator, rhs: ReferenceExpression<any, any>): FilterNode;
13
13
  export declare function parseExistFilter(ctx: ParseContext, arg: ExistsExpression<any, any>): FilterNode;
14
14
  export declare function parseNotExistFilter(ctx: ParseContext, arg: ExistsExpression<any, any>): FilterNode;
15
+ export declare function parseFilter(ctx: ParseContext, type: 'where' | 'having' | 'on', args: any[]): FilterExpressionNode;
@@ -1,5 +1,5 @@
1
1
  import { FilterNode } from '../operation-node/filter-node.js';
2
- import { isBoolean, isFunction, isNull, isString, } from '../util/object-utils.js';
2
+ import { freeze, isBoolean, isFunction, isNull, isString, } from '../util/object-utils.js';
3
3
  import { isOperationNodeSource } from '../operation-node/operation-node-source.js';
4
4
  import { RawNode } from '../operation-node/raw-node.js';
5
5
  import { OperatorNode, OPERATORS, } from '../operation-node/operator-node.js';
@@ -9,37 +9,13 @@ import { parseValueExpressionOrList, } from './value-parser.js';
9
9
  import { SelectQueryNode } from '../operation-node/select-query-node.js';
10
10
  import { ValueNode } from '../operation-node/value-node.js';
11
11
  export function parseWhereFilter(ctx, args) {
12
- if (args.length === 3) {
13
- return parseThreeArgFilter(ctx, args[0], args[1], args[2]);
14
- }
15
- else if (args.length === 1 && isFunction(args[0])) {
16
- return parseWhereGroup(ctx, args[0]);
17
- }
18
- else {
19
- throw new Error(`invalid arguments passed to a where method ${JSON.stringify(args)}`);
20
- }
12
+ return parseFilter(ctx, 'where', args);
21
13
  }
22
14
  export function parseHavingFilter(ctx, args) {
23
- if (args.length === 3) {
24
- return parseThreeArgFilter(ctx, args[0], args[1], args[2]);
25
- }
26
- else if (args.length === 1 && isFunction(args[0])) {
27
- return parseHavingGroup(ctx, args[0]);
28
- }
29
- else {
30
- throw new Error(`invalid arguments passed to a having method ${JSON.stringify(args)}`);
31
- }
15
+ return parseFilter(ctx, 'having', args);
32
16
  }
33
17
  export function parseOnFilter(ctx, args) {
34
- if (args.length === 3) {
35
- return parseThreeArgFilter(ctx, args[0], args[1], args[2]);
36
- }
37
- else if (args.length === 1 && isFunction(args[0])) {
38
- return parseOnGroup(ctx, args[0]);
39
- }
40
- else {
41
- throw new Error(`invalid arguments passed to an on method ${JSON.stringify(args)}`);
42
- }
18
+ return parseFilter(ctx, 'on', args);
43
19
  }
44
20
  export function parseReferenceFilter(ctx, lhs, op, rhs) {
45
21
  return FilterNode.create(parseReferenceExpression(ctx, lhs), parseFilterOperator(op), parseReferenceExpression(ctx, rhs));
@@ -50,6 +26,24 @@ export function parseExistFilter(ctx, arg) {
50
26
  export function parseNotExistFilter(ctx, arg) {
51
27
  return parseExistExpression(ctx, 'not exists', arg);
52
28
  }
29
+ export function parseFilter(ctx, type, args) {
30
+ if (args.length === 3) {
31
+ return parseThreeArgFilter(ctx, args[0], args[1], args[2]);
32
+ }
33
+ else if (args.length === 1) {
34
+ const arg = args[0];
35
+ if (isFunction(arg)) {
36
+ return GROUP_PARSERS[type](ctx, arg);
37
+ }
38
+ else if (isOperationNodeSource(arg)) {
39
+ const node = arg.toOperationNode();
40
+ if (RawNode.is(node)) {
41
+ return node;
42
+ }
43
+ }
44
+ }
45
+ throw new Error(`invalid arguments passed to a '${type}' method: ${JSON.stringify(args)}`);
46
+ }
53
47
  function parseThreeArgFilter(ctx, left, op, right) {
54
48
  if ((op === 'is' || op === 'is not') && (isNull(right) || isBoolean(right))) {
55
49
  return parseIsFilter(ctx, left, op, right);
@@ -70,30 +64,6 @@ function parseFilterOperator(op) {
70
64
  }
71
65
  throw new Error(`invalid comparison operator ${JSON.stringify(op)} passed to a filter method`);
72
66
  }
73
- function parseWhereGroup(ctx, callback) {
74
- const query = callback(ctx.createSelectQueryBuilder([]));
75
- const queryNode = query.toOperationNode();
76
- if (!queryNode.where) {
77
- throw new Error('no `where*` methods called insided a group callback');
78
- }
79
- return ParensNode.create(queryNode.where.where);
80
- }
81
- function parseHavingGroup(ctx, callback) {
82
- const query = callback(ctx.createSelectQueryBuilder([]));
83
- const queryNode = query.toOperationNode();
84
- if (!queryNode.having) {
85
- throw new Error('no `having*` methods called insided a group callback');
86
- }
87
- return ParensNode.create(queryNode.having.having);
88
- }
89
- function parseOnGroup(ctx, callback) {
90
- const joinBuilder = callback(ctx.createJoinBuilder('InnerJoin', 'table'));
91
- const joinNode = joinBuilder.toOperationNode();
92
- if (!joinNode.on) {
93
- throw new Error('no `on*` methods called insided a group callback');
94
- }
95
- return ParensNode.create(joinNode.on.on);
96
- }
97
67
  function parseExistExpression(ctx, type, arg) {
98
68
  const node = isFunction(arg)
99
69
  ? arg(ctx.createExpressionBuilder()).toOperationNode()
@@ -103,3 +73,29 @@ function parseExistExpression(ctx, type, arg) {
103
73
  }
104
74
  return FilterNode.create(undefined, OperatorNode.create(type), node);
105
75
  }
76
+ const GROUP_PARSERS = freeze({
77
+ where(ctx, callback) {
78
+ const query = callback(ctx.createSelectQueryBuilder([]));
79
+ const queryNode = query.toOperationNode();
80
+ if (!queryNode.where) {
81
+ throw new Error('no `where` methods called insided a group callback');
82
+ }
83
+ return ParensNode.create(queryNode.where.where);
84
+ },
85
+ having(ctx, callback) {
86
+ const query = callback(ctx.createSelectQueryBuilder([]));
87
+ const queryNode = query.toOperationNode();
88
+ if (!queryNode.having) {
89
+ throw new Error('no `having` methods called insided a group callback');
90
+ }
91
+ return ParensNode.create(queryNode.having.having);
92
+ },
93
+ on(ctx, callback) {
94
+ const joinBuilder = callback(ctx.createJoinBuilder('InnerJoin', 'table'));
95
+ const joinNode = joinBuilder.toOperationNode();
96
+ if (!joinNode.on) {
97
+ throw new Error('no `on` methods called insided a group callback');
98
+ }
99
+ return ParensNode.create(joinNode.on.on);
100
+ },
101
+ });
@@ -4,6 +4,7 @@ import { ExistsExpression, FilterOperator } from '../parser/filter-parser.js';
4
4
  import { ParseContext } from '../parser/parse-context.js';
5
5
  import { ReferenceExpression } from '../parser/reference-parser.js';
6
6
  import { ValueExpressionOrList } from '../parser/value-parser.js';
7
+ import { AnyRawBuilder } from '../util/type-utils.js';
7
8
  export declare class JoinBuilder<DB, TB extends keyof DB> implements OperationNodeSource {
8
9
  #private;
9
10
  constructor(props: JoinBuilderProps);
@@ -15,6 +16,7 @@ export declare class JoinBuilder<DB, TB extends keyof DB> implements OperationNo
15
16
  */
16
17
  on<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: ValueExpressionOrList<DB, TB, RE>): JoinBuilder<DB, TB>;
17
18
  on(grouper: (qb: JoinBuilder<DB, TB>) => JoinBuilder<DB, TB>): JoinBuilder<DB, TB>;
19
+ on(raw: AnyRawBuilder): JoinBuilder<DB, TB>;
18
20
  /**
19
21
  * Just like {@link QueryBuilder.orWhere} but adds an item to the join's
20
22
  * `on` clause instead.
@@ -23,6 +25,7 @@ export declare class JoinBuilder<DB, TB extends keyof DB> implements OperationNo
23
25
  */
24
26
  orOn<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: ValueExpressionOrList<DB, TB, RE>): JoinBuilder<DB, TB>;
25
27
  orOn(grouper: (qb: JoinBuilder<DB, TB>) => JoinBuilder<DB, TB>): JoinBuilder<DB, TB>;
28
+ orOn(raw: AnyRawBuilder): JoinBuilder<DB, TB>;
26
29
  /**
27
30
  * Just like {@link QueryBuilder.whereRef} but adds an item to the join's
28
31
  * `on` clause instead.
@@ -10,7 +10,7 @@ import { QueryBuilderWithReturning } from '../parser/returning-parser.js';
10
10
  import { ReferenceExpression } from '../parser/reference-parser.js';
11
11
  import { ValueExpressionOrList } from '../parser/value-parser.js';
12
12
  import { QueryNode } from '../operation-node/query-node.js';
13
- import { AnyColumn, SingleResultType } from '../util/type-utils.js';
13
+ import { AnyColumn, AnyRawBuilder, SingleResultType } from '../util/type-utils.js';
14
14
  import { OrderByDirectionExpression, OrderByExpression } from '../parser/order-by-parser.js';
15
15
  import { MutationObject } from '../parser/update-set-parser.js';
16
16
  import { Compilable } from '../util/compilable.js';
@@ -220,6 +220,7 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
220
220
  */
221
221
  where<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: ValueExpressionOrList<DB, TB, RE>): QueryBuilder<DB, TB, O>;
222
222
  where(grouper: (qb: QueryBuilder<DB, TB, O>) => QueryBuilder<DB, TB, O>): QueryBuilder<DB, TB, O>;
223
+ where(raw: AnyRawBuilder): QueryBuilder<DB, TB, O>;
223
224
  /**
224
225
  * Adds a `where` clause where both sides of the operator are references
225
226
  * to columns.
@@ -339,6 +340,7 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
339
340
  */
340
341
  orWhere<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: ValueExpressionOrList<DB, TB, RE>): QueryBuilder<DB, TB, O>;
341
342
  orWhere(grouper: (qb: QueryBuilder<DB, TB, O>) => QueryBuilder<DB, TB, O>): QueryBuilder<DB, TB, O>;
343
+ orWhere(raw: AnyRawBuilder): QueryBuilder<DB, TB, O>;
342
344
  /**
343
345
  * Adds an `or where` clause to the query. Otherwise works just like
344
346
  * {@link QueryBuilder.whereRef | whereRef}.
@@ -424,6 +426,7 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
424
426
  */
425
427
  having<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: ValueExpressionOrList<DB, TB, RE>): QueryBuilder<DB, TB, O>;
426
428
  having(grouper: (qb: QueryBuilder<DB, TB, O>) => QueryBuilder<DB, TB, O>): QueryBuilder<DB, TB, O>;
429
+ having(raw: AnyRawBuilder): QueryBuilder<DB, TB, O>;
427
430
  /**
428
431
  * Just like {@link QueryBuilder.whereRef | whereRef} but adds a `having` statement
429
432
  * instead of a `where` statement.
@@ -435,6 +438,7 @@ export declare class QueryBuilder<DB, TB extends keyof DB, O = {}> implements Op
435
438
  */
436
439
  orHaving<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: ValueExpressionOrList<DB, TB, RE>): QueryBuilder<DB, TB, O>;
437
440
  orHaving(grouper: (qb: QueryBuilder<DB, TB, O>) => QueryBuilder<DB, TB, O>): QueryBuilder<DB, TB, O>;
441
+ orHaving(raw: AnyRawBuilder): QueryBuilder<DB, TB, O>;
438
442
  /**
439
443
  * Just like {@link QueryBuilder.orWhereRef | orWhereRef} but adds a `having` statement
440
444
  * instead of a `where` statement.
@@ -1,7 +1,7 @@
1
1
  import { isFunction, isObject } from './object-utils.js';
2
2
  export async function importFunction(modulePath) {
3
3
  const module = await import(modulePath);
4
- const errorMessage = `module "${modulePath}" doesn export a function`;
4
+ const errorMessage = `module "${modulePath}" doesn't export a function`;
5
5
  if (isFunction(module)) {
6
6
  return module;
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kysely",
3
- "version": "0.11.1",
3
+ "version": "0.11.2",
4
4
  "description": "Type safe SQL query builder",
5
5
  "repository": {
6
6
  "type": "git",