jcc-express-mvc 1.7.2 → 1.7.3

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.
@@ -4,748 +4,773 @@ exports.Builder = void 0;
4
4
  const Database_1 = require("./Database");
5
5
  const utils_1 = require("./utils");
6
6
  class Builder {
7
- constructor() {
8
- this.tableName = "";
9
- this.queryBuilder = null;
10
- this.model = null;
11
- this.eagerLoad = [];
12
- this.softDelete = true; // Default to true (filtering out deleted), set to false to include deleted
13
- this.db = Database_1.Database.connect();
14
- }
15
- withTrashed() {
16
- this.softDelete = false;
17
- return this;
18
- }
19
- onlyTrashed() {
20
- this.softDelete = false;
21
- this.whereNotNull("deleted_at");
22
- return this;
23
- }
24
- with(relations) {
25
- if (typeof relations === "string") {
26
- this.eagerLoad = [relations];
27
- }
28
- else {
29
- this.eagerLoad = relations;
30
- }
31
- return this;
32
- }
33
- setModel(model) {
34
- this.model = model;
35
- return this;
36
- }
37
- has(relation, operator = ">=", count = 1, boolean = "and", callback) {
38
- if (!this.model) {
39
- throw new Error("Model not set for builder");
40
- }
41
- const instance = new this.model();
42
- const relationObject = instance[relation]();
43
- const query = relationObject.getRelationExistenceQuery(relationObject.getQuery(), this.getQueryBuilder());
44
- if (callback) {
45
- callback(query);
46
- }
47
- const { sql, bindings } = query.toSQL();
48
- if (operator === ">=" && count === 1) {
49
- const method = boolean === "or" ? "orWhereRaw" : "whereRaw";
50
- this[method](`exists (${sql})`, bindings);
51
- }
52
- else {
53
- query.clearSelect().count("*");
54
- const { sql: countSql, bindings: countBindings } = query.toSQL();
55
- const method = boolean === "or" ? "orWhereRaw" : "whereRaw";
56
- this[method](`(${countSql}) ${operator} ?`, [
57
- ...countBindings,
58
- count,
59
- ]);
60
- }
61
- return this;
62
- }
63
- whereHas(relation, callback, operator = ">=", count = 1) {
64
- return this.has(relation, operator, count, "and", callback);
65
- }
66
- orWhereHas(relation, callback, operator = ">=", count = 1) {
67
- return this.has(relation, operator, count, "or", callback);
68
- }
69
- getQueryBuilder() {
70
- if (!this.queryBuilder) {
71
- this.queryBuilder = this.db.queryBuilder().from(this.tableName);
72
- }
73
- return this.queryBuilder;
74
- }
75
- /**
76
- * Set the table for the query and reset the queryBuilder
77
- */
78
- from(tableName) {
79
- this.tableName = tableName;
80
- this.queryBuilder = this.db.queryBuilder().from(this.tableName);
81
- return this;
82
- }
83
- /**
84
- *
85
- * @param columnName
86
- * @returns
87
- */
88
- as(columnName) {
89
- this.getQueryBuilder().as(columnName);
90
- return this;
91
- }
92
- fromRaw(query) {
93
- this.queryBuilder?.fromRaw(query);
94
- return this;
95
- }
96
- /**
97
- * Alias for from()
98
- */
99
- table(tableName) {
100
- return this.from(tableName);
101
- }
102
- /**
103
- * Select specific columns for the query.
104
- * @param
105
- */
106
- select(...columns) {
107
- this.queryBuilder = this.getQueryBuilder().select(columns.length ? columns : "*");
108
- return this;
109
- }
110
- whereJson(path, operator, value) {
111
- const [jsonColumn, ...pathParts] = path.split(".");
112
- const jsonPath = `$.${pathParts.join(".")}`;
113
- if (!value) {
114
- this.getQueryBuilder().whereRaw(`JSON_UNQUOTE(JSON_EXTRACT(??, ?)) = ?`, [
115
- jsonColumn,
116
- jsonPath,
117
- operator,
118
- ]);
119
- }
120
- else {
121
- this.getQueryBuilder().whereRaw(`JSON_UNQUOTE(JSON_EXTRACT(??, ?)) ${operator} ?`, [jsonColumn, jsonPath, operator]);
122
- }
123
- return this;
124
- }
125
- /**
126
- * Add a where clause to the query - Laravel style
127
- *
128
- * Supports multiple signatures:
129
- * 1. where(callback) - Grouped conditions
130
- * 2. where([...conditions]) - Array of conditions
131
- * 3. where({key: value}) - Object syntax
132
- * 4. where(column, value) - Two-argument form (assumes = operator)
133
- * 5. where(column, operator, value) - Three-argument form
134
- *
135
- * @example
136
- * // Closure for grouped conditions
137
- * query.where((q) => {
138
- * q.where('age', '>', 18).orWhere('vip', true);
139
- * });
140
- *
141
- * // Array of conditions
142
- * query.where([
143
- * ['status', 'active'],
144
- * ['role', '=', 'admin']
145
- * ]);
146
- *
147
- * // Object syntax
148
- * query.where({ status: 'active', role: 'admin' });
149
- *
150
- * // Two-argument form
151
- * query.where('status', 'active');
152
- *
153
- * // Three-argument form
154
- * query.where('age', '>', 18);
155
- */
156
- where(column, operator, value) {
157
- if (typeof column === "function") {
158
- this.getQueryBuilder().where((qb) => {
159
- const subQuery = new this.constructor();
160
- subQuery.queryBuilder = qb;
161
- column(subQuery);
162
- });
163
- return this;
164
- }
165
- if (Array.isArray(column)) {
166
- column.forEach((condition) => {
167
- if (condition.length === 2) {
168
- this.where(condition[0], "=", condition[1]);
169
- }
170
- else if (condition.length === 3) {
171
- this.where(condition[0], condition[1], condition[2]);
172
- }
173
- });
174
- return this;
175
- }
176
- if (typeof column === "object" &&
177
- column !== null &&
178
- !Array.isArray(column)) {
179
- Object.entries(column).forEach(([key, val]) => {
180
- this.where(key, "=", val);
181
- });
182
- return this;
183
- }
184
- // Case 4 & 5: String column name
185
- const isJson = column.includes(".") && !column.includes(" ");
186
- // Two-argument form: where(column, value)
187
- if (value === undefined && operator !== undefined && !isJson) {
188
- this.getQueryBuilder().where(column, "=", operator);
189
- return this;
190
- }
191
- // JSON path handling
192
- if (isJson) {
193
- this.whereJson(column, operator, value || "");
194
- return this;
195
- }
196
- // Three-argument form: where(column, operator, value)
197
- this.getQueryBuilder().where(column, operator, value || "");
198
- return this;
199
- }
200
- whereNull(column) {
201
- this.getQueryBuilder().whereNull(column);
202
- return this;
203
- }
204
- whereNot(column, operator, value) {
205
- if (value === undefined) {
206
- this.getQueryBuilder().whereNot(column, operator);
207
- }
208
- else {
209
- this.getQueryBuilder().whereNot(column, operator, value);
210
- }
211
- return this;
212
- }
213
- orWhereNot(column, operator, value) {
214
- if (value === undefined) {
215
- this.getQueryBuilder().orWhereNot(column, operator);
216
- }
217
- else {
218
- this.getQueryBuilder().orWhereNot(column, operator, value);
219
- }
220
- return this;
221
- }
222
- whereNotNull(column) {
223
- this.getQueryBuilder().whereNotNull(column);
224
- return this;
225
- }
226
- whereExists(callback) {
227
- return this.applyExists("whereRaw", callback);
228
- }
229
- orWhereExists(callback) {
230
- return this.applyExists("orWhereRaw", callback);
231
- }
232
- whereBetween(column, range) {
233
- this.getQueryBuilder().whereBetween(column, range);
234
- return this;
235
- }
236
- orWhereBetween(column, range) {
237
- this.getQueryBuilder().orWhereBetween(column, range);
238
- return this;
239
- }
240
- whereNotBetween(column, range) {
241
- this.getQueryBuilder().whereNotBetween(column, range);
242
- return this;
243
- }
244
- orWhereNotBetween(column, range) {
245
- this.getQueryBuilder().orWhereNotBetween(column, range);
246
- return this;
247
- }
248
- orderBy(column, direction = "asc") {
249
- this.getQueryBuilder().orderBy(column, direction);
250
- return this;
251
- }
252
- orderByRaw(query, bindings) {
253
- this.getQueryBuilder().orderByRaw(query, bindings);
254
- return this;
255
- }
256
- latest(column = "id") {
257
- this.getQueryBuilder().orderBy(column, "desc");
258
- return this;
259
- }
260
- older(column = "id") {
261
- this.getQueryBuilder().orderBy(column, "asc");
262
- return this;
263
- }
264
- having(column, operator, value) {
265
- if (!value) {
266
- this.getQueryBuilder().having(column, "=", operator);
267
- }
268
- else {
269
- this.getQueryBuilder().having(column, operator, value);
270
- }
271
- return this;
272
- }
273
- havingIn(column, values) {
274
- this.getQueryBuilder().havingIn(column, values);
275
- return this;
276
- }
277
- havingNotIn(column, values) {
278
- this.getQueryBuilder().havingIn(column, values);
279
- return this;
280
- }
281
- havingNull(column) {
282
- this.getQueryBuilder().havingNull(column);
283
- return this;
284
- }
285
- havingNotNull(column) {
286
- this.getQueryBuilder().havingNotNull(column);
287
- return this;
288
- }
289
- havingBetween(column, values) {
290
- this.getQueryBuilder().havingBetween(column, values);
291
- return this;
292
- }
293
- havingNotBetween(column, values) {
294
- this.getQueryBuilder().havingNotBetween(column, values);
295
- return this;
296
- }
297
- havingRaw(column, values) {
298
- this.getQueryBuilder().havingRaw(column, values);
299
- return this;
300
- }
301
- orWhere(column, operator, value) {
302
- if (value === undefined) {
303
- this.getQueryBuilder().orWhere(column, operator);
304
- }
305
- else {
306
- this.getQueryBuilder().orWhere(column, operator, value);
307
- }
308
- return this;
309
- }
310
- whereIn(column, values) {
311
- if (typeof values === "function") {
312
- this.getQueryBuilder().whereIn(column, function () {
313
- values(this);
314
- });
315
- }
316
- else {
317
- this.getQueryBuilder().whereIn(column, values);
318
- }
319
- return this;
320
- }
321
- whereLike(column, value) {
322
- this.getQueryBuilder().whereLike(column, `%${value}%`);
323
- return this;
324
- }
325
- andWhereLike(column, value) {
326
- this.getQueryBuilder().andWhereLike(column, `%${value}%`);
327
- return this;
328
- }
329
- orWhereLike(column, value) {
330
- this.getQueryBuilder().orWhereLike(column, `%${value}%`);
331
- return this;
332
- }
333
- joinRaw(sql, bindings) {
334
- this.getQueryBuilder().joinRaw(sql, bindings);
335
- return this;
336
- }
337
- join(table, columnOrCallback, operator, column2) {
338
- return this.applyJoin("join", table, columnOrCallback, operator, column2);
339
- }
340
- innerJoin(table, columnOrCallback, operator, column2) {
341
- return this.applyJoin("innerJoin", table, columnOrCallback, operator, column2);
342
- }
343
- toSQL() {
344
- return this.getQueryBuilder().toSQL();
345
- }
346
- joinSub(subQuery, alias, callback) {
347
- return this._joinSubWithType("INNER", subQuery, alias, callback);
348
- }
349
- leftJoin(table, columnOrCallback, operator, column2) {
350
- return this.applyJoin("leftJoin", table, columnOrCallback, operator, column2);
351
- }
352
- rightJoin(table, columnOrCallback, operator, column2) {
353
- return this.applyJoin("rightJoin", table, columnOrCallback, operator, column2);
354
- }
355
- leftOuterJoin(table, columnOrCallback, operator, column2) {
356
- return this.applyJoin("leftOuterJoin", table, columnOrCallback, operator, column2);
357
- }
358
- rightOuterJoin(table, columnOrCallback, operator, column2) {
359
- return this.applyJoin("rightOuterJoin", table, columnOrCallback, operator, column2);
360
- }
361
- fullOuterJoin(table, columnOrCallback, operator, column2) {
362
- return this.applyJoin("fullOuterJoin", table, columnOrCallback, operator, column2);
363
- }
364
- _joinSubWithType(type, subQuery, alias, callback) {
365
- const { sql, bindings } = subQuery.toSQL();
366
- const clauses = [];
367
- const onBuilder = {
368
- on(left, op, right) {
369
- clauses.push(`${left} ${op} ${right}`);
370
- },
371
- onRaw(raw) {
372
- clauses.push(raw);
373
- },
374
- };
375
- callback(onBuilder);
376
- const onClause = clauses.join(" ");
377
- clauses.length = 0;
378
- this.joinRaw(`${type} JOIN (${this.raw(sql, bindings)}) AS ${alias} ${onClause}`);
379
- return this;
380
- }
381
- applyJoin(type, table, columnOrCallback, operator, column2) {
382
- const qb = this.getQueryBuilder();
383
- const self = this;
384
- //
385
- if (typeof columnOrCallback === "function") {
386
- qb.join(table, function () {
387
- columnOrCallback(self.applyJoinHelper(this));
388
- });
389
- }
390
- else if (operator && column2) {
391
- qb.join(table, columnOrCallback, operator, column2);
392
- }
393
- else {
394
- throw new Error(`Invalid ${type} parameters`);
395
- }
396
- return this;
397
- }
398
- crossJoinSub(subQuery, alias) {
399
- const { sql, bindings } = subQuery.toSQL();
400
- this.joinRaw(`CROSS JOIN (${this.raw(sql, bindings)}) AS ${alias}`);
401
- return this;
402
- }
403
- leftJoinSub(subQuery, alias, callback) {
404
- return this._joinSubWithType("LEFT", subQuery, alias, callback);
405
- }
406
- rightJoinSub(subQuery, alias, callback) {
407
- return this._joinSubWithType("RIGHT", subQuery, alias, callback);
408
- }
409
- clearSelect() {
410
- this.getQueryBuilder().clearSelect();
411
- return this;
412
- }
413
- clearGroup() {
414
- this.getQueryBuilder().clearGroup();
415
- return this;
416
- }
417
- clearHaving() {
418
- this.getQueryBuilder().clearHaving();
419
- return this;
420
- }
421
- clearWhere() {
422
- this.getQueryBuilder().clearWhere();
423
- return this;
424
- }
425
- distinct(...columns) {
426
- this.getQueryBuilder().distinct(columns);
427
- return this;
428
- }
429
- groupBy(...columns) {
430
- this.getQueryBuilder().groupBy(columns);
431
- return this;
432
- }
433
- groupByRaw(query, bindings) {
434
- this.getQueryBuilder().groupByRaw(query, bindings);
435
- return this;
436
- }
437
- async get() {
438
- const result = this.getQueryBuilder().clone();
439
- console.log(result.toSQL());
440
- this.reset();
441
- return result;
442
- }
443
- async first() {
444
- const result = await this.limit(1).get();
445
- this.reset();
446
- return result.length ? result[0] : null;
447
- }
448
- clone() {
449
- const clone = new Builder();
450
- clone.queryBuilder = this.getQueryBuilder().clone();
451
- clone.tableName = this.tableName;
452
- clone.model = this.model;
453
- clone.db = this.db;
454
- clone.eagerLoad = [...this.eagerLoad];
455
- clone.softDelete = this.softDelete;
456
- return clone;
457
- }
458
- /**
459
- * Check if any record exists for the current query.
460
- */
461
- async exists() {
462
- const result = await this.first();
463
- this.reset();
464
- console.log({ result });
465
- return !!result;
466
- }
467
- /**
468
- * Check if no record exists for the current query.
469
- */
470
- async doesntExist() {
471
- return !(await this.exists());
472
- }
473
- /**
474
- * Get a single column's value from the first result.
475
- */
476
- async value(column) {
477
- const row = await this.first();
478
- return row ? row[column] : null;
479
- }
480
- async insert(data) {
481
- const result = await this.db(this.tableName).insert(data);
482
- this.reset();
483
- return result && Array.isArray(result) ? result[0] : result;
484
- }
485
- async update(data) {
486
- let result = false;
487
- for (const key in data) {
488
- if (key.includes(".")) {
489
- result = await this.updateJson(key, data[key]);
490
- delete data[key];
491
- }
492
- }
493
- if (Object.keys(data).length > 0) {
494
- result = await this.getQueryBuilder().update(data);
495
- }
496
- this.reset();
497
- return result ? true : false;
498
- }
499
- async delete() {
500
- const result = await this.getQueryBuilder().delete();
501
- this.reset();
502
- return result;
503
- }
504
- raw(query, bindings = []) {
505
- return this.db.raw(query, bindings);
506
- }
507
- whereRaw(query, bindings = []) {
508
- this.getQueryBuilder().whereRaw(query, bindings);
509
- return this;
510
- }
511
- orWhereRaw(query, bindings = []) {
512
- this.getQueryBuilder().orWhereRaw(query, bindings);
513
- return this;
514
- }
515
- async runQuery(query, bindings = []) {
516
- const res = await this.db.raw(query, bindings);
517
- return res?.rows ? res?.rows : res;
518
- }
519
- returning(columns) {
520
- this.getQueryBuilder().returning(columns);
521
- return this;
522
- }
523
- offset(value) {
524
- this.getQueryBuilder().offset(value);
525
- return this;
526
- }
527
- limit(value) {
528
- this.getQueryBuilder().limit(value);
529
- return this;
530
- }
531
- union(queries) {
532
- return this.applyUnion("union", queries);
533
- }
534
- unionAll(queries) {
535
- return this.applyUnion("unionAll", queries);
536
- }
537
- toSqlCode() {
538
- return this.queryBuilder.toSQL().sql;
539
- }
540
- max(columns) {
541
- return this.applyAggregate("max", columns);
542
- }
543
- async count(columns = "id") {
544
- this.applyAggregate("count", columns);
545
- return utils_1.Utils.countValue(await this.first());
546
- }
547
- min(columns) {
548
- return this.applyAggregate("min", columns);
549
- }
550
- sum(columns) {
551
- return this.applyAggregate("sum", columns);
552
- }
553
- avg(columns) {
554
- return this.applyAggregate("avg", columns);
555
- }
556
- increment(column, amount) {
557
- if (typeof column === "string") {
558
- this.queryBuilder.increment(column, amount ?? 1);
559
- }
560
- else {
561
- this.queryBuilder.increment(column); // object form { col1: value1, col2: value2 }
562
- }
563
- return this;
564
- }
565
- truncate() {
566
- this.queryBuilder.truncate();
567
- return this;
568
- }
569
- async paginate(request, perPage = 15) {
570
- const page = Math.max(1, Number(request.query.page) || 1);
571
- const offset = (page - 1) * Number(perPage);
572
- const count = await this.clone().count();
573
- const total = count;
574
- const data = await this.clone().offset(offset).limit(Number(perPage)).get();
575
- const totalPages = Math.ceil(total / Number(perPage));
576
- const path = `${request.protocol}://${request.get("host")}${request.path}`;
577
- return {
578
- data: data,
579
- meta: {
580
- current_page: page,
581
- per_page: perPage,
582
- total: total,
583
- total_pages: totalPages,
584
- has_more: page < totalPages,
585
- links: utils_1.Utils.generatePaginationLinks(path, page, totalPages),
586
- },
587
- links: {
588
- first: `${path}?page=1`,
589
- last: `${path}?page=${totalPages}`,
590
- },
591
- };
592
- }
593
- plunk(column) {
594
- this.getQueryBuilder().pluck(column);
595
- return this;
596
- }
597
- /**
598
- * Get an array of values for a single column (alias like Laravel pluck).
599
- */
600
- async pluck(column) {
601
- const result = await this.queryBuilder.pluck(column);
602
- this.reset();
603
- return result;
604
- }
605
- decrement(column, amount) {
606
- if (typeof column === "string") {
607
- this.getQueryBuilder().decrement(column, amount ?? 1);
608
- }
609
- else {
610
- this.getQueryBuilder().decrement(column); // object form
611
- }
612
- return this;
613
- }
614
- async updateJson(path, value) {
615
- const [column, ...jsonPathParts] = path.split(".");
616
- const jsonPath = "$." + jsonPathParts.join(".");
617
- const result = await this.getQueryBuilder().update({
618
- [column]: this.db.raw(`JSON_SET(??, ?, ?)`, [column, jsonPath, value]),
619
- });
620
- this.reset();
621
- return result ? true : false;
622
- }
623
- applyJoinHelper(joinBuilder) {
624
- const db = this.db; // or however you access knex
625
- const helper = {
626
- on: (c1, op, c2) => {
627
- joinBuilder.on(c1, op, c2);
628
- return helper;
629
- },
630
- orOn: (c1, op, c2) => {
631
- joinBuilder.orOn(c1, op, c2);
632
- return helper;
633
- },
634
- raw: (sql, bindings = []) => {
635
- joinBuilder.on(db.raw(sql, bindings));
636
- return helper;
637
- },
638
- };
7
+ constructor() {
8
+ this.tableName = "";
9
+ this.queryBuilder = null;
10
+ this.model = null;
11
+ this.eagerLoad = [];
12
+ this.softDelete = true; // Default to true (filtering out deleted), set to false to include deleted
13
+ this.db = Database_1.Database.connect();
14
+ }
15
+ withTrashed() {
16
+ this.softDelete = false;
17
+ return this;
18
+ }
19
+ onlyTrashed() {
20
+ this.softDelete = false;
21
+ this.whereNotNull("deleted_at");
22
+ return this;
23
+ }
24
+ with(relations) {
25
+ if (typeof relations === "string") {
26
+ this.eagerLoad = [relations];
27
+ } else {
28
+ this.eagerLoad = relations;
29
+ }
30
+ return this;
31
+ }
32
+ setModel(model) {
33
+ this.model = model;
34
+ return this;
35
+ }
36
+ has(relation, operator = ">=", count = 1, boolean = "and", callback) {
37
+ if (!this.model) {
38
+ throw new Error("Model not set for builder");
39
+ }
40
+ const instance = new this.model();
41
+ const relationObject = instance[relation]();
42
+ const query = relationObject.getRelationExistenceQuery(
43
+ relationObject.getQuery(),
44
+ this.getQueryBuilder()
45
+ );
46
+ if (callback) {
47
+ callback(query);
48
+ }
49
+ const { sql, bindings } = query.toSQL();
50
+ if (operator === ">=" && count === 1) {
51
+ const method = boolean === "or" ? "orWhereRaw" : "whereRaw";
52
+ this[method](`exists (${sql})`, bindings);
53
+ } else {
54
+ query.clearSelect().count("*");
55
+ const { sql: countSql, bindings: countBindings } = query.toSQL();
56
+ const method = boolean === "or" ? "orWhereRaw" : "whereRaw";
57
+ this[method](`(${countSql}) ${operator} ?`, [...countBindings, count]);
58
+ }
59
+ return this;
60
+ }
61
+ whereHas(relation, callback, operator = ">=", count = 1) {
62
+ return this.has(relation, operator, count, "and", callback);
63
+ }
64
+ orWhereHas(relation, callback, operator = ">=", count = 1) {
65
+ return this.has(relation, operator, count, "or", callback);
66
+ }
67
+ getQueryBuilder() {
68
+ if (!this.queryBuilder) {
69
+ this.queryBuilder = this.db.queryBuilder().from(this.tableName);
70
+ }
71
+ return this.queryBuilder;
72
+ }
73
+ /**
74
+ * Set the table for the query and reset the queryBuilder
75
+ */
76
+ from(tableName) {
77
+ this.tableName = tableName;
78
+ this.queryBuilder = this.db.queryBuilder().from(this.tableName);
79
+ return this;
80
+ }
81
+ /**
82
+ *
83
+ * @param columnName
84
+ * @returns
85
+ */
86
+ as(columnName) {
87
+ this.getQueryBuilder().as(columnName);
88
+ return this;
89
+ }
90
+ fromRaw(query) {
91
+ this.queryBuilder?.fromRaw(query);
92
+ return this;
93
+ }
94
+ /**
95
+ * Alias for from()
96
+ */
97
+ table(tableName) {
98
+ return this.from(tableName);
99
+ }
100
+ /**
101
+ * Select specific columns for the query.
102
+ * @param
103
+ */
104
+ select(...columns) {
105
+ this.queryBuilder = this.getQueryBuilder().select(
106
+ columns.length ? columns : "*"
107
+ );
108
+ return this;
109
+ }
110
+ whereJson(path, operator, value) {
111
+ const [jsonColumn, ...pathParts] = path.split(".");
112
+ const jsonPath = `$.${pathParts.join(".")}`;
113
+ if (!value) {
114
+ this.getQueryBuilder().whereRaw(`JSON_UNQUOTE(JSON_EXTRACT(??, ?)) = ?`, [
115
+ jsonColumn,
116
+ jsonPath,
117
+ operator,
118
+ ]);
119
+ } else {
120
+ this.getQueryBuilder().whereRaw(
121
+ `JSON_UNQUOTE(JSON_EXTRACT(??, ?)) ${operator} ?`,
122
+ [jsonColumn, jsonPath, operator]
123
+ );
124
+ }
125
+ return this;
126
+ }
127
+ /**
128
+ * Add a where clause to the query - Laravel style
129
+ *
130
+ * Supports multiple signatures:
131
+ * 1. where(callback) - Grouped conditions
132
+ * 2. where([...conditions]) - Array of conditions
133
+ * 3. where({key: value}) - Object syntax
134
+ * 4. where(column, value) - Two-argument form (assumes = operator)
135
+ * 5. where(column, operator, value) - Three-argument form
136
+ *
137
+ * @example
138
+ * // Closure for grouped conditions
139
+ * query.where((q) => {
140
+ * q.where('age', '>', 18).orWhere('vip', true);
141
+ * });
142
+ *
143
+ * // Array of conditions
144
+ * query.where([
145
+ * ['status', 'active'],
146
+ * ['role', '=', 'admin']
147
+ * ]);
148
+ *
149
+ * // Object syntax
150
+ * query.where({ status: 'active', role: 'admin' });
151
+ *
152
+ * // Two-argument form
153
+ * query.where('status', 'active');
154
+ *
155
+ * // Three-argument form
156
+ * query.where('age', '>', 18);
157
+ */
158
+ where(column, operator, value) {
159
+ if (typeof column === "function") {
160
+ this.getQueryBuilder().where((qb) => {
161
+ const subQuery = new this.constructor();
162
+ subQuery.queryBuilder = qb;
163
+ column(subQuery);
164
+ });
165
+ return this;
166
+ }
167
+ if (Array.isArray(column)) {
168
+ column.forEach((condition) => {
169
+ if (condition.length === 2) {
170
+ this.where(condition[0], "=", condition[1]);
171
+ } else if (condition.length === 3) {
172
+ this.where(condition[0], condition[1], condition[2]);
173
+ }
174
+ });
175
+ return this;
176
+ }
177
+ if (
178
+ typeof column === "object" &&
179
+ column !== null &&
180
+ !Array.isArray(column)
181
+ ) {
182
+ Object.entries(column).forEach(([key, val]) => {
183
+ this.where(key, "=", val);
184
+ });
185
+ return this;
186
+ }
187
+ // Case 4 & 5: String column name
188
+ const isJson = column.includes(".") && !column.includes(" ");
189
+ // Two-argument form: where(column, value)
190
+ if (value === undefined && operator !== undefined && !isJson) {
191
+ this.getQueryBuilder().where(column, "=", operator);
192
+ return this;
193
+ }
194
+ // JSON path handling
195
+ if (isJson) {
196
+ this.whereJson(column, operator, value || "");
197
+ return this;
198
+ }
199
+ // Three-argument form: where(column, operator, value)
200
+ this.getQueryBuilder().where(column, operator, value || "");
201
+ return this;
202
+ }
203
+ whereNull(column) {
204
+ this.getQueryBuilder().whereNull(column);
205
+ return this;
206
+ }
207
+ whereNot(column, operator, value) {
208
+ if (value === undefined) {
209
+ this.getQueryBuilder().whereNot(column, operator);
210
+ } else {
211
+ this.getQueryBuilder().whereNot(column, operator, value);
212
+ }
213
+ return this;
214
+ }
215
+ orWhereNot(column, operator, value) {
216
+ if (value === undefined) {
217
+ this.getQueryBuilder().orWhereNot(column, operator);
218
+ } else {
219
+ this.getQueryBuilder().orWhereNot(column, operator, value);
220
+ }
221
+ return this;
222
+ }
223
+ whereNotNull(column) {
224
+ this.getQueryBuilder().whereNotNull(column);
225
+ return this;
226
+ }
227
+ whereExists(callback) {
228
+ return this.applyExists("whereRaw", callback);
229
+ }
230
+ orWhereExists(callback) {
231
+ return this.applyExists("orWhereRaw", callback);
232
+ }
233
+ whereBetween(column, range) {
234
+ this.getQueryBuilder().whereBetween(column, range);
235
+ return this;
236
+ }
237
+ orWhereBetween(column, range) {
238
+ this.getQueryBuilder().orWhereBetween(column, range);
239
+ return this;
240
+ }
241
+ whereNotBetween(column, range) {
242
+ this.getQueryBuilder().whereNotBetween(column, range);
243
+ return this;
244
+ }
245
+ orWhereNotBetween(column, range) {
246
+ this.getQueryBuilder().orWhereNotBetween(column, range);
247
+ return this;
248
+ }
249
+ orderBy(column, direction = "asc") {
250
+ this.getQueryBuilder().orderBy(column, direction);
251
+ return this;
252
+ }
253
+ orderByRaw(query, bindings) {
254
+ this.getQueryBuilder().orderByRaw(query, bindings);
255
+ return this;
256
+ }
257
+ latest(column = "id") {
258
+ this.getQueryBuilder().orderBy(column, "desc");
259
+ return this;
260
+ }
261
+ older(column = "id") {
262
+ this.getQueryBuilder().orderBy(column, "asc");
263
+ return this;
264
+ }
265
+ having(column, operator, value) {
266
+ if (!value) {
267
+ this.getQueryBuilder().having(column, "=", operator);
268
+ } else {
269
+ this.getQueryBuilder().having(column, operator, value);
270
+ }
271
+ return this;
272
+ }
273
+ havingIn(column, values) {
274
+ this.getQueryBuilder().havingIn(column, values);
275
+ return this;
276
+ }
277
+ havingNotIn(column, values) {
278
+ this.getQueryBuilder().havingIn(column, values);
279
+ return this;
280
+ }
281
+ havingNull(column) {
282
+ this.getQueryBuilder().havingNull(column);
283
+ return this;
284
+ }
285
+ havingNotNull(column) {
286
+ this.getQueryBuilder().havingNotNull(column);
287
+ return this;
288
+ }
289
+ havingBetween(column, values) {
290
+ this.getQueryBuilder().havingBetween(column, values);
291
+ return this;
292
+ }
293
+ havingNotBetween(column, values) {
294
+ this.getQueryBuilder().havingNotBetween(column, values);
295
+ return this;
296
+ }
297
+ havingRaw(column, values) {
298
+ this.getQueryBuilder().havingRaw(column, values);
299
+ return this;
300
+ }
301
+ orWhere(column, operator, value) {
302
+ if (value === undefined) {
303
+ this.getQueryBuilder().orWhere(column, operator);
304
+ } else {
305
+ this.getQueryBuilder().orWhere(column, operator, value);
306
+ }
307
+ return this;
308
+ }
309
+ whereIn(column, values) {
310
+ if (typeof values === "function") {
311
+ this.getQueryBuilder().whereIn(column, function () {
312
+ values(this);
313
+ });
314
+ } else {
315
+ this.getQueryBuilder().whereIn(column, values);
316
+ }
317
+ return this;
318
+ }
319
+ whereLike(column, value) {
320
+ this.getQueryBuilder().whereLike(column, `%${value}%`);
321
+ return this;
322
+ }
323
+ andWhereLike(column, value) {
324
+ this.getQueryBuilder().andWhereLike(column, `%${value}%`);
325
+ return this;
326
+ }
327
+ orWhereLike(column, value) {
328
+ this.getQueryBuilder().orWhereLike(column, `%${value}%`);
329
+ return this;
330
+ }
331
+ joinRaw(sql, bindings) {
332
+ this.getQueryBuilder().joinRaw(sql, bindings);
333
+ return this;
334
+ }
335
+ join(table, columnOrCallback, operator, column2) {
336
+ return this.applyJoin("join", table, columnOrCallback, operator, column2);
337
+ }
338
+ innerJoin(table, columnOrCallback, operator, column2) {
339
+ return this.applyJoin(
340
+ "innerJoin",
341
+ table,
342
+ columnOrCallback,
343
+ operator,
344
+ column2
345
+ );
346
+ }
347
+ toSQL() {
348
+ return this.getQueryBuilder().toSQL();
349
+ }
350
+ joinSub(subQuery, alias, callback) {
351
+ return this._joinSubWithType("INNER", subQuery, alias, callback);
352
+ }
353
+ leftJoin(table, columnOrCallback, operator, column2) {
354
+ return this.applyJoin(
355
+ "leftJoin",
356
+ table,
357
+ columnOrCallback,
358
+ operator,
359
+ column2
360
+ );
361
+ }
362
+ rightJoin(table, columnOrCallback, operator, column2) {
363
+ return this.applyJoin(
364
+ "rightJoin",
365
+ table,
366
+ columnOrCallback,
367
+ operator,
368
+ column2
369
+ );
370
+ }
371
+ leftOuterJoin(table, columnOrCallback, operator, column2) {
372
+ return this.applyJoin(
373
+ "leftOuterJoin",
374
+ table,
375
+ columnOrCallback,
376
+ operator,
377
+ column2
378
+ );
379
+ }
380
+ rightOuterJoin(table, columnOrCallback, operator, column2) {
381
+ return this.applyJoin(
382
+ "rightOuterJoin",
383
+ table,
384
+ columnOrCallback,
385
+ operator,
386
+ column2
387
+ );
388
+ }
389
+ fullOuterJoin(table, columnOrCallback, operator, column2) {
390
+ return this.applyJoin(
391
+ "fullOuterJoin",
392
+ table,
393
+ columnOrCallback,
394
+ operator,
395
+ column2
396
+ );
397
+ }
398
+ _joinSubWithType(type, subQuery, alias, callback) {
399
+ const { sql, bindings } = subQuery.toSQL();
400
+ const clauses = [];
401
+ const onBuilder = {
402
+ on(left, op, right) {
403
+ clauses.push(`${left} ${op} ${right}`);
404
+ },
405
+ onRaw(raw) {
406
+ clauses.push(raw);
407
+ },
408
+ };
409
+ callback(onBuilder);
410
+ const onClause = clauses.join(" ");
411
+ clauses.length = 0;
412
+ this.joinRaw(
413
+ `${type} JOIN (${this.raw(sql, bindings)}) AS ${alias} ${onClause}`
414
+ );
415
+ return this;
416
+ }
417
+ applyJoin(type, table, columnOrCallback, operator, column2) {
418
+ const qb = this.getQueryBuilder();
419
+ const self = this;
420
+ //
421
+ if (typeof columnOrCallback === "function") {
422
+ qb.join(table, function () {
423
+ columnOrCallback(self.applyJoinHelper(this));
424
+ });
425
+ } else if (operator && column2) {
426
+ qb.join(table, columnOrCallback, operator, column2);
427
+ } else {
428
+ throw new Error(`Invalid ${type} parameters`);
429
+ }
430
+ return this;
431
+ }
432
+ crossJoinSub(subQuery, alias) {
433
+ const { sql, bindings } = subQuery.toSQL();
434
+ this.joinRaw(`CROSS JOIN (${this.raw(sql, bindings)}) AS ${alias}`);
435
+ return this;
436
+ }
437
+ leftJoinSub(subQuery, alias, callback) {
438
+ return this._joinSubWithType("LEFT", subQuery, alias, callback);
439
+ }
440
+ rightJoinSub(subQuery, alias, callback) {
441
+ return this._joinSubWithType("RIGHT", subQuery, alias, callback);
442
+ }
443
+ clearSelect() {
444
+ this.getQueryBuilder().clearSelect();
445
+ return this;
446
+ }
447
+ clearGroup() {
448
+ this.getQueryBuilder().clearGroup();
449
+ return this;
450
+ }
451
+ clearHaving() {
452
+ this.getQueryBuilder().clearHaving();
453
+ return this;
454
+ }
455
+ clearWhere() {
456
+ this.getQueryBuilder().clearWhere();
457
+ return this;
458
+ }
459
+ distinct(...columns) {
460
+ this.getQueryBuilder().distinct(columns);
461
+ return this;
462
+ }
463
+ groupBy(...columns) {
464
+ this.getQueryBuilder().groupBy(columns);
465
+ return this;
466
+ }
467
+ groupByRaw(query, bindings) {
468
+ this.getQueryBuilder().groupByRaw(query, bindings);
469
+ return this;
470
+ }
471
+ async get() {
472
+ const result = this.getQueryBuilder().clone();
473
+ this.reset();
474
+ return result;
475
+ }
476
+ async first() {
477
+ const result = await this.limit(1).get();
478
+ this.reset();
479
+ return result.length ? result[0] : null;
480
+ }
481
+ clone() {
482
+ const clone = new Builder();
483
+ clone.queryBuilder = this.getQueryBuilder().clone();
484
+ clone.tableName = this.tableName;
485
+ clone.model = this.model;
486
+ clone.db = this.db;
487
+ clone.eagerLoad = [...this.eagerLoad];
488
+ clone.softDelete = this.softDelete;
489
+ return clone;
490
+ }
491
+ /**
492
+ * Check if any record exists for the current query.
493
+ */
494
+ async exists() {
495
+ const result = await this.first();
496
+ this.reset();
497
+ return !!result;
498
+ }
499
+ /**
500
+ * Check if no record exists for the current query.
501
+ */
502
+ async doesntExist() {
503
+ return !(await this.exists());
504
+ }
505
+ /**
506
+ * Get a single column's value from the first result.
507
+ */
508
+ async value(column) {
509
+ const row = await this.first();
510
+ return row ? row[column] : null;
511
+ }
512
+ async insert(data) {
513
+ const result = await this.db(this.tableName).insert(data);
514
+ this.reset();
515
+ return result && Array.isArray(result) ? result[0] : result;
516
+ }
517
+ async update(data) {
518
+ let result = false;
519
+ for (const key in data) {
520
+ if (key.includes(".")) {
521
+ result = await this.updateJson(key, data[key]);
522
+ delete data[key];
523
+ }
524
+ }
525
+ if (Object.keys(data).length > 0) {
526
+ result = await this.getQueryBuilder().update(data);
527
+ }
528
+ this.reset();
529
+ return result ? true : false;
530
+ }
531
+ async delete() {
532
+ const result = await this.getQueryBuilder().delete();
533
+ this.reset();
534
+ return result;
535
+ }
536
+ raw(query, bindings = []) {
537
+ return this.db.raw(query, bindings);
538
+ }
539
+ whereRaw(query, bindings = []) {
540
+ this.getQueryBuilder().whereRaw(query, bindings);
541
+ return this;
542
+ }
543
+ orWhereRaw(query, bindings = []) {
544
+ this.getQueryBuilder().orWhereRaw(query, bindings);
545
+ return this;
546
+ }
547
+ async runQuery(query, bindings = []) {
548
+ const res = await this.db.raw(query, bindings);
549
+ return res?.rows ? res?.rows : res;
550
+ }
551
+ returning(columns) {
552
+ this.getQueryBuilder().returning(columns);
553
+ return this;
554
+ }
555
+ offset(value) {
556
+ this.getQueryBuilder().offset(value);
557
+ return this;
558
+ }
559
+ limit(value) {
560
+ this.getQueryBuilder().limit(value);
561
+ return this;
562
+ }
563
+ union(queries) {
564
+ return this.applyUnion("union", queries);
565
+ }
566
+ unionAll(queries) {
567
+ return this.applyUnion("unionAll", queries);
568
+ }
569
+ toSqlCode() {
570
+ return this.queryBuilder.toSQL().sql;
571
+ }
572
+ max(columns) {
573
+ return this.applyAggregate("max", columns);
574
+ }
575
+ async count(columns = "id") {
576
+ this.applyAggregate("count", columns);
577
+ return utils_1.Utils.countValue(await this.first());
578
+ }
579
+ min(columns) {
580
+ return this.applyAggregate("min", columns);
581
+ }
582
+ sum(columns) {
583
+ return this.applyAggregate("sum", columns);
584
+ }
585
+ avg(columns) {
586
+ return this.applyAggregate("avg", columns);
587
+ }
588
+ increment(column, amount) {
589
+ if (typeof column === "string") {
590
+ this.queryBuilder.increment(column, amount ?? 1);
591
+ } else {
592
+ this.queryBuilder.increment(column); // object form { col1: value1, col2: value2 }
593
+ }
594
+ return this;
595
+ }
596
+ truncate() {
597
+ this.queryBuilder.truncate();
598
+ return this;
599
+ }
600
+ async paginate(request, perPage = 15) {
601
+ const page = Math.max(1, Number(request.query.page) || 1);
602
+ const offset = (page - 1) * Number(perPage);
603
+ const count = await this.clone().count();
604
+ const total = count;
605
+ const data = await this.clone().offset(offset).limit(Number(perPage)).get();
606
+ const totalPages = Math.ceil(total / Number(perPage));
607
+ const path = `${request.protocol}://${request.get("host")}${request.path}`;
608
+ return {
609
+ data: data,
610
+ meta: {
611
+ current_page: page,
612
+ per_page: perPage,
613
+ total: total,
614
+ total_pages: totalPages,
615
+ has_more: page < totalPages,
616
+ links: utils_1.Utils.generatePaginationLinks(path, page, totalPages),
617
+ },
618
+ links: {
619
+ first: `${path}?page=1`,
620
+ last: `${path}?page=${totalPages}`,
621
+ },
622
+ };
623
+ }
624
+ plunk(column) {
625
+ this.getQueryBuilder().pluck(column);
626
+ return this;
627
+ }
628
+ /**
629
+ * Get an array of values for a single column (alias like Laravel pluck).
630
+ */
631
+ async pluck(column) {
632
+ const result = await this.queryBuilder.pluck(column);
633
+ this.reset();
634
+ return result;
635
+ }
636
+ decrement(column, amount) {
637
+ if (typeof column === "string") {
638
+ this.getQueryBuilder().decrement(column, amount ?? 1);
639
+ } else {
640
+ this.getQueryBuilder().decrement(column); // object form
641
+ }
642
+ return this;
643
+ }
644
+ async updateJson(path, value) {
645
+ const [column, ...jsonPathParts] = path.split(".");
646
+ const jsonPath = "$." + jsonPathParts.join(".");
647
+ const result = await this.getQueryBuilder().update({
648
+ [column]: this.db.raw(`JSON_SET(??, ?, ?)`, [column, jsonPath, value]),
649
+ });
650
+ this.reset();
651
+ return result ? true : false;
652
+ }
653
+ applyJoinHelper(joinBuilder) {
654
+ const db = this.db; // or however you access knex
655
+ const helper = {
656
+ on: (c1, op, c2) => {
657
+ joinBuilder.on(c1, op, c2);
639
658
  return helper;
640
- }
641
- whereColumn(column, operator, value) {
642
- return this.applyColumn("whereColumn", column, operator, value);
643
- }
644
- orWhereColumn(column, operator, value) {
645
- return this.applyColumn("orWhereColumn", column, operator, value);
646
- }
647
- whereNotColumn(column, operator, value) {
648
- return this.applyColumn("whereNotColumn", column, operator, value);
649
- }
650
- applyExists(method, callback) {
651
- const sub = this.getQueryBuilder();
652
- callback(sub);
653
- const { sql, bindings } = sub.clone().toSQL();
654
- this.getQueryBuilder()[method](`exists (${sql})`, bindings);
655
- return this;
656
- }
657
- applyColumn(type, column, operator, value) {
658
- if (!value) {
659
- this.getQueryBuilder()[type](column, operator);
660
- }
661
- else {
662
- this.getQueryBuilder()[type](column, operator, value);
663
- }
664
- return this;
665
- }
666
- applyAggregate(type, columns) {
667
- const qb = this.getQueryBuilder();
668
- if (typeof columns === "string") {
669
- switch (type) {
670
- case "max":
671
- qb.max(columns);
672
- break;
673
- case "min":
674
- qb.min(columns);
675
- break;
676
- case "sum":
677
- qb.sum(columns);
678
- break;
679
- case "avg":
680
- qb.avg(columns);
681
- break;
682
- case "count":
683
- qb.count(columns);
684
- break;
685
- }
686
- }
687
- else if (Array.isArray(columns)) {
688
- columns.forEach((col) => {
689
- switch (type) {
690
- case "max":
691
- qb.max(col);
692
- break;
693
- case "min":
694
- qb.min(col);
695
- break;
696
- case "sum":
697
- qb.sum(col);
698
- break;
699
- case "avg":
700
- qb.avg(col);
701
- break;
702
- case "count":
703
- qb.count(col);
704
- break;
705
- }
706
- });
707
- }
708
- else {
709
- Object.entries(columns).forEach(([alias, col]) => {
710
- const expr = `${col} as ${alias}`;
711
- switch (type) {
712
- case "max":
713
- qb.max(expr);
714
- break;
715
- case "min":
716
- qb.min(expr);
717
- break;
718
- case "sum":
719
- qb.sum(expr);
720
- break;
721
- case "avg":
722
- qb.avg(expr);
723
- break;
724
- case "count":
725
- qb.count(expr);
726
- break;
727
- }
728
- });
729
- }
730
- return this;
731
- }
732
- applyUnion(type, queries) {
733
- const qb = this.getQueryBuilder();
734
- if (typeof queries === "function") {
735
- qb[type](queries);
736
- }
737
- else if (Array.isArray(queries)) {
738
- const queryBuilders = queries.map((q) => q.getQueryBuilder());
739
- qb[type](queryBuilders);
740
- }
741
- else {
742
- qb[type](queries);
743
- }
744
- return this;
745
- }
746
- reset() {
747
- this.queryBuilder = null;
748
- // this.tableName = "";
749
- }
659
+ },
660
+ orOn: (c1, op, c2) => {
661
+ joinBuilder.orOn(c1, op, c2);
662
+ return helper;
663
+ },
664
+ raw: (sql, bindings = []) => {
665
+ joinBuilder.on(db.raw(sql, bindings));
666
+ return helper;
667
+ },
668
+ };
669
+ return helper;
670
+ }
671
+ whereColumn(column, operator, value) {
672
+ return this.applyColumn("whereColumn", column, operator, value);
673
+ }
674
+ orWhereColumn(column, operator, value) {
675
+ return this.applyColumn("orWhereColumn", column, operator, value);
676
+ }
677
+ whereNotColumn(column, operator, value) {
678
+ return this.applyColumn("whereNotColumn", column, operator, value);
679
+ }
680
+ applyExists(method, callback) {
681
+ const sub = this.getQueryBuilder();
682
+ callback(sub);
683
+ const { sql, bindings } = sub.clone().toSQL();
684
+ this.getQueryBuilder()[method](`exists (${sql})`, bindings);
685
+ return this;
686
+ }
687
+ applyColumn(type, column, operator, value) {
688
+ if (!value) {
689
+ this.getQueryBuilder()[type](column, operator);
690
+ } else {
691
+ this.getQueryBuilder()[type](column, operator, value);
692
+ }
693
+ return this;
694
+ }
695
+ applyAggregate(type, columns) {
696
+ const qb = this.getQueryBuilder();
697
+ if (typeof columns === "string") {
698
+ switch (type) {
699
+ case "max":
700
+ qb.max(columns);
701
+ break;
702
+ case "min":
703
+ qb.min(columns);
704
+ break;
705
+ case "sum":
706
+ qb.sum(columns);
707
+ break;
708
+ case "avg":
709
+ qb.avg(columns);
710
+ break;
711
+ case "count":
712
+ qb.count(columns);
713
+ break;
714
+ }
715
+ } else if (Array.isArray(columns)) {
716
+ columns.forEach((col) => {
717
+ switch (type) {
718
+ case "max":
719
+ qb.max(col);
720
+ break;
721
+ case "min":
722
+ qb.min(col);
723
+ break;
724
+ case "sum":
725
+ qb.sum(col);
726
+ break;
727
+ case "avg":
728
+ qb.avg(col);
729
+ break;
730
+ case "count":
731
+ qb.count(col);
732
+ break;
733
+ }
734
+ });
735
+ } else {
736
+ Object.entries(columns).forEach(([alias, col]) => {
737
+ const expr = `${col} as ${alias}`;
738
+ switch (type) {
739
+ case "max":
740
+ qb.max(expr);
741
+ break;
742
+ case "min":
743
+ qb.min(expr);
744
+ break;
745
+ case "sum":
746
+ qb.sum(expr);
747
+ break;
748
+ case "avg":
749
+ qb.avg(expr);
750
+ break;
751
+ case "count":
752
+ qb.count(expr);
753
+ break;
754
+ }
755
+ });
756
+ }
757
+ return this;
758
+ }
759
+ applyUnion(type, queries) {
760
+ const qb = this.getQueryBuilder();
761
+ if (typeof queries === "function") {
762
+ qb[type](queries);
763
+ } else if (Array.isArray(queries)) {
764
+ const queryBuilders = queries.map((q) => q.getQueryBuilder());
765
+ qb[type](queryBuilders);
766
+ } else {
767
+ qb[type](queries);
768
+ }
769
+ return this;
770
+ }
771
+ reset() {
772
+ this.queryBuilder = null;
773
+ // this.tableName = "";
774
+ }
750
775
  }
751
776
  exports.Builder = Builder;