jcc-express-mvc 1.7.1 → 1.7.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.
- package/lib/Jcc-eloquent/lib/Builder.d.ts +12 -6
- package/lib/Jcc-eloquent/lib/Builder.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Builder.js +64 -17
- package/lib/Jcc-eloquent/lib/Model.d.ts +7 -3
- package/lib/Jcc-eloquent/lib/Model.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/Model.js +8 -13
- package/lib/Jcc-eloquent/lib/QueryBuilder.d.ts +74 -56
- package/lib/Jcc-eloquent/lib/QueryBuilder.d.ts.map +1 -1
- package/lib/Jcc-eloquent/lib/QueryBuilder.js +82 -128
- package/package.json +1 -1
|
@@ -7,7 +7,12 @@ export declare class Builder {
|
|
|
7
7
|
private db;
|
|
8
8
|
private queryBuilder;
|
|
9
9
|
private model;
|
|
10
|
+
eagerLoad: string[];
|
|
11
|
+
softDelete: boolean;
|
|
10
12
|
constructor();
|
|
13
|
+
withTrashed(): this;
|
|
14
|
+
onlyTrashed(): this;
|
|
15
|
+
with(relations: string | string[]): this;
|
|
11
16
|
setModel(model: typeof Model): this;
|
|
12
17
|
has(relation: string, operator?: string, count?: number, boolean?: "and" | "or", callback?: (q: Builder) => void): this;
|
|
13
18
|
whereHas(relation: string, callback?: (q: Builder) => void, operator?: string, count?: number): this;
|
|
@@ -97,7 +102,7 @@ export declare class Builder {
|
|
|
97
102
|
join(table: string | any, columnOrCallback: JoinCallback, operator?: string, column2?: string): this;
|
|
98
103
|
innerJoin(table: string | any, columnOrCallback: JoinCallback, operator?: string, column2?: string): this;
|
|
99
104
|
toSQL(): Knex.Sql;
|
|
100
|
-
joinSub(subQuery: typeof Model, alias: string, callback: SubJoinCallback): this;
|
|
105
|
+
joinSub(subQuery: typeof Model | Builder, alias: string, callback: SubJoinCallback): this;
|
|
101
106
|
leftJoin(table: string | any, columnOrCallback: JoinCallback, operator?: string, column2?: string): this;
|
|
102
107
|
rightJoin(table: string | any, columnOrCallback: JoinCallback, operator?: string, column2?: string): this;
|
|
103
108
|
leftOuterJoin(table: string | any, columnOrCallback: JoinCallback, operator?: string, column2?: string): this;
|
|
@@ -108,16 +113,16 @@ export declare class Builder {
|
|
|
108
113
|
crossJoinSub(subQuery: typeof Model, alias: string): this;
|
|
109
114
|
leftJoinSub(subQuery: typeof Model, alias: string, callback: SubJoinCallback): this;
|
|
110
115
|
rightJoinSub(subQuery: typeof Model, alias: string, callback: SubJoinCallback): this;
|
|
111
|
-
clearSelect():
|
|
112
|
-
clearGroup():
|
|
113
|
-
clearHaving():
|
|
114
|
-
clearWhere():
|
|
116
|
+
clearSelect(): this;
|
|
117
|
+
clearGroup(): this;
|
|
118
|
+
clearHaving(): this;
|
|
119
|
+
clearWhere(): this;
|
|
115
120
|
distinct(...columns: any[]): this;
|
|
116
121
|
groupBy(...columns: any[]): this;
|
|
117
122
|
groupByRaw(query: string, bindings?: any[]): this;
|
|
118
123
|
get(): Promise<any[]>;
|
|
119
124
|
first(): Promise<any | null>;
|
|
120
|
-
clone():
|
|
125
|
+
clone(): Builder;
|
|
121
126
|
/**
|
|
122
127
|
* Check if any record exists for the current query.
|
|
123
128
|
*/
|
|
@@ -150,6 +155,7 @@ export declare class Builder {
|
|
|
150
155
|
avg(columns: AggregateInput): this;
|
|
151
156
|
increment(column: string | Record<string, number>, amount?: number): this;
|
|
152
157
|
truncate(): this;
|
|
158
|
+
paginate(request: any, perPage?: number | string): Promise<any>;
|
|
153
159
|
plunk(column: string): this;
|
|
154
160
|
/**
|
|
155
161
|
* Get an array of values for a single column (alias like Laravel pluck).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Builder.d.ts","sourceRoot":"","sources":["../../../../Framework/lib/Jcc-eloquent/lib/Builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,OAAO,EACL,cAAc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,OAAO,CAAC,WAAW;IAanB,OAAO,CAAC,WAAW;IAcnB,OAAO,CAAC,cAAc;IAsEtB,OAAO,CAAC,UAAU;IAkBlB,OAAO,CAAC,KAAK;CAId"}
|
|
@@ -8,8 +8,28 @@ class Builder {
|
|
|
8
8
|
this.tableName = "";
|
|
9
9
|
this.queryBuilder = null;
|
|
10
10
|
this.model = null;
|
|
11
|
+
this.eagerLoad = [];
|
|
12
|
+
this.softDelete = true; // Default to true (filtering out deleted), set to false to include deleted
|
|
11
13
|
this.db = Database_1.Database.connect();
|
|
12
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
|
+
}
|
|
13
33
|
setModel(model) {
|
|
14
34
|
this.model = model;
|
|
15
35
|
return this;
|
|
@@ -203,16 +223,6 @@ class Builder {
|
|
|
203
223
|
this.getQueryBuilder().whereNotNull(column);
|
|
204
224
|
return this;
|
|
205
225
|
}
|
|
206
|
-
// public whereExists(
|
|
207
|
-
// subquery: ((qb: Knex.QueryBuilder) => void) | Knex.QueryBuilder
|
|
208
|
-
// ): this {
|
|
209
|
-
// if (typeof subquery === "function") {
|
|
210
|
-
// this.getQueryBuilder().whereExists(subquery);
|
|
211
|
-
// } else {
|
|
212
|
-
// this.getQueryBuilder().whereExists(subquery);
|
|
213
|
-
// }
|
|
214
|
-
// return this;
|
|
215
|
-
// }
|
|
216
226
|
whereExists(callback) {
|
|
217
227
|
return this.applyExists("whereRaw", callback);
|
|
218
228
|
}
|
|
@@ -397,16 +407,20 @@ class Builder {
|
|
|
397
407
|
return this._joinSubWithType("RIGHT", subQuery, alias, callback);
|
|
398
408
|
}
|
|
399
409
|
clearSelect() {
|
|
400
|
-
|
|
410
|
+
this.getQueryBuilder().clearSelect();
|
|
411
|
+
return this;
|
|
401
412
|
}
|
|
402
413
|
clearGroup() {
|
|
403
|
-
|
|
414
|
+
this.getQueryBuilder().clearGroup();
|
|
415
|
+
return this;
|
|
404
416
|
}
|
|
405
417
|
clearHaving() {
|
|
406
|
-
|
|
418
|
+
this.getQueryBuilder().clearHaving();
|
|
419
|
+
return this;
|
|
407
420
|
}
|
|
408
421
|
clearWhere() {
|
|
409
|
-
|
|
422
|
+
this.getQueryBuilder().clearWhere();
|
|
423
|
+
return this;
|
|
410
424
|
}
|
|
411
425
|
distinct(...columns) {
|
|
412
426
|
this.getQueryBuilder().distinct(columns);
|
|
@@ -421,7 +435,8 @@ class Builder {
|
|
|
421
435
|
return this;
|
|
422
436
|
}
|
|
423
437
|
async get() {
|
|
424
|
-
const result =
|
|
438
|
+
const result = this.getQueryBuilder().clone();
|
|
439
|
+
console.log(result.toSQL());
|
|
425
440
|
this.reset();
|
|
426
441
|
return result;
|
|
427
442
|
}
|
|
@@ -431,14 +446,22 @@ class Builder {
|
|
|
431
446
|
return result.length ? result[0] : null;
|
|
432
447
|
}
|
|
433
448
|
clone() {
|
|
434
|
-
|
|
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;
|
|
435
457
|
}
|
|
436
458
|
/**
|
|
437
459
|
* Check if any record exists for the current query.
|
|
438
460
|
*/
|
|
439
461
|
async exists() {
|
|
440
|
-
const result = await this.
|
|
462
|
+
const result = await this.first();
|
|
441
463
|
this.reset();
|
|
464
|
+
console.log({ result });
|
|
442
465
|
return !!result;
|
|
443
466
|
}
|
|
444
467
|
/**
|
|
@@ -543,6 +566,30 @@ class Builder {
|
|
|
543
566
|
this.queryBuilder.truncate();
|
|
544
567
|
return this;
|
|
545
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
|
+
}
|
|
546
593
|
plunk(column) {
|
|
547
594
|
this.getQueryBuilder().pluck(column);
|
|
548
595
|
return this;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseModel } from "./BaseModel";
|
|
2
|
+
import { Builder } from "./Builder";
|
|
2
3
|
import { HasOne, HasMany, BelongsTo, BelongsToMany, MorphTo, MorphOne, MorphMany } from "./Relations";
|
|
3
4
|
import { Request } from "express";
|
|
4
5
|
import { Pagination } from "./Interfaces";
|
|
@@ -29,8 +30,11 @@ export declare class Model extends BaseModel {
|
|
|
29
30
|
/**
|
|
30
31
|
* Retrieves all records, including soft-deleted ones.
|
|
31
32
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Retrieves all records, including soft-deleted ones.
|
|
35
|
+
*/
|
|
36
|
+
static withTrashed(): Builder;
|
|
37
|
+
static onlyTrashed(): Builder;
|
|
34
38
|
/**
|
|
35
39
|
* Executes the query and loads specified relations.
|
|
36
40
|
*/
|
|
@@ -49,7 +53,7 @@ export declare class Model extends BaseModel {
|
|
|
49
53
|
protected morphOne(related: typeof Model, morphName: string, type?: string): MorphOne;
|
|
50
54
|
protected morphMany(related: typeof Model, morphName: string, type?: string): MorphMany;
|
|
51
55
|
protected morphTo(morphName?: string | typeof Model): MorphTo;
|
|
52
|
-
static with(relations: string | string[]):
|
|
56
|
+
static with(relations: string | string[]): Builder;
|
|
53
57
|
setRelation(name: string, value: any): void;
|
|
54
58
|
getRelation(name: string): any;
|
|
55
59
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../../../../Framework/lib/Jcc-eloquent/lib/Model.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../../../../Framework/lib/Jcc-eloquent/lib/Model.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EACL,MAAM,EACN,OAAO,EACP,SAAS,EACT,aAAa,EACb,OAAO,EACP,QAAQ,EACR,SAAS,EACV,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,qBAAa,KAAM,SAAQ,SAAS;IAClC,SAAS,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,CAAM;IACnC,SAAS,EAAE,MAAM,CAAC,MAAM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AC,EAAE,MAAM,EACnB,QAAQ,GAAE,MAAa,GACtB,MAAM;IAUT,SAAS,CAAC,OAAO,CACf,OAAO,EAAE,OAAO,KAAK,EACrB,UAAU,CAAC,EAAE,MAAM,EACnB,QAAQ,GAAE,MAAa,GACtB,OAAO;IAUV,SAAS,CAAC,SAAS,CACjB,OAAO,EAAE,OAAO,KAAK,EACrB,UAAU,CAAC,EAAE,MAAM,EACnB,QAAQ,GAAE,MAAa,GACtB,SAAS;IAaZ,SAAS,CAAC,aAAa,CACrB,OAAO,EAAE,OAAO,KAAK,EACrB,UAAU,CAAC,EAAE,MAAM,EACnB,eAAe,CAAC,EAAE,MAAM,EACxB,eAAe,CAAC,EAAE,MAAM,EACxB,SAAS,GAAE,MAAa,EACxB,UAAU,GAAE,MAAa,GACxB,aAAa;IAiChB,SAAS,CAAC,QAAQ,CAChB,OAAO,EAAE,OAAO,KAAK,EACrB,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,MAAM,GACZ,QAAQ;IAeX,SAAS,CAAC,SAAS,CACjB,OAAO,EAAE,OAAO,KAAK,EACrB,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,MAAM,GACZ,SAAS;IAeZ,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,KAAK,GAAG,OAAO;WAa/C,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO;IAIlD,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG;IAWpC,WAAW,CAAC,IAAI,EAAE,MAAM;IAI/B;;OAEG;IACU,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAM/D"}
|
|
@@ -33,7 +33,7 @@ class Model extends BaseModel_1.BaseModel {
|
|
|
33
33
|
const page = Math.max(1, Number(request.query.page) || 1);
|
|
34
34
|
const offset = (page - 1) * Number(perPage);
|
|
35
35
|
const count = await this.clone().count();
|
|
36
|
-
const total =
|
|
36
|
+
const total = count;
|
|
37
37
|
const data = await this.select()
|
|
38
38
|
.offset(offset)
|
|
39
39
|
.limit(Number(perPage))
|
|
@@ -106,17 +106,17 @@ class Model extends BaseModel_1.BaseModel {
|
|
|
106
106
|
}
|
|
107
107
|
return query.delete();
|
|
108
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Retrieves all records, including soft-deleted ones.
|
|
111
|
+
*/
|
|
109
112
|
/**
|
|
110
113
|
* Retrieves all records, including soft-deleted ones.
|
|
111
114
|
*/
|
|
112
115
|
static withTrashed() {
|
|
113
|
-
this.
|
|
114
|
-
return this;
|
|
116
|
+
return this.query().withTrashed();
|
|
115
117
|
}
|
|
116
118
|
static onlyTrashed() {
|
|
117
|
-
this.
|
|
118
|
-
this.whereNotNull("deleted_at");
|
|
119
|
-
return this;
|
|
119
|
+
return this.query().onlyTrashed();
|
|
120
120
|
}
|
|
121
121
|
/**
|
|
122
122
|
* Executes the query and loads specified relations.
|
|
@@ -309,14 +309,9 @@ class Model extends BaseModel_1.BaseModel {
|
|
|
309
309
|
return new Relations_1.MorphTo(this, morphType, morphId);
|
|
310
310
|
}
|
|
311
311
|
// Eager Loading Methods
|
|
312
|
+
// Eager Loading Methods
|
|
312
313
|
static with(relations) {
|
|
313
|
-
|
|
314
|
-
this.eagerLoad = [relations];
|
|
315
|
-
}
|
|
316
|
-
else {
|
|
317
|
-
this.eagerLoad = relations;
|
|
318
|
-
}
|
|
319
|
-
return this;
|
|
314
|
+
return this.query().with(relations);
|
|
320
315
|
}
|
|
321
316
|
setRelation(name, value) {
|
|
322
317
|
this.relations[name] = value;
|
|
@@ -7,7 +7,6 @@ export declare class QueryBuilder extends ModelEvent {
|
|
|
7
7
|
protected static table: string;
|
|
8
8
|
protected static softDelete: boolean;
|
|
9
9
|
protected static eagerLoad: string[];
|
|
10
|
-
protected static builderInstance: Builder | null;
|
|
11
10
|
relations: Record<string, any>;
|
|
12
11
|
static getTable(): string;
|
|
13
12
|
/**
|
|
@@ -17,40 +16,40 @@ export declare class QueryBuilder extends ModelEvent {
|
|
|
17
16
|
static has(relation: string, operator?: string, count?: number, boolean?: "and" | "or", callback?: (q: Builder) => void): Builder;
|
|
18
17
|
static whereHas(relation: string, callback?: (q: Builder) => void, operator?: string, count?: number): Builder;
|
|
19
18
|
static orWhereHas(relation: string, callback?: (q: Builder) => void, operator?: string, count?: number): Builder;
|
|
20
|
-
static clone():
|
|
19
|
+
static clone(): Builder;
|
|
21
20
|
/**
|
|
22
21
|
* Set the table for the query.
|
|
23
22
|
*/
|
|
24
|
-
static from(tableName: string):
|
|
23
|
+
static from(tableName: string): Builder;
|
|
25
24
|
/**
|
|
26
25
|
* Set the table using raw SQL.
|
|
27
26
|
*/
|
|
28
|
-
static fromRaw(query: string):
|
|
29
|
-
static joinRaw(sql: string, bindings?: any[]):
|
|
27
|
+
static fromRaw(query: string): Builder;
|
|
28
|
+
static joinRaw(sql: string, bindings?: any[]): Builder;
|
|
30
29
|
/**
|
|
31
30
|
* Select specific columns.
|
|
32
31
|
*/
|
|
33
|
-
static select(...columns: string[]):
|
|
32
|
+
static select(...columns: string[]): Builder;
|
|
34
33
|
/**
|
|
35
34
|
* Add a where clause.
|
|
36
35
|
*/
|
|
37
|
-
static where(column: WhereInput, operator?: any, value?: any):
|
|
36
|
+
static where(column: WhereInput, operator?: any, value?: any): Builder;
|
|
38
37
|
/**
|
|
39
38
|
* Add a where not clause.
|
|
40
39
|
*/
|
|
41
|
-
static whereNot(column: string, operator: any, value?: any):
|
|
40
|
+
static whereNot(column: string, operator: any, value?: any): Builder;
|
|
42
41
|
/**
|
|
43
42
|
* Add an or where not clause.
|
|
44
43
|
*/
|
|
45
|
-
static orWhereNot(column: string, operator: any, value?: any):
|
|
44
|
+
static orWhereNot(column: string, operator: any, value?: any): Builder;
|
|
46
45
|
/**
|
|
47
46
|
* Add a where not null clause.
|
|
48
47
|
*/
|
|
49
|
-
static whereNotNull(column: string):
|
|
48
|
+
static whereNotNull(column: string): Builder;
|
|
50
49
|
/**
|
|
51
50
|
* Add a where exists clause.
|
|
52
51
|
*/
|
|
53
|
-
static whereExists(callback: (qb: Knex.QueryBuilder | typeof QueryBuilder) => void):
|
|
52
|
+
static whereExists(callback: (qb: Knex.QueryBuilder | typeof QueryBuilder) => void): Builder;
|
|
54
53
|
/**
|
|
55
54
|
* Add an or where exists clause.
|
|
56
55
|
*/
|
|
@@ -58,161 +57,167 @@ export declare class QueryBuilder extends ModelEvent {
|
|
|
58
57
|
/**
|
|
59
58
|
* Add a where between clause.
|
|
60
59
|
*/
|
|
61
|
-
static whereBetween(column: string, range: [number | string, number | string]):
|
|
60
|
+
static whereBetween(column: string, range: [number | string, number | string]): Builder;
|
|
62
61
|
/**
|
|
63
62
|
* Add an or where between clause.
|
|
64
63
|
*/
|
|
65
|
-
static orWhereBetween(column: string, range: [number | string, number | string]):
|
|
64
|
+
static orWhereBetween(column: string, range: [number | string, number | string]): Builder;
|
|
66
65
|
/**
|
|
67
66
|
* Add a where not between clause.
|
|
68
67
|
*/
|
|
69
|
-
static whereNotBetween(column: string, range: [number | string, number | string]):
|
|
68
|
+
static whereNotBetween(column: string, range: [number | string, number | string]): Builder;
|
|
70
69
|
/**
|
|
71
70
|
* Add an or where not between clause.
|
|
72
71
|
*/
|
|
73
|
-
static orWhereNotBetween(column: string, range: [number | string, number | string]):
|
|
72
|
+
static orWhereNotBetween(column: string, range: [number | string, number | string]): Builder;
|
|
74
73
|
/**
|
|
75
74
|
* Order results by column.
|
|
76
75
|
*/
|
|
77
|
-
static orderBy(column: string, direction?: "asc" | "desc"):
|
|
76
|
+
static orderBy(column: string, direction?: "asc" | "desc"): Builder;
|
|
78
77
|
/**
|
|
79
78
|
* Order results using raw SQL.
|
|
80
79
|
*/
|
|
81
|
-
static orderByRaw(query: string, bindings?: any[]):
|
|
80
|
+
static orderByRaw(query: string, bindings?: any[]): Builder;
|
|
82
81
|
/**
|
|
83
82
|
* Order results by column descending.
|
|
84
83
|
*/
|
|
85
|
-
static latest(column?: string):
|
|
84
|
+
static latest(column?: string): Builder;
|
|
86
85
|
/**
|
|
87
86
|
* Order results by column ascending.
|
|
88
87
|
*/
|
|
89
|
-
static older(column?: string):
|
|
88
|
+
static older(column?: string): Builder;
|
|
90
89
|
/**
|
|
91
90
|
* Add a having clause.
|
|
92
91
|
*/
|
|
93
|
-
static having(column: string, operator: string, value?: any):
|
|
92
|
+
static having(column: string, operator: string, value?: any): Builder;
|
|
94
93
|
/**
|
|
95
94
|
* Add a having in clause.
|
|
96
95
|
*/
|
|
97
|
-
static havingIn(column: string, values: any[]):
|
|
96
|
+
static havingIn(column: string, values: any[]): Builder;
|
|
98
97
|
/**
|
|
99
98
|
* Add a having not in clause.
|
|
100
99
|
*/
|
|
101
|
-
static havingNotIn(column: string, values: any[]):
|
|
100
|
+
static havingNotIn(column: string, values: any[]): Builder;
|
|
102
101
|
/**
|
|
103
102
|
* Add a having null clause.
|
|
104
103
|
*/
|
|
105
|
-
static havingNull(column: string):
|
|
104
|
+
static havingNull(column: string): Builder;
|
|
106
105
|
/**
|
|
107
106
|
* Add a having not null clause.
|
|
108
107
|
*/
|
|
109
|
-
static havingNotNull(column: string):
|
|
108
|
+
static havingNotNull(column: string): Builder;
|
|
110
109
|
/**
|
|
111
110
|
* Add a having between clause.
|
|
112
111
|
*/
|
|
113
|
-
static havingBetween(column: string, values: any[]):
|
|
112
|
+
static havingBetween(column: string, values: any[]): Builder;
|
|
114
113
|
/**
|
|
115
114
|
* Add a having not between clause.
|
|
116
115
|
*/
|
|
117
|
-
static havingNotBetween(column: string, values: any[]):
|
|
116
|
+
static havingNotBetween(column: string, values: any[]): Builder;
|
|
118
117
|
/**
|
|
119
118
|
* Add a raw having clause.
|
|
120
119
|
*/
|
|
121
|
-
static havingRaw(column: string, values: any[]):
|
|
120
|
+
static havingRaw(column: string, values: any[]): Builder;
|
|
122
121
|
/**
|
|
123
122
|
* Add an or where clause.
|
|
124
123
|
*/
|
|
125
|
-
static orWhere(column: string, operator: any, value?: any):
|
|
124
|
+
static orWhere(column: string, operator: any, value?: any): Builder;
|
|
126
125
|
/**
|
|
127
126
|
* Add a where in clause.
|
|
128
127
|
*/
|
|
129
|
-
static whereIn(column: string, values: any[] | ((qb: Knex.QueryBuilder) => void)):
|
|
128
|
+
static whereIn(column: string, values: any[] | ((qb: Knex.QueryBuilder) => void)): Builder;
|
|
130
129
|
/**
|
|
131
130
|
* Add a where like clause with wildcards.
|
|
132
131
|
*/
|
|
133
|
-
static whereLike(column: string, value: string):
|
|
132
|
+
static whereLike(column: string, value: string): Builder;
|
|
134
133
|
/**
|
|
135
134
|
* Add an and where like clause.
|
|
136
135
|
*/
|
|
137
|
-
static andWhereLike(column: string, value: string):
|
|
136
|
+
static andWhereLike(column: string, value: string): Builder;
|
|
138
137
|
/**
|
|
139
138
|
* Add an or where like clause.
|
|
140
139
|
*/
|
|
141
|
-
static orWhereLike(column: string, value: string):
|
|
140
|
+
static orWhereLike(column: string, value: string): Builder;
|
|
142
141
|
/**
|
|
143
142
|
*
|
|
144
143
|
* @param columnName
|
|
145
144
|
* @returns
|
|
146
145
|
*/
|
|
147
|
-
static as(columnName: string | number | symbol):
|
|
146
|
+
static as(columnName: string | number | symbol): Builder;
|
|
148
147
|
/**
|
|
149
148
|
* Add a join clause.
|
|
150
149
|
*/
|
|
151
|
-
static join(table: string | any, columnOrCallback: JoinCallback, operator?: string, column2?: string):
|
|
150
|
+
static join(table: string | any, columnOrCallback: JoinCallback, operator?: string, column2?: string): Builder;
|
|
152
151
|
static toSQL(): Knex.Sql;
|
|
153
|
-
static joinSub(subQuery: any, alias: string, callback: SubJoinCallback):
|
|
152
|
+
static joinSub(subQuery: any, alias: string, callback: SubJoinCallback): Builder;
|
|
154
153
|
/**
|
|
155
154
|
* Add an inner join clause.
|
|
156
155
|
*/
|
|
157
|
-
static innerJoin(table: string, column1: string, operator: string, column2?: string):
|
|
156
|
+
static innerJoin(table: string, column1: string, operator: string, column2?: string): Builder;
|
|
158
157
|
/**
|
|
159
158
|
* Add a left join clause.
|
|
160
159
|
*/
|
|
161
|
-
static leftJoin(table: string, column1: string, column2: string):
|
|
160
|
+
static leftJoin(table: string, column1: string, column2: string): Builder;
|
|
162
161
|
/**
|
|
163
162
|
* Add a right join clause.
|
|
164
163
|
*/
|
|
165
|
-
static rightJoin(table: string, column1: string, column2: string):
|
|
164
|
+
static rightJoin(table: string, column1: string, column2: string): Builder;
|
|
166
165
|
/**
|
|
167
166
|
* Add a left outer join clause.
|
|
168
167
|
*/
|
|
169
|
-
static leftOuterJoin(table: string, column1: string, column2: string):
|
|
168
|
+
static leftOuterJoin(table: string, column1: string, column2: string): Builder;
|
|
170
169
|
/**
|
|
171
170
|
* Add a right outer join clause.
|
|
172
171
|
*/
|
|
173
|
-
static rightOuterJoin(table: string, column1: string, column2: string):
|
|
172
|
+
static rightOuterJoin(table: string, column1: string, column2: string): Builder;
|
|
174
173
|
/**
|
|
175
174
|
* Add a full outer join clause.
|
|
176
175
|
*/
|
|
177
|
-
static fullOuterJoin(table: string, column1: string, column2: string):
|
|
176
|
+
static fullOuterJoin(table: string, column1: string, column2: string): Builder;
|
|
178
177
|
/**
|
|
179
178
|
* Clear select clause.
|
|
180
179
|
*/
|
|
181
|
-
static clearSelect():
|
|
180
|
+
static clearSelect(): Builder;
|
|
182
181
|
/**
|
|
183
182
|
* Clear group by clause.
|
|
184
183
|
*/
|
|
185
|
-
static clearGroup():
|
|
184
|
+
static clearGroup(): Builder;
|
|
186
185
|
/**
|
|
187
186
|
* Clear having clause.
|
|
188
187
|
*/
|
|
189
|
-
static clearHaving():
|
|
188
|
+
static clearHaving(): Builder;
|
|
190
189
|
/**
|
|
191
190
|
* Clear where clause.
|
|
192
191
|
*/
|
|
193
|
-
static clearWhere():
|
|
192
|
+
static clearWhere(): Builder;
|
|
194
193
|
/**
|
|
195
194
|
* Add distinct clause.
|
|
196
195
|
*/
|
|
197
|
-
static distinct(...columns: any[]):
|
|
196
|
+
static distinct(...columns: any[]): Builder;
|
|
198
197
|
/**
|
|
199
198
|
* Add group by clause.
|
|
200
199
|
*/
|
|
201
|
-
static groupBy(...columns: any[]):
|
|
200
|
+
static groupBy(...columns: any[]): Builder;
|
|
202
201
|
/**
|
|
203
202
|
* Add raw group by clause.
|
|
204
203
|
*/
|
|
205
|
-
static groupByRaw(query: string, bindings?: any[]):
|
|
204
|
+
static groupByRaw(query: string, bindings?: any[]): Builder;
|
|
206
205
|
/**
|
|
207
206
|
* Execute query and return all results.
|
|
208
207
|
*/
|
|
209
|
-
|
|
210
|
-
|
|
208
|
+
/**
|
|
209
|
+
* Execute query and return all results.
|
|
210
|
+
*/
|
|
211
|
+
static get(): Promise<any[]>;
|
|
212
|
+
static first(): Promise<any>;
|
|
211
213
|
/**
|
|
212
214
|
* Execute query and return first result.
|
|
213
215
|
*/
|
|
214
|
-
static whereNull(column: string):
|
|
216
|
+
static whereNull(column: string): Builder;
|
|
215
217
|
static restore(): Promise<Boolean>;
|
|
218
|
+
/**
|
|
219
|
+
* Insert data into table.
|
|
220
|
+
*/
|
|
216
221
|
/**
|
|
217
222
|
* Insert data into table.
|
|
218
223
|
*/
|
|
@@ -221,6 +226,9 @@ export declare class QueryBuilder extends ModelEvent {
|
|
|
221
226
|
* Update records.
|
|
222
227
|
*/
|
|
223
228
|
static update(data: any): Promise<any>;
|
|
229
|
+
/**
|
|
230
|
+
* Delete records.
|
|
231
|
+
*/
|
|
224
232
|
/**
|
|
225
233
|
* Delete records.
|
|
226
234
|
*/
|
|
@@ -233,6 +241,9 @@ export declare class QueryBuilder extends ModelEvent {
|
|
|
233
241
|
* Execute raw SQL query.
|
|
234
242
|
*/
|
|
235
243
|
static runQuery(query: string, bindings?: any[]): Promise<any>;
|
|
244
|
+
/**
|
|
245
|
+
* Specify returning columns for insert/update.
|
|
246
|
+
*/
|
|
236
247
|
/**
|
|
237
248
|
* Specify returning columns for insert/update.
|
|
238
249
|
*/
|
|
@@ -240,19 +251,19 @@ export declare class QueryBuilder extends ModelEvent {
|
|
|
240
251
|
/**
|
|
241
252
|
* Set offset for pagination.
|
|
242
253
|
*/
|
|
243
|
-
static offset(value: number):
|
|
254
|
+
static offset(value: number): Builder;
|
|
244
255
|
/**
|
|
245
256
|
* Set limit for results.
|
|
246
257
|
*/
|
|
247
|
-
static limit(value: number):
|
|
258
|
+
static limit(value: number): Builder;
|
|
248
259
|
/**
|
|
249
260
|
* Add union clause.
|
|
250
261
|
*/
|
|
251
|
-
static union(queries: Builder[] | ((qb: Knex.QueryBuilder) => void) | Knex.Raw):
|
|
262
|
+
static union(queries: Builder[] | ((qb: Knex.QueryBuilder) => void) | Knex.Raw): Builder;
|
|
252
263
|
/**
|
|
253
264
|
* Add union all clause.
|
|
254
265
|
*/
|
|
255
|
-
static unionAll(queries: Builder[] | ((qb: Knex.QueryBuilder) => void) | Knex.Raw):
|
|
266
|
+
static unionAll(queries: Builder[] | ((qb: Knex.QueryBuilder) => void) | Knex.Raw): Builder;
|
|
256
267
|
/**
|
|
257
268
|
* Get SQL string of the query.
|
|
258
269
|
*/
|
|
@@ -265,6 +276,9 @@ export declare class QueryBuilder extends ModelEvent {
|
|
|
265
276
|
* Count rows or column values.
|
|
266
277
|
*/
|
|
267
278
|
static count(columns?: AggregateInput): Promise<number>;
|
|
279
|
+
/**
|
|
280
|
+
* Check if any record exists for the current query.
|
|
281
|
+
*/
|
|
268
282
|
/**
|
|
269
283
|
* Check if any record exists for the current query.
|
|
270
284
|
*/
|
|
@@ -309,7 +323,11 @@ export declare class QueryBuilder extends ModelEvent {
|
|
|
309
323
|
* Eager load the specified relationships.
|
|
310
324
|
* @param relations - The relationships to eager load
|
|
311
325
|
*/
|
|
312
|
-
|
|
326
|
+
/**
|
|
327
|
+
* Eager load the specified relationships.
|
|
328
|
+
* @param relations - The relationships to eager load
|
|
329
|
+
*/
|
|
330
|
+
static with(relations: string | string[]): Builder;
|
|
313
331
|
/**
|
|
314
332
|
* Get the eager loaded relations.
|
|
315
333
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryBuilder.d.ts","sourceRoot":"","sources":["../../../../Framework/lib/Jcc-eloquent/lib/QueryBuilder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EACL,cAAc,EACd,YAAY,EACZ,eAAe,EACf,UAAU,EACX,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,qBAAa,YAAa,SAAQ,UAAU;IAC1C,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC;IAC/B,SAAS,CAAC,MAAM,CAAC,UAAU,UAAS;IACpC,SAAS,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,CAAM;
|
|
1
|
+
{"version":3,"file":"QueryBuilder.d.ts","sourceRoot":"","sources":["../../../../Framework/lib/Jcc-eloquent/lib/QueryBuilder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EACL,cAAc,EACd,YAAY,EACZ,eAAe,EACf,UAAU,EACX,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,qBAAa,YAAa,SAAQ,UAAU;IAC1C,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC;IAC/B,SAAS,CAAC,MAAM,CAAC,UAAU,UAAS;IACpC,SAAS,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,CAAM;IACnC,SAAS,EAAE,MAAM,CAAC,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B"}
|
|
@@ -16,11 +16,7 @@ class QueryBuilder extends ModelEvent_1.ModelEvent {
|
|
|
16
16
|
* Return a query builder instance for the model's table.
|
|
17
17
|
*/
|
|
18
18
|
static query() {
|
|
19
|
-
|
|
20
|
-
this.builderInstance = new Builder_1.Builder()
|
|
21
|
-
.setModel(this)
|
|
22
|
-
.table(this.getTable());
|
|
23
|
-
return this.builderInstance;
|
|
19
|
+
return new Builder_1.Builder().setModel(this).table(this.getTable());
|
|
24
20
|
}
|
|
25
21
|
static has(relation, operator = ">=", count = 1, boolean = "and", callback) {
|
|
26
22
|
return this.query().has(relation, operator, count, boolean, callback);
|
|
@@ -33,7 +29,7 @@ class QueryBuilder extends ModelEvent_1.ModelEvent {
|
|
|
33
29
|
}
|
|
34
30
|
static clone() {
|
|
35
31
|
if (this.softDelete) {
|
|
36
|
-
this.query().whereNull("deleted_at");
|
|
32
|
+
return this.query().whereNull("deleted_at").clone();
|
|
37
33
|
}
|
|
38
34
|
return this.query().clone();
|
|
39
35
|
}
|
|
@@ -41,57 +37,46 @@ class QueryBuilder extends ModelEvent_1.ModelEvent {
|
|
|
41
37
|
* Set the table for the query.
|
|
42
38
|
*/
|
|
43
39
|
static from(tableName) {
|
|
44
|
-
this.
|
|
45
|
-
if (this.builderInstance) {
|
|
46
|
-
this.builderInstance.from(tableName);
|
|
47
|
-
}
|
|
48
|
-
return this;
|
|
40
|
+
return this.query().from(tableName);
|
|
49
41
|
}
|
|
50
42
|
/**
|
|
51
43
|
* Set the table using raw SQL.
|
|
52
44
|
*/
|
|
53
45
|
static fromRaw(query) {
|
|
54
|
-
this.query().fromRaw(query);
|
|
55
|
-
return this;
|
|
46
|
+
return this.query().fromRaw(query);
|
|
56
47
|
}
|
|
57
48
|
static joinRaw(sql, bindings) {
|
|
58
|
-
this.query().joinRaw(sql, bindings);
|
|
59
|
-
return this;
|
|
49
|
+
return this.query().joinRaw(sql, bindings);
|
|
60
50
|
}
|
|
61
51
|
/**
|
|
62
52
|
* Select specific columns.
|
|
63
53
|
*/
|
|
64
54
|
static select(...columns) {
|
|
65
|
-
this.query().select(...columns);
|
|
66
|
-
return this;
|
|
55
|
+
return this.query().select(...columns);
|
|
67
56
|
}
|
|
68
57
|
/**
|
|
69
58
|
* Add a where clause.
|
|
70
59
|
*/
|
|
71
60
|
static where(column, operator, value) {
|
|
72
|
-
this.query().where(column, operator, value);
|
|
73
|
-
return this;
|
|
61
|
+
return this.query().where(column, operator, value);
|
|
74
62
|
}
|
|
75
63
|
/**
|
|
76
64
|
* Add a where not clause.
|
|
77
65
|
*/
|
|
78
66
|
static whereNot(column, operator, value) {
|
|
79
|
-
this.query().whereNot(column, operator, value);
|
|
80
|
-
return this;
|
|
67
|
+
return this.query().whereNot(column, operator, value);
|
|
81
68
|
}
|
|
82
69
|
/**
|
|
83
70
|
* Add an or where not clause.
|
|
84
71
|
*/
|
|
85
72
|
static orWhereNot(column, operator, value) {
|
|
86
|
-
this.query().orWhereNot(column, operator, value);
|
|
87
|
-
return this;
|
|
73
|
+
return this.query().orWhereNot(column, operator, value);
|
|
88
74
|
}
|
|
89
75
|
/**
|
|
90
76
|
* Add a where not null clause.
|
|
91
77
|
*/
|
|
92
78
|
static whereNotNull(column) {
|
|
93
|
-
this.query().whereNotNull(column);
|
|
94
|
-
return this;
|
|
79
|
+
return this.query().whereNotNull(column);
|
|
95
80
|
}
|
|
96
81
|
/**
|
|
97
82
|
* Add a where exists clause.
|
|
@@ -103,8 +88,7 @@ class QueryBuilder extends ModelEvent_1.ModelEvent {
|
|
|
103
88
|
// return this;
|
|
104
89
|
// }
|
|
105
90
|
static whereExists(callback) {
|
|
106
|
-
this.query().whereExists(callback);
|
|
107
|
-
return this;
|
|
91
|
+
return this.query().whereExists(callback);
|
|
108
92
|
}
|
|
109
93
|
/**
|
|
110
94
|
* Add an or where exists clause.
|
|
@@ -116,148 +100,127 @@ class QueryBuilder extends ModelEvent_1.ModelEvent {
|
|
|
116
100
|
* Add a where between clause.
|
|
117
101
|
*/
|
|
118
102
|
static whereBetween(column, range) {
|
|
119
|
-
this.query().whereBetween(column, range);
|
|
120
|
-
return this;
|
|
103
|
+
return this.query().whereBetween(column, range);
|
|
121
104
|
}
|
|
122
105
|
/**
|
|
123
106
|
* Add an or where between clause.
|
|
124
107
|
*/
|
|
125
108
|
static orWhereBetween(column, range) {
|
|
126
|
-
this.query().orWhereBetween(column, range);
|
|
127
|
-
return this;
|
|
109
|
+
return this.query().orWhereBetween(column, range);
|
|
128
110
|
}
|
|
129
111
|
/**
|
|
130
112
|
* Add a where not between clause.
|
|
131
113
|
*/
|
|
132
114
|
static whereNotBetween(column, range) {
|
|
133
|
-
this.query().whereNotBetween(column, range);
|
|
134
|
-
return this;
|
|
115
|
+
return this.query().whereNotBetween(column, range);
|
|
135
116
|
}
|
|
136
117
|
/**
|
|
137
118
|
* Add an or where not between clause.
|
|
138
119
|
*/
|
|
139
120
|
static orWhereNotBetween(column, range) {
|
|
140
|
-
this.query().orWhereNotBetween(column, range);
|
|
141
|
-
return this;
|
|
121
|
+
return this.query().orWhereNotBetween(column, range);
|
|
142
122
|
}
|
|
143
123
|
/**
|
|
144
124
|
* Order results by column.
|
|
145
125
|
*/
|
|
146
126
|
static orderBy(column, direction = "asc") {
|
|
147
|
-
this.query().orderBy(column, direction);
|
|
148
|
-
return this;
|
|
127
|
+
return this.query().orderBy(column, direction);
|
|
149
128
|
}
|
|
150
129
|
/**
|
|
151
130
|
* Order results using raw SQL.
|
|
152
131
|
*/
|
|
153
132
|
static orderByRaw(query, bindings) {
|
|
154
|
-
this.query().orderByRaw(query, bindings);
|
|
155
|
-
return this;
|
|
133
|
+
return this.query().orderByRaw(query, bindings);
|
|
156
134
|
}
|
|
157
135
|
/**
|
|
158
136
|
* Order results by column descending.
|
|
159
137
|
*/
|
|
160
138
|
static latest(column = "id") {
|
|
161
|
-
this.query().latest(column);
|
|
162
|
-
return this;
|
|
139
|
+
return this.query().latest(column);
|
|
163
140
|
}
|
|
164
141
|
/**
|
|
165
142
|
* Order results by column ascending.
|
|
166
143
|
*/
|
|
167
144
|
static older(column = "id") {
|
|
168
|
-
this.query().older(column);
|
|
169
|
-
return this;
|
|
145
|
+
return this.query().older(column);
|
|
170
146
|
}
|
|
171
147
|
/**
|
|
172
148
|
* Add a having clause.
|
|
173
149
|
*/
|
|
174
150
|
static having(column, operator, value) {
|
|
175
|
-
this.query().having(column, operator, value);
|
|
176
|
-
return this;
|
|
151
|
+
return this.query().having(column, operator, value);
|
|
177
152
|
}
|
|
178
153
|
/**
|
|
179
154
|
* Add a having in clause.
|
|
180
155
|
*/
|
|
181
156
|
static havingIn(column, values) {
|
|
182
|
-
this.query().havingIn(column, values);
|
|
183
|
-
return this;
|
|
157
|
+
return this.query().havingIn(column, values);
|
|
184
158
|
}
|
|
185
159
|
/**
|
|
186
160
|
* Add a having not in clause.
|
|
187
161
|
*/
|
|
188
162
|
static havingNotIn(column, values) {
|
|
189
|
-
this.query().havingNotIn(column, values);
|
|
190
|
-
return this;
|
|
163
|
+
return this.query().havingNotIn(column, values);
|
|
191
164
|
}
|
|
192
165
|
/**
|
|
193
166
|
* Add a having null clause.
|
|
194
167
|
*/
|
|
195
168
|
static havingNull(column) {
|
|
196
|
-
this.query().havingNull(column);
|
|
197
|
-
return this;
|
|
169
|
+
return this.query().havingNull(column);
|
|
198
170
|
}
|
|
199
171
|
/**
|
|
200
172
|
* Add a having not null clause.
|
|
201
173
|
*/
|
|
202
174
|
static havingNotNull(column) {
|
|
203
|
-
this.query().havingNotNull(column);
|
|
204
|
-
return this;
|
|
175
|
+
return this.query().havingNotNull(column);
|
|
205
176
|
}
|
|
206
177
|
/**
|
|
207
178
|
* Add a having between clause.
|
|
208
179
|
*/
|
|
209
180
|
static havingBetween(column, values) {
|
|
210
|
-
this.query().havingBetween(column, values);
|
|
211
|
-
return this;
|
|
181
|
+
return this.query().havingBetween(column, values);
|
|
212
182
|
}
|
|
213
183
|
/**
|
|
214
184
|
* Add a having not between clause.
|
|
215
185
|
*/
|
|
216
186
|
static havingNotBetween(column, values) {
|
|
217
|
-
this.query().havingNotBetween(column, values);
|
|
218
|
-
return this;
|
|
187
|
+
return this.query().havingNotBetween(column, values);
|
|
219
188
|
}
|
|
220
189
|
/**
|
|
221
190
|
* Add a raw having clause.
|
|
222
191
|
*/
|
|
223
192
|
static havingRaw(column, values) {
|
|
224
|
-
this.query().havingRaw(column, values);
|
|
225
|
-
return this;
|
|
193
|
+
return this.query().havingRaw(column, values);
|
|
226
194
|
}
|
|
227
195
|
/**
|
|
228
196
|
* Add an or where clause.
|
|
229
197
|
*/
|
|
230
198
|
static orWhere(column, operator, value) {
|
|
231
|
-
this.query().orWhere(column, operator, value);
|
|
232
|
-
return this;
|
|
199
|
+
return this.query().orWhere(column, operator, value);
|
|
233
200
|
}
|
|
234
201
|
/**
|
|
235
202
|
* Add a where in clause.
|
|
236
203
|
*/
|
|
237
204
|
static whereIn(column, values) {
|
|
238
|
-
this.query().whereIn(column, values);
|
|
239
|
-
return this;
|
|
205
|
+
return this.query().whereIn(column, values);
|
|
240
206
|
}
|
|
241
207
|
/**
|
|
242
208
|
* Add a where like clause with wildcards.
|
|
243
209
|
*/
|
|
244
210
|
static whereLike(column, value) {
|
|
245
|
-
this.query().whereLike(column, value);
|
|
246
|
-
return this;
|
|
211
|
+
return this.query().whereLike(column, value);
|
|
247
212
|
}
|
|
248
213
|
/**
|
|
249
214
|
* Add an and where like clause.
|
|
250
215
|
*/
|
|
251
216
|
static andWhereLike(column, value) {
|
|
252
|
-
this.query().andWhereLike(column, value);
|
|
253
|
-
return this;
|
|
217
|
+
return this.query().andWhereLike(column, value);
|
|
254
218
|
}
|
|
255
219
|
/**
|
|
256
220
|
* Add an or where like clause.
|
|
257
221
|
*/
|
|
258
222
|
static orWhereLike(column, value) {
|
|
259
|
-
this.query().orWhereLike(column, value);
|
|
260
|
-
return this;
|
|
223
|
+
return this.query().orWhereLike(column, value);
|
|
261
224
|
}
|
|
262
225
|
/**
|
|
263
226
|
*
|
|
@@ -265,64 +228,55 @@ class QueryBuilder extends ModelEvent_1.ModelEvent {
|
|
|
265
228
|
* @returns
|
|
266
229
|
*/
|
|
267
230
|
static as(columnName) {
|
|
268
|
-
this.query().as(columnName);
|
|
269
|
-
return this;
|
|
231
|
+
return this.query().as(columnName);
|
|
270
232
|
}
|
|
271
233
|
/**
|
|
272
234
|
* Add a join clause.
|
|
273
235
|
*/
|
|
274
236
|
static join(table, columnOrCallback, operator, column2) {
|
|
275
|
-
this.query().join(table, columnOrCallback, operator, column2);
|
|
276
|
-
return this;
|
|
237
|
+
return this.query().join(table, columnOrCallback, operator, column2);
|
|
277
238
|
}
|
|
278
239
|
static toSQL() {
|
|
279
240
|
return this.query().toSQL();
|
|
280
241
|
}
|
|
281
242
|
static joinSub(subQuery, alias, callback) {
|
|
282
|
-
this.query().joinSub(subQuery, alias, callback);
|
|
283
|
-
return this;
|
|
243
|
+
return this.query().joinSub(subQuery, alias, callback);
|
|
284
244
|
}
|
|
285
245
|
/**
|
|
286
246
|
* Add an inner join clause.
|
|
287
247
|
*/
|
|
288
248
|
static innerJoin(table, column1, operator, column2) {
|
|
289
|
-
this.query().innerJoin(table, column1, operator, column2);
|
|
290
|
-
return this;
|
|
249
|
+
return this.query().innerJoin(table, column1, operator, column2);
|
|
291
250
|
}
|
|
292
251
|
/**
|
|
293
252
|
* Add a left join clause.
|
|
294
253
|
*/
|
|
295
254
|
static leftJoin(table, column1, column2) {
|
|
296
|
-
this.query().leftJoin(table, column1, column2);
|
|
297
|
-
return this;
|
|
255
|
+
return this.query().leftJoin(table, column1, column2);
|
|
298
256
|
}
|
|
299
257
|
/**
|
|
300
258
|
* Add a right join clause.
|
|
301
259
|
*/
|
|
302
260
|
static rightJoin(table, column1, column2) {
|
|
303
|
-
this.query().rightJoin(table, column1, column2);
|
|
304
|
-
return this;
|
|
261
|
+
return this.query().rightJoin(table, column1, column2);
|
|
305
262
|
}
|
|
306
263
|
/**
|
|
307
264
|
* Add a left outer join clause.
|
|
308
265
|
*/
|
|
309
266
|
static leftOuterJoin(table, column1, column2) {
|
|
310
|
-
this.query().leftOuterJoin(table, column1, column2);
|
|
311
|
-
return this;
|
|
267
|
+
return this.query().leftOuterJoin(table, column1, column2);
|
|
312
268
|
}
|
|
313
269
|
/**
|
|
314
270
|
* Add a right outer join clause.
|
|
315
271
|
*/
|
|
316
272
|
static rightOuterJoin(table, column1, column2) {
|
|
317
|
-
this.query().rightOuterJoin(table, column1, column2);
|
|
318
|
-
return this;
|
|
273
|
+
return this.query().rightOuterJoin(table, column1, column2);
|
|
319
274
|
}
|
|
320
275
|
/**
|
|
321
276
|
* Add a full outer join clause.
|
|
322
277
|
*/
|
|
323
278
|
static fullOuterJoin(table, column1, column2) {
|
|
324
|
-
this.query().fullOuterJoin(table, column1, column2);
|
|
325
|
-
return this;
|
|
279
|
+
return this.query().fullOuterJoin(table, column1, column2);
|
|
326
280
|
}
|
|
327
281
|
/**
|
|
328
282
|
* Clear select clause.
|
|
@@ -352,62 +306,64 @@ class QueryBuilder extends ModelEvent_1.ModelEvent {
|
|
|
352
306
|
* Add distinct clause.
|
|
353
307
|
*/
|
|
354
308
|
static distinct(...columns) {
|
|
355
|
-
this.query().distinct(...columns);
|
|
356
|
-
return this;
|
|
309
|
+
return this.query().distinct(...columns);
|
|
357
310
|
}
|
|
358
311
|
/**
|
|
359
312
|
* Add group by clause.
|
|
360
313
|
*/
|
|
361
314
|
static groupBy(...columns) {
|
|
362
|
-
this.query().groupBy(...columns);
|
|
363
|
-
return this;
|
|
315
|
+
return this.query().groupBy(...columns);
|
|
364
316
|
}
|
|
365
317
|
/**
|
|
366
318
|
* Add raw group by clause.
|
|
367
319
|
*/
|
|
368
320
|
static groupByRaw(query, bindings) {
|
|
369
|
-
this.query().groupByRaw(query, bindings);
|
|
370
|
-
return this;
|
|
321
|
+
return this.query().groupByRaw(query, bindings);
|
|
371
322
|
}
|
|
372
323
|
/**
|
|
373
324
|
* Execute query and return all results.
|
|
374
325
|
*/
|
|
375
|
-
|
|
376
|
-
|
|
326
|
+
/**
|
|
327
|
+
* Execute query and return all results.
|
|
328
|
+
*/
|
|
329
|
+
static async get() {
|
|
330
|
+
return this.query().get();
|
|
331
|
+
}
|
|
332
|
+
static async first() {
|
|
333
|
+
return this.query().first();
|
|
334
|
+
}
|
|
377
335
|
/**
|
|
378
336
|
* Execute query and return first result.
|
|
379
337
|
*/
|
|
380
338
|
static whereNull(column) {
|
|
381
|
-
this.query().whereNull(column);
|
|
382
|
-
return this;
|
|
339
|
+
return this.query().whereNull(column);
|
|
383
340
|
}
|
|
384
341
|
static restore() {
|
|
385
342
|
return this.query().update({ deleted_at: null });
|
|
386
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* Insert data into table.
|
|
346
|
+
*/
|
|
387
347
|
/**
|
|
388
348
|
* Insert data into table.
|
|
389
349
|
*/
|
|
390
350
|
static async insert(data) {
|
|
391
|
-
|
|
392
|
-
this.builderInstance = null;
|
|
393
|
-
return res;
|
|
351
|
+
return this.query().insert(data);
|
|
394
352
|
}
|
|
395
353
|
/**
|
|
396
354
|
* Update records.
|
|
397
355
|
*/
|
|
398
356
|
static async update(data) {
|
|
399
|
-
|
|
400
|
-
// this.builderInstance = null;
|
|
401
|
-
// return res;
|
|
402
|
-
return;
|
|
357
|
+
return this.query().update(data);
|
|
403
358
|
}
|
|
359
|
+
/**
|
|
360
|
+
* Delete records.
|
|
361
|
+
*/
|
|
404
362
|
/**
|
|
405
363
|
* Delete records.
|
|
406
364
|
*/
|
|
407
365
|
static async delete() {
|
|
408
|
-
|
|
409
|
-
this.builderInstance = null;
|
|
410
|
-
return res;
|
|
366
|
+
return this.query().delete();
|
|
411
367
|
}
|
|
412
368
|
/**
|
|
413
369
|
* Execute raw SQL query.
|
|
@@ -419,10 +375,11 @@ class QueryBuilder extends ModelEvent_1.ModelEvent {
|
|
|
419
375
|
* Execute raw SQL query.
|
|
420
376
|
*/
|
|
421
377
|
static async runQuery(query, bindings = []) {
|
|
422
|
-
|
|
423
|
-
this.builderInstance = null;
|
|
424
|
-
return res;
|
|
378
|
+
return this.query().runQuery(query, bindings);
|
|
425
379
|
}
|
|
380
|
+
/**
|
|
381
|
+
* Specify returning columns for insert/update.
|
|
382
|
+
*/
|
|
426
383
|
/**
|
|
427
384
|
* Specify returning columns for insert/update.
|
|
428
385
|
*/
|
|
@@ -433,29 +390,25 @@ class QueryBuilder extends ModelEvent_1.ModelEvent {
|
|
|
433
390
|
* Set offset for pagination.
|
|
434
391
|
*/
|
|
435
392
|
static offset(value) {
|
|
436
|
-
this.query().offset(value);
|
|
437
|
-
return this;
|
|
393
|
+
return this.query().offset(value);
|
|
438
394
|
}
|
|
439
395
|
/**
|
|
440
396
|
* Set limit for results.
|
|
441
397
|
*/
|
|
442
398
|
static limit(value) {
|
|
443
|
-
this.query().limit(value);
|
|
444
|
-
return this;
|
|
399
|
+
return this.query().limit(value);
|
|
445
400
|
}
|
|
446
401
|
/**
|
|
447
402
|
* Add union clause.
|
|
448
403
|
*/
|
|
449
404
|
static union(queries) {
|
|
450
|
-
this.query().union(queries);
|
|
451
|
-
return this;
|
|
405
|
+
return this.query().union(queries);
|
|
452
406
|
}
|
|
453
407
|
/**
|
|
454
408
|
* Add union all clause.
|
|
455
409
|
*/
|
|
456
410
|
static unionAll(queries) {
|
|
457
|
-
this.query().unionAll(queries);
|
|
458
|
-
return this;
|
|
411
|
+
return this.query().unionAll(queries);
|
|
459
412
|
}
|
|
460
413
|
/**
|
|
461
414
|
* Get SQL string of the query.
|
|
@@ -475,29 +428,26 @@ class QueryBuilder extends ModelEvent_1.ModelEvent {
|
|
|
475
428
|
static count(columns = "id") {
|
|
476
429
|
return this.query().count(columns);
|
|
477
430
|
}
|
|
431
|
+
/**
|
|
432
|
+
* Check if any record exists for the current query.
|
|
433
|
+
*/
|
|
478
434
|
/**
|
|
479
435
|
* Check if any record exists for the current query.
|
|
480
436
|
*/
|
|
481
437
|
static async exists() {
|
|
482
|
-
|
|
483
|
-
this.builderInstance = null;
|
|
484
|
-
return res;
|
|
438
|
+
return this.query().exists();
|
|
485
439
|
}
|
|
486
440
|
/**
|
|
487
441
|
* Check if no record exists for the current query.
|
|
488
442
|
*/
|
|
489
443
|
static async doesntExist() {
|
|
490
|
-
|
|
491
|
-
this.builderInstance = null;
|
|
492
|
-
return res;
|
|
444
|
+
return this.query().doesntExist();
|
|
493
445
|
}
|
|
494
446
|
/**
|
|
495
447
|
* Get a single column's value from the first result.
|
|
496
448
|
*/
|
|
497
449
|
static async value(column) {
|
|
498
|
-
|
|
499
|
-
this.builderInstance = null;
|
|
500
|
-
return res;
|
|
450
|
+
return this.query().value(column);
|
|
501
451
|
}
|
|
502
452
|
/**
|
|
503
453
|
* Get minimum value of column.
|
|
@@ -541,6 +491,10 @@ class QueryBuilder extends ModelEvent_1.ModelEvent {
|
|
|
541
491
|
static decrement(column, amount) {
|
|
542
492
|
return this.query().decrement(column, amount);
|
|
543
493
|
}
|
|
494
|
+
/**
|
|
495
|
+
* Eager load the specified relationships.
|
|
496
|
+
* @param relations - The relationships to eager load
|
|
497
|
+
*/
|
|
544
498
|
/**
|
|
545
499
|
* Eager load the specified relationships.
|
|
546
500
|
* @param relations - The relationships to eager load
|
|
@@ -548,6 +502,7 @@ class QueryBuilder extends ModelEvent_1.ModelEvent {
|
|
|
548
502
|
static with(relations) {
|
|
549
503
|
// this.eagerLoad = Array.isArray(relations) ? relations : [relations];
|
|
550
504
|
// return this;
|
|
505
|
+
return this.query(); // Placeholder, implementation commented out in original
|
|
551
506
|
}
|
|
552
507
|
/**
|
|
553
508
|
* Get the eager loaded relations.
|
|
@@ -572,4 +527,3 @@ class QueryBuilder extends ModelEvent_1.ModelEvent {
|
|
|
572
527
|
exports.QueryBuilder = QueryBuilder;
|
|
573
528
|
QueryBuilder.softDelete = false;
|
|
574
529
|
QueryBuilder.eagerLoad = [];
|
|
575
|
-
QueryBuilder.builderInstance = null;
|