jcc-express-mvc 1.2.8 → 1.3.0
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/index.d.ts +25 -0
- package/index.d.ts.map +1 -0
- package/index.js +1 -5
- package/lib/App.d.ts +19 -0
- package/lib/App.d.ts.map +1 -0
- package/lib/Auth/AuthMiddleware.d.ts +8 -0
- package/lib/Auth/AuthMiddleware.d.ts.map +1 -0
- package/lib/Auth/index.d.ts +16 -0
- package/lib/Auth/index.d.ts.map +1 -0
- package/lib/Command-Line/NodeArtisanCommand.d.ts +7 -0
- package/lib/Command-Line/NodeArtisanCommand.d.ts.map +1 -0
- package/lib/Command-Line/command.d.ts +11 -0
- package/lib/Command-Line/command.d.ts.map +1 -0
- package/lib/Command-Line/files/Controller.d.ts +8 -0
- package/lib/Command-Line/files/Controller.d.ts.map +1 -0
- package/lib/Command-Line/files/Migration.d.ts +3 -0
- package/lib/Command-Line/files/Migration.d.ts.map +1 -0
- package/lib/Command-Line/files/Models.d.ts +8 -0
- package/lib/Command-Line/files/Models.d.ts.map +1 -0
- package/lib/Command-Line/files/Request.d.ts +8 -0
- package/lib/Command-Line/files/Request.d.ts.map +1 -0
- package/lib/Command-Line/files/ResourcesController.d.ts +8 -0
- package/lib/Command-Line/files/ResourcesController.d.ts.map +1 -0
- package/lib/Command-Line/utils.d.ts +2 -0
- package/lib/Command-Line/utils.d.ts.map +1 -0
- package/lib/Config/Config.d.ts +8 -0
- package/lib/Config/Config.d.ts.map +1 -0
- package/lib/Error/AppError.d.ts +7 -0
- package/lib/Error/AppError.d.ts.map +1 -0
- package/lib/Error/AppErrorHandler.d.ts +10 -0
- package/lib/Error/AppErrorHandler.d.ts.map +1 -0
- package/lib/Error/Constants/error.d.ts +13 -0
- package/lib/Error/Constants/error.d.ts.map +1 -0
- package/lib/Error/Constants/index.d.ts +4 -0
- package/lib/Error/Constants/index.d.ts.map +1 -0
- package/lib/HttpKernel/HttpKernel.d.ts +7 -0
- package/lib/HttpKernel/HttpKernel.d.ts.map +1 -0
- package/lib/Interface/index.d.ts +43 -0
- package/lib/Interface/index.d.ts.map +1 -0
- package/lib/Middlewares/index.d.ts +45 -0
- package/lib/Middlewares/index.d.ts.map +1 -0
- package/lib/Middlewares/isLogin.d.ts +16 -0
- package/lib/Middlewares/isLogin.d.ts.map +1 -0
- package/lib/Passport/config.d.ts +10 -0
- package/lib/Passport/config.d.ts.map +1 -0
- package/lib/Request/FormRequest.d.ts +36 -0
- package/lib/Request/FormRequest.d.ts.map +1 -0
- package/lib/Request/request.d.ts +17 -0
- package/lib/Request/request.d.ts.map +1 -0
- package/lib/Response/index.d.ts +23 -0
- package/lib/Response/index.d.ts.map +1 -0
- package/lib/Routes/RouteBuilder.d.ts +45 -0
- package/lib/Routes/RouteBuilder.d.ts.map +1 -0
- package/lib/Routes/Router.d.ts +69 -0
- package/lib/Routes/Router.d.ts.map +1 -0
- package/lib/Server/index.d.ts +8 -0
- package/lib/Server/index.d.ts.map +1 -0
- package/lib/Services/ServiceContainer.d.ts +10 -0
- package/lib/Services/ServiceContainer.d.ts.map +1 -0
- package/lib/Services/ServiceProvider.d.ts +14 -0
- package/lib/Services/ServiceProvider.d.ts.map +1 -0
- package/lib/Templating-engine/engineHelper.d.ts +45 -0
- package/lib/Templating-engine/engineHelper.d.ts.map +1 -0
- package/lib/Templating-engine/expressions.d.ts +14 -0
- package/lib/Templating-engine/expressions.d.ts.map +1 -0
- package/lib/Templating-engine/index.d.ts +83 -0
- package/lib/Templating-engine/index.d.ts.map +1 -0
- package/lib/Type/index.d.ts +24 -0
- package/lib/Type/index.d.ts.map +1 -0
- package/lib/Validation/index.d.ts +12 -0
- package/lib/Validation/index.d.ts.map +1 -0
- package/lib/Validation/rules.d.ts +5 -0
- package/lib/Validation/rules.d.ts.map +1 -0
- package/lib/Validation/validate.d.ts +196 -0
- package/lib/Validation/validate.d.ts.map +1 -0
- package/lib/util/index.d.ts +93 -0
- package/lib/util/index.d.ts.map +1 -0
- package/package.json +2 -1
- package/lib/Database/src/BaseEntity.js +0 -208
- package/lib/Database/src/BaseModel.js +0 -44
- package/lib/Database/src/Builder.js +0 -430
- package/lib/Database/src/Cast/index.js +0 -98
- package/lib/Database/src/Cast/types.js +0 -25
- package/lib/Database/src/Date/index.js +0 -36
- package/lib/Database/src/Model.js +0 -53
- package/lib/Database/src/Query.js +0 -16
- package/lib/Database/src/QueryBuilder.js +0 -354
- package/lib/Database/src/QueryInstance.js +0 -28
- package/lib/Database/src/RelationBuilder.js +0 -97
- package/lib/Database/src/Schema/BaseSchemaEntity/index.js +0 -26
- package/lib/Database/src/Schema/BluePrint/index.js +0 -257
- package/lib/Database/src/Schema/index.js +0 -18
- package/lib/Database/src/db/connection.js +0 -22
- package/lib/Database/src/type.js +0 -2
- package/lib/Database/src/utils/index.js +0 -112
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Cast = void 0;
|
|
4
|
-
const Date_1 = require("../Date");
|
|
5
|
-
const types_1 = require("./types");
|
|
6
|
-
class Cast {
|
|
7
|
-
static getCastType(cast, query) {
|
|
8
|
-
try {
|
|
9
|
-
if (Object.keys(cast).length > 0) {
|
|
10
|
-
for (let key in cast) {
|
|
11
|
-
if (typeof cast[key] !== "function") {
|
|
12
|
-
this.castData(cast[key], key, query);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
let func = cast[key];
|
|
16
|
-
if ((key.includes("set") && !query.hasOwnProperty("id")) ||
|
|
17
|
-
(func.name.includes("set") && !query.hasOwnProperty("id"))) {
|
|
18
|
-
//
|
|
19
|
-
const attributeName = this.getAttributeName(key);
|
|
20
|
-
query[attributeName] = func(query[attributeName]);
|
|
21
|
-
//
|
|
22
|
-
}
|
|
23
|
-
if ((key.includes("get") && query.hasOwnProperty("id")) ||
|
|
24
|
-
(func.name.includes("get") && query.hasOwnProperty("id"))) {
|
|
25
|
-
//
|
|
26
|
-
const attributeName = this.getAttributeName(key);
|
|
27
|
-
query[attributeName] = func(query[attributeName], query);
|
|
28
|
-
//
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return query;
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
console.log(error.message);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
static castData(castMethod, key, query) {
|
|
40
|
-
if (castMethod.includes(":")) {
|
|
41
|
-
let formater = castMethod.split(":")[1];
|
|
42
|
-
return (query[key] = this.dateTime(query[key], formater));
|
|
43
|
-
}
|
|
44
|
-
switch (castMethod.trim()) {
|
|
45
|
-
//
|
|
46
|
-
case types_1.STRING:
|
|
47
|
-
query[key] = this.string(query[key]);
|
|
48
|
-
return;
|
|
49
|
-
//
|
|
50
|
-
case types_1.DATETIME:
|
|
51
|
-
query[key] = this.dateTime(query[key], "Y-m-d H:i:s");
|
|
52
|
-
return;
|
|
53
|
-
case types_1.DATE:
|
|
54
|
-
query[key] = this.dateTime(query[key], "y-m-d");
|
|
55
|
-
return;
|
|
56
|
-
case types_1.TIME:
|
|
57
|
-
query[key] = this.dateTime(query[key], "H:i:s");
|
|
58
|
-
return;
|
|
59
|
-
case types_1.NOW:
|
|
60
|
-
query[key] = this.dateTime(query[key], types_1.NOW);
|
|
61
|
-
return;
|
|
62
|
-
//
|
|
63
|
-
case types_1.INTEGER:
|
|
64
|
-
query[key] = this.integer(query[key]);
|
|
65
|
-
return;
|
|
66
|
-
case types_1.ARRAY:
|
|
67
|
-
query[key] = this.array(query[key]);
|
|
68
|
-
return;
|
|
69
|
-
case types_1.BOOLEAN:
|
|
70
|
-
query[key] = this.boolean(query[key]);
|
|
71
|
-
return;
|
|
72
|
-
default:
|
|
73
|
-
throw new Error(`Unkown method of ${castMethod}()`);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
static string(value) {
|
|
77
|
-
return value.toString() || "";
|
|
78
|
-
}
|
|
79
|
-
static dateTime(value, format) {
|
|
80
|
-
return value ? new Date_1.DateCasting(value).format(format) : "";
|
|
81
|
-
}
|
|
82
|
-
static array(data) {
|
|
83
|
-
return data ? JSON.stringify(data) : "";
|
|
84
|
-
}
|
|
85
|
-
static integer(value) {
|
|
86
|
-
return value ? Number(value) : "";
|
|
87
|
-
}
|
|
88
|
-
static boolean(value) {
|
|
89
|
-
return Number(value) > 1 || false;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
exports.Cast = Cast;
|
|
93
|
-
Cast.getAttributeName = (attr) => {
|
|
94
|
-
return attr
|
|
95
|
-
.replace(/(set|get)/g, "")
|
|
96
|
-
.toLowerCase()
|
|
97
|
-
.trim();
|
|
98
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DATEFORMATS = exports.NOW = exports.GET = exports.SET = exports.INTEGER = exports.BOOLEAN = exports.DATE = exports.TIME = exports.TRIM = exports.ARRAY = exports.DATETIME = exports.LOWERCASE = exports.UPPERCASE = exports.CAPITALIZE = exports.STRING = void 0;
|
|
4
|
-
exports.STRING = "string";
|
|
5
|
-
exports.CAPITALIZE = "capitalize";
|
|
6
|
-
exports.UPPERCASE = "uppercase";
|
|
7
|
-
exports.LOWERCASE = "lowercase";
|
|
8
|
-
exports.DATETIME = "datetime";
|
|
9
|
-
exports.ARRAY = "array";
|
|
10
|
-
exports.TRIM = "trim";
|
|
11
|
-
exports.TIME = "time";
|
|
12
|
-
exports.DATE = "date";
|
|
13
|
-
exports.BOOLEAN = "boolean";
|
|
14
|
-
exports.INTEGER = "integer";
|
|
15
|
-
exports.SET = "set";
|
|
16
|
-
exports.GET = "get";
|
|
17
|
-
exports.NOW = "now";
|
|
18
|
-
exports.DATEFORMATS = {
|
|
19
|
-
"y-m-d": "yyyy-MM-dd",
|
|
20
|
-
"d-m-y": "dd-MM-yyyy",
|
|
21
|
-
"y/m/d": "yyyy/MM/dd",
|
|
22
|
-
"d/m/y": "dd/MM/yyyy",
|
|
23
|
-
"H:i:s": "HH:mm:ss",
|
|
24
|
-
"Y-m-d H:i:s": "yyyy-MM-dd HH:mm:ss",
|
|
25
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DateCasting = void 0;
|
|
4
|
-
const date_fns_1 = require("date-fns");
|
|
5
|
-
const types_1 = require("../Cast/types");
|
|
6
|
-
class DateCasting {
|
|
7
|
-
constructor(date) {
|
|
8
|
-
this.formatHelper = {
|
|
9
|
-
"y-m-d": "yyyy-MM-dd",
|
|
10
|
-
"d-m-y": "dd-MM-yyyy",
|
|
11
|
-
"y/m/d": "yyyy/MM/dd",
|
|
12
|
-
"d/m/y": "dd/MM/yyyy",
|
|
13
|
-
"H:i:s": "HH:mm:ss",
|
|
14
|
-
"Y-m-d H:i:s": "yyyy-MM-dd HH:mm:ss",
|
|
15
|
-
};
|
|
16
|
-
this.date = date;
|
|
17
|
-
}
|
|
18
|
-
dateToTimestamps() {
|
|
19
|
-
const date = (0, date_fns_1.parseISO)(this.date);
|
|
20
|
-
return (0, date_fns_1.getTime)(date);
|
|
21
|
-
}
|
|
22
|
-
timeToTimestamp() {
|
|
23
|
-
const combinedDateTimeString = `${(0, date_fns_1.format)(new Date(), "yyyy-MM-dd")}T${this.date}`;
|
|
24
|
-
const date = (0, date_fns_1.parse)(combinedDateTimeString, "yyyy-MM-dd'T'HH:mm:ss", new Date());
|
|
25
|
-
return (0, date_fns_1.getTime)(date);
|
|
26
|
-
}
|
|
27
|
-
format(formatStr) {
|
|
28
|
-
if (formatStr === types_1.NOW)
|
|
29
|
-
return this.diffForHumans();
|
|
30
|
-
return this.date ? (0, date_fns_1.format)(this.date, this.formatHelper[formatStr]) : "";
|
|
31
|
-
}
|
|
32
|
-
diffForHumans() {
|
|
33
|
-
return (0, date_fns_1.formatDistanceToNow)(this.date, { addSuffix: true });
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.DateCasting = DateCasting;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Model = void 0;
|
|
4
|
-
const BaseModel_1 = require("./BaseModel");
|
|
5
|
-
class Model extends BaseModel_1.BaseModel {
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
/**
|
|
9
|
-
* Retrieves a single record from the database table associated with the current model by its ID.
|
|
10
|
-
*
|
|
11
|
-
* @param {number} id - The ID of the record to retrieve.
|
|
12
|
-
* @returns {Promise<Object>} A Promise that resolves with the found record, or an empty object if not found.
|
|
13
|
-
*/
|
|
14
|
-
static async find(id) {
|
|
15
|
-
return this.select().from(this.name).where("id", id).first();
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Retrieves all records from the database table associated with the current model.
|
|
19
|
-
*
|
|
20
|
-
* @returns {Promise<any>} A Promise that resolves with all records.
|
|
21
|
-
*/
|
|
22
|
-
static async all() {
|
|
23
|
-
try {
|
|
24
|
-
return this.select().get();
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
throw new Error(error.message);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Creates one or more records in the database table associated with the current model.
|
|
32
|
-
*
|
|
33
|
-
* @param {Object|Array<Object>} data - The data or array of data to insert.
|
|
34
|
-
* @returns {Promise<any>} A Promise that resolves with the inserted data.
|
|
35
|
-
* @throws {Error} Throws an error if the data type is not supported (neither object nor array).
|
|
36
|
-
*/
|
|
37
|
-
static async create(data) {
|
|
38
|
-
try {
|
|
39
|
-
if (Array.isArray(data)) {
|
|
40
|
-
let insetedData = data.map((item) => this.insert(item));
|
|
41
|
-
return await Promise.all(insetedData);
|
|
42
|
-
}
|
|
43
|
-
if (typeof data === "object") {
|
|
44
|
-
return this.insert(data);
|
|
45
|
-
}
|
|
46
|
-
throw new Error(`${this.name}.create value should be an array or an object`);
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
throw Error(error.message);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.Model = Model;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Query = void 0;
|
|
4
|
-
const Builder_1 = require("./Builder");
|
|
5
|
-
class Query extends Builder_1.Builder {
|
|
6
|
-
constructor() {
|
|
7
|
-
super(...arguments);
|
|
8
|
-
this.query = new Builder_1.Builder();
|
|
9
|
-
}
|
|
10
|
-
static setMassAttributes(data) {
|
|
11
|
-
const { hidden, casts } = data;
|
|
12
|
-
this.query.setCasts(casts || {});
|
|
13
|
-
this.query.setHidden(hidden || []);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.Query = Query;
|
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QueryBuilder = void 0;
|
|
4
|
-
const Query_1 = require("./Query");
|
|
5
|
-
class QueryBuilder extends Query_1.Query {
|
|
6
|
-
/**
|
|
7
|
-
* Fetch the first record from the database table.
|
|
8
|
-
* The table name is derived from the current class name or the previously set table name.
|
|
9
|
-
* @returns {Object} The first record if found, otherwise an empty object.
|
|
10
|
-
*/
|
|
11
|
-
static async first() {
|
|
12
|
-
try {
|
|
13
|
-
this.query.table(this.name);
|
|
14
|
-
this.setMassAttributes({ hidden: this.hidden, casts: this.casts });
|
|
15
|
-
return this.query.first();
|
|
16
|
-
}
|
|
17
|
-
catch (error) {
|
|
18
|
-
throw new Error(error.message);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Specifies the columns to select in a query.
|
|
23
|
-
*
|
|
24
|
-
* @param {...string} columns - The columns to select.
|
|
25
|
-
* @returns {typeof QueryBuilder} The instance of the model, allowing for method chaining.
|
|
26
|
-
*/
|
|
27
|
-
static select(...columns) {
|
|
28
|
-
const columnValue = columns.length > 0 ? columns.join(", ") : "*";
|
|
29
|
-
this.query.select(columnValue);
|
|
30
|
-
return this;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Marks the query to return distinct results.
|
|
34
|
-
*
|
|
35
|
-
* @returns {typeof QueryBuilder} The instance of the model, allowing for method chaining.
|
|
36
|
-
*/
|
|
37
|
-
static distinct() {
|
|
38
|
-
this.query.distinct();
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Specifies the table to query from.
|
|
43
|
-
*
|
|
44
|
-
* @param {string} tableName - The name of the table to query from.
|
|
45
|
-
* @returns {typeof QueryBuilder} The instance of the model, allowing for method chaining.
|
|
46
|
-
*/
|
|
47
|
-
static from(tableName) {
|
|
48
|
-
this.query.from(tableName || this.name);
|
|
49
|
-
return this;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Adds a WHERE clause to the query.
|
|
53
|
-
*
|
|
54
|
-
* @param {string} column - The column to apply the condition on.
|
|
55
|
-
* @param {string} operator - The operator to use for the condition (e.g., '=', '>', '<').
|
|
56
|
-
* @param {any} value - The value to compare the column against.
|
|
57
|
-
* @returns {typeof QueryBuilder} The instance of the model, allowing for method chaining.
|
|
58
|
-
*/
|
|
59
|
-
static where(column, operator, value) {
|
|
60
|
-
this.query.where(column, operator, value);
|
|
61
|
-
return this;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Adds an OR WHERE clause to the query.
|
|
65
|
-
*
|
|
66
|
-
* @param {string} column - The column to apply the condition on.
|
|
67
|
-
* @param {string} operator - The operator to use for the condition (e.g., '=', '>', '<').
|
|
68
|
-
* @param {any} value - The value to compare the column against.
|
|
69
|
-
* @returns {typeof QueryBuilder} The instance of the model, allowing for method chaining.
|
|
70
|
-
*/
|
|
71
|
-
static orWhere(column, operator, value) {
|
|
72
|
-
if (arguments.length === 2) {
|
|
73
|
-
value = operator;
|
|
74
|
-
operator = "=";
|
|
75
|
-
}
|
|
76
|
-
this.query.orWhere(column, operator, value);
|
|
77
|
-
return this;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Specifies the column and direction for ordering the query results.
|
|
81
|
-
*
|
|
82
|
-
* @param {string} column - The column to order by.
|
|
83
|
-
* @param {string} [direction="asc"] - The direction of ordering ("asc" for ascending, "desc" for descending).
|
|
84
|
-
* @returns {typeof QueryBuilder} The instance of the model, allowing for method chaining.
|
|
85
|
-
*/
|
|
86
|
-
static orderBy(column, direction = "asc") {
|
|
87
|
-
this.query.orderBy(column, direction);
|
|
88
|
-
return this;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Limits the number of results returned by the query.
|
|
92
|
-
*
|
|
93
|
-
* @param {number} count - The maximum number of results to return.
|
|
94
|
-
* @returns {typeof QueryBuilder} The instance of the model, allowing for method chaining.
|
|
95
|
-
*/
|
|
96
|
-
static limit(value) {
|
|
97
|
-
this.query.limit(value);
|
|
98
|
-
return this;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Limits the number of results returned by the query.
|
|
102
|
-
*
|
|
103
|
-
* @param {number} count - The maximum number of results to return.
|
|
104
|
-
* @returns {typeof QueryBuilder} The instance of the model, allowing for method chaining.
|
|
105
|
-
*/
|
|
106
|
-
static take(value) {
|
|
107
|
-
this.query.limit(value);
|
|
108
|
-
return this;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Specifies the offset for starting the query results.
|
|
112
|
-
*
|
|
113
|
-
* @param {number} count - The number of rows to skip before starting to return rows.
|
|
114
|
-
* @returns {typeof QueryBuilder} The instance of the model, allowing for method chaining.
|
|
115
|
-
*/
|
|
116
|
-
static offset(count) {
|
|
117
|
-
this.query.offset(count);
|
|
118
|
-
return this;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Specifies the columns to group the query results by.
|
|
122
|
-
*
|
|
123
|
-
* @param {...string} columns - The columns to group by.
|
|
124
|
-
* @returns {typeof QueryBuilder} The instance of the model, allowing for method chaining.
|
|
125
|
-
*/
|
|
126
|
-
static groupBy(...columns) {
|
|
127
|
-
this.query.groupBy(columns);
|
|
128
|
-
return this;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Adds a HAVING clause to the query.
|
|
132
|
-
*
|
|
133
|
-
* @param {string} column - The column to apply the condition on.
|
|
134
|
-
* @param {string} operator - The operator to use for the condition (e.g., '=', '>', '<').
|
|
135
|
-
* @param {any} value - The value to compare the column against.
|
|
136
|
-
* @returns {typeof QueryBuilder} The instance of the model, allowing for method chaining.
|
|
137
|
-
*/
|
|
138
|
-
static having(column, operator, value) {
|
|
139
|
-
this.query.having(column, operator, value);
|
|
140
|
-
return this;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Adds a JOIN clause to the query.
|
|
144
|
-
*
|
|
145
|
-
* @param {string} table - The name of the table to join.
|
|
146
|
-
* @param {string} firstColumn - The column from the current table to join on.
|
|
147
|
-
* @param {string} operator - The operator to use for the join condition (e.g., '=', '>', '<').
|
|
148
|
-
* @param {string} secondColumn - The column from the joined table to join on.
|
|
149
|
-
* @returns {typeof QueryBuilder} The instance of the model, allowing for method chaining.
|
|
150
|
-
*/
|
|
151
|
-
static join(type, table, firstColumn, operator, secondColumn) {
|
|
152
|
-
this.query.join(type, table, firstColumn, operator, secondColumn);
|
|
153
|
-
return this;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Adds an INNER JOIN clause to the query.
|
|
157
|
-
*
|
|
158
|
-
* @param {string} table - The name of the table to join.
|
|
159
|
-
* @param {string} firstColumn - The column from the current table to join on.
|
|
160
|
-
* @param {string} operator - The operator to use for the join condition (e.g., '=', '>', '<').
|
|
161
|
-
* @param {string} secondColumn - The column from the joined table to join on.
|
|
162
|
-
* @returns {typeof QueryBuilder} The instance of the model, allowing for method chaining.
|
|
163
|
-
*/
|
|
164
|
-
static innerJoin(table, firstColumn, operator, secondColumn) {
|
|
165
|
-
this.join("INNER", table, firstColumn, operator, secondColumn);
|
|
166
|
-
return this;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Adds a LEFT JOIN clause to the query.
|
|
170
|
-
*
|
|
171
|
-
* @param {string} table - The name of the table to join.
|
|
172
|
-
* @param {string} firstColumn - The column from the current table to join on.
|
|
173
|
-
* @param {string} operator - The operator to use for the join condition (e.g., '=', '>', '<').
|
|
174
|
-
* @param {string} secondColumn - The column from the joined table to join on.
|
|
175
|
-
* @returns {typeof QueryBuilder} The instance of the model, allowing for method chaining.
|
|
176
|
-
*/
|
|
177
|
-
static leftJoin(table, firstColumn, operator, secondColumn) {
|
|
178
|
-
this.join("LEFT", table, firstColumn, operator, secondColumn);
|
|
179
|
-
return this;
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Adds a RIGHT JOIN clause to the query.
|
|
183
|
-
*
|
|
184
|
-
* @param {string} table - The name of the table to join.
|
|
185
|
-
* @param {string} firstColumn - The column from the current table to join on.
|
|
186
|
-
* @param {string} operator - The operator to use for the join condition (e.g., '=', '>', '<').
|
|
187
|
-
* @param {string} secondColumn - The column from the joined table to join on.
|
|
188
|
-
* @returns {typeof QueryBuilder} The instance of the model, allowing for method chaining.
|
|
189
|
-
*/
|
|
190
|
-
static rightJoin(table, firstColumn, operator, secondColumn) {
|
|
191
|
-
this.join("RIGHT", table, firstColumn, operator, secondColumn);
|
|
192
|
-
return this;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Inserts data into the database and retrieves the inserted record.
|
|
196
|
-
*
|
|
197
|
-
* @param {Object} data - The data to insert into the database.
|
|
198
|
-
* @returns {Promise<any>} The inserted record.
|
|
199
|
-
*/
|
|
200
|
-
static async insert(data) {
|
|
201
|
-
this.query.table(this.name);
|
|
202
|
-
this.setMassAttributes({ hidden: this.hidden, casts: this.casts });
|
|
203
|
-
return this.query.insert(data, this.fillable, this.guard);
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Sets the query to perform a delete operation.
|
|
207
|
-
*
|
|
208
|
-
* @returns {this} The instance of the model, allowing for method chaining.
|
|
209
|
-
*/
|
|
210
|
-
// static delete(): any {
|
|
211
|
-
// return this.query.delete();
|
|
212
|
-
// }
|
|
213
|
-
/**
|
|
214
|
-
* Executes the constructed query, loads specified relations, and resets the query builder state.
|
|
215
|
-
*
|
|
216
|
-
* @returns {Promise<Array>} A Promise that resolves with the fetched results including loaded relations.
|
|
217
|
-
*/
|
|
218
|
-
static async get() {
|
|
219
|
-
this.query.table(this.name);
|
|
220
|
-
// this.query.addHidden(this.hidden);
|
|
221
|
-
this.setMassAttributes({ hidden: this.hidden, casts: this.casts });
|
|
222
|
-
return this.query.get();
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Sets the data to update for the query.
|
|
226
|
-
*
|
|
227
|
-
* @param {Object} data - The data to update.
|
|
228
|
-
* @returns {Promise<any>} The instance of the model, allowing for method chaining.
|
|
229
|
-
*/
|
|
230
|
-
static async update(data = {}) {
|
|
231
|
-
this.query.table(this.name);
|
|
232
|
-
this.setMassAttributes({ hidden: this.hidden, casts: this.casts });
|
|
233
|
-
return this.query.update(data, this.fillable, this.guard);
|
|
234
|
-
}
|
|
235
|
-
static latest(column) {
|
|
236
|
-
this.query.latest(column);
|
|
237
|
-
return this;
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Adds the specified relationships to the model.
|
|
241
|
-
*
|
|
242
|
-
* @param {...string} relations - The names of the relationships to add.
|
|
243
|
-
* @returns {typeof QueryBuilder} The instance of the model, allowing for method chaining.
|
|
244
|
-
*/
|
|
245
|
-
static with(...relations) {
|
|
246
|
-
// if (relations.length === 0) {
|
|
247
|
-
// throw new Error("At least one relationship name must be provided.");
|
|
248
|
-
// }
|
|
249
|
-
this.query.with(relations[0]);
|
|
250
|
-
return this;
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Iterates over each record returned by the query, applies a callback function to each record, and collects the results in an array.
|
|
254
|
-
*
|
|
255
|
-
* @param {Function} callback - The function to be applied to each record. The function should accept a record as an argument and return a value.
|
|
256
|
-
* @returns {Promise<Array>} A promise that resolves to an array of results from applying the callback function to each record.
|
|
257
|
-
*/
|
|
258
|
-
static async each(callback) {
|
|
259
|
-
this.query.addHidden(this.hidden);
|
|
260
|
-
this.query.table(this.name);
|
|
261
|
-
return this.query.each(callback);
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Iterates over map record returned by the query, applies a callback function to map record, and collects the results in an array.
|
|
265
|
-
*
|
|
266
|
-
* @param {Function} callback - The function to be applied to map record. The function should accept a record as an argument and return a value.
|
|
267
|
-
* @returns {Promise<Array>} A promise that resolves to an array of results from applying the callback function to each record.
|
|
268
|
-
*/
|
|
269
|
-
static async map(callback) {
|
|
270
|
-
this.query.table(this.name);
|
|
271
|
-
this.query.addHidden(this.hidden);
|
|
272
|
-
return this.query.map(callback);
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Retrieves the value of a specified field from the first record that matches the current query conditions.
|
|
276
|
-
*
|
|
277
|
-
* @param {string} field - The field name whose value is to be retrieved.
|
|
278
|
-
* @returns {Promise<any>} A promise that resolves to the value of the specified field, or null if no records are found.
|
|
279
|
-
*/
|
|
280
|
-
static async value(field) {
|
|
281
|
-
this.query.table(this.name);
|
|
282
|
-
return this.query.value(field);
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* Checks if any records exist that match the current query conditions.
|
|
286
|
-
*
|
|
287
|
-
* @returns {Promise<boolean>} A promise that resolves to true if records exist, false otherwise.
|
|
288
|
-
*/
|
|
289
|
-
static async exists() {
|
|
290
|
-
this.query.table(this.name);
|
|
291
|
-
return this.query.exists();
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Checks if no records exist that match the current query conditions.
|
|
295
|
-
*
|
|
296
|
-
* @returns {Promise<boolean>} A promise that resolves to true if no records exist, false otherwise.
|
|
297
|
-
*/
|
|
298
|
-
static async doesntExist() {
|
|
299
|
-
this.query.table(this.name);
|
|
300
|
-
return this.query.doesntExist();
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Executes a count query based on the current query builder state.
|
|
304
|
-
*
|
|
305
|
-
* @returns {Promise<number>} A Promise that resolves with the count of records.
|
|
306
|
-
*/
|
|
307
|
-
static async count() {
|
|
308
|
-
this.query.table(this.name);
|
|
309
|
-
return this.query.count();
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Executes a max query based on the current query builder state.
|
|
313
|
-
*
|
|
314
|
-
* @returns {Promise<number>} A Promise that resolves with the max of records.
|
|
315
|
-
*/
|
|
316
|
-
static async max(column) {
|
|
317
|
-
this.query.table(this.name);
|
|
318
|
-
return this.query.max(column);
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Executes a min query based on the current query builder state.
|
|
322
|
-
*
|
|
323
|
-
* @returns {Promise<number>} A Promise that resolves with the min of records.
|
|
324
|
-
*/
|
|
325
|
-
static async min(column) {
|
|
326
|
-
this.query.table(this.name);
|
|
327
|
-
return this.query.min(column);
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* Executes a min query based on the current query builder state.
|
|
331
|
-
*
|
|
332
|
-
* @returns {Promise<number>} A Promise that resolves with the sum of records.
|
|
333
|
-
*/
|
|
334
|
-
static async sum(column) {
|
|
335
|
-
this.query.table(this.name);
|
|
336
|
-
return this.query.sum(column);
|
|
337
|
-
}
|
|
338
|
-
/**
|
|
339
|
-
* Executes a average query based on the current query builder state.
|
|
340
|
-
*
|
|
341
|
-
* @returns {Promise<number>} A Promise that resolves with the sum of records.
|
|
342
|
-
*/
|
|
343
|
-
static async avg(column) {
|
|
344
|
-
this.query.table(this.name);
|
|
345
|
-
return this.query.avg(column);
|
|
346
|
-
}
|
|
347
|
-
static resetQuery() {
|
|
348
|
-
return this.query._resetQuery();
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
exports.QueryBuilder = QueryBuilder;
|
|
352
|
-
QueryBuilder.guard = [];
|
|
353
|
-
QueryBuilder.fillable = [];
|
|
354
|
-
QueryBuilder.hidden = [];
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QueryInstance = void 0;
|
|
4
|
-
const Builder_1 = require("./Builder");
|
|
5
|
-
class QueryInstance {
|
|
6
|
-
// private attributes: Array<any> = [];
|
|
7
|
-
constructor(data) {
|
|
8
|
-
Object.assign(this, data);
|
|
9
|
-
}
|
|
10
|
-
query() {
|
|
11
|
-
return new Builder_1.Builder();
|
|
12
|
-
}
|
|
13
|
-
save() {
|
|
14
|
-
console.log(this);
|
|
15
|
-
return "Hello";
|
|
16
|
-
}
|
|
17
|
-
load() {
|
|
18
|
-
//
|
|
19
|
-
}
|
|
20
|
-
// getResult() {
|
|
21
|
-
// return this.attributes;
|
|
22
|
-
// }
|
|
23
|
-
update() {
|
|
24
|
-
return this.query().update(this);
|
|
25
|
-
console.log(this);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.QueryInstance = QueryInstance;
|