@webtypen/webframez-core 0.0.21 → 0.0.22
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/Database/Model.d.ts
CHANGED
|
@@ -15,6 +15,32 @@ export declare class Model {
|
|
|
15
15
|
* @returns QueryBulder
|
|
16
16
|
*/
|
|
17
17
|
static where(column: any, operator: any, value: any): QueryBuilder;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new query-builder object and adds a orderBy-clause
|
|
20
|
+
* @param column
|
|
21
|
+
* @param sort
|
|
22
|
+
* @returns QueryBulder
|
|
23
|
+
*/
|
|
24
|
+
static orderBy(column: any, sort: any): QueryBuilder;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new query-builder object and executes first()
|
|
27
|
+
* @param options?
|
|
28
|
+
* @returns QueryBulder
|
|
29
|
+
*/
|
|
30
|
+
static first(options?: any): Promise<any>;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new query-builder object and executes get()
|
|
33
|
+
* @param options?
|
|
34
|
+
* @returns QueryBulder
|
|
35
|
+
*/
|
|
36
|
+
static get(options?: any): Promise<any>;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new query-builder object and executes paginate()
|
|
39
|
+
* @param count
|
|
40
|
+
* @param options?
|
|
41
|
+
* @returns QueryBulder
|
|
42
|
+
*/
|
|
43
|
+
static paginate(count: number, options?: any): Promise<any>;
|
|
18
44
|
/**
|
|
19
45
|
* Executes a database-aggregation (mostly used by no-sql connections)
|
|
20
46
|
* @param aggregation
|
package/lib/Database/Model.js
CHANGED
|
@@ -44,6 +44,63 @@ class Model {
|
|
|
44
44
|
queryBuilder.where(column, operator, value);
|
|
45
45
|
return queryBuilder;
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Creates a new query-builder object and adds a orderBy-clause
|
|
49
|
+
* @param column
|
|
50
|
+
* @param sort
|
|
51
|
+
* @returns QueryBulder
|
|
52
|
+
*/
|
|
53
|
+
static orderBy(column, sort) {
|
|
54
|
+
const model = new this();
|
|
55
|
+
const queryBuilder = new QueryBuilder_1.QueryBuilder();
|
|
56
|
+
queryBuilder.setModelMapping(this);
|
|
57
|
+
queryBuilder.table(model.__table);
|
|
58
|
+
queryBuilder.orderBy(column, sort);
|
|
59
|
+
return queryBuilder;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Creates a new query-builder object and executes first()
|
|
63
|
+
* @param options?
|
|
64
|
+
* @returns QueryBulder
|
|
65
|
+
*/
|
|
66
|
+
static first(options) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const model = new this();
|
|
69
|
+
const queryBuilder = new QueryBuilder_1.QueryBuilder();
|
|
70
|
+
queryBuilder.setModelMapping(this);
|
|
71
|
+
queryBuilder.table(model.__table);
|
|
72
|
+
return yield queryBuilder.first(options);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Creates a new query-builder object and executes get()
|
|
77
|
+
* @param options?
|
|
78
|
+
* @returns QueryBulder
|
|
79
|
+
*/
|
|
80
|
+
static get(options) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const model = new this();
|
|
83
|
+
const queryBuilder = new QueryBuilder_1.QueryBuilder();
|
|
84
|
+
queryBuilder.setModelMapping(this);
|
|
85
|
+
queryBuilder.table(model.__table);
|
|
86
|
+
return yield queryBuilder.get(options);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Creates a new query-builder object and executes paginate()
|
|
91
|
+
* @param count
|
|
92
|
+
* @param options?
|
|
93
|
+
* @returns QueryBulder
|
|
94
|
+
*/
|
|
95
|
+
static paginate(count, options) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
const model = new this();
|
|
98
|
+
const queryBuilder = new QueryBuilder_1.QueryBuilder();
|
|
99
|
+
queryBuilder.setModelMapping(this);
|
|
100
|
+
queryBuilder.table(model.__table);
|
|
101
|
+
return yield queryBuilder.paginate(count, options);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
47
104
|
/**
|
|
48
105
|
* Executes a database-aggregation (mostly used by no-sql connections)
|
|
49
106
|
* @param aggregation
|
|
@@ -2,13 +2,20 @@ export declare class QueryBuilder {
|
|
|
2
2
|
database: string | null;
|
|
3
3
|
query: any[];
|
|
4
4
|
queryTable: string;
|
|
5
|
+
sort: any[];
|
|
6
|
+
limitCount: number | null;
|
|
7
|
+
offsetCount: number | null;
|
|
5
8
|
mode: string;
|
|
6
9
|
modelMapping: null;
|
|
7
10
|
setModelMapping(model?: any | null): this;
|
|
8
11
|
table(table: string): this;
|
|
9
12
|
where(column: any, operator: any, value: any): this;
|
|
13
|
+
orderBy(column: any, sort: any): this;
|
|
14
|
+
take(count: number | null): this;
|
|
15
|
+
offset(count: number | null): this;
|
|
10
16
|
get(options?: any): Promise<any>;
|
|
11
17
|
first(options?: any): Promise<any>;
|
|
18
|
+
paginate(count: number, options?: any): Promise<any>;
|
|
12
19
|
delete(options?: {
|
|
13
20
|
mode: string;
|
|
14
21
|
}): Promise<boolean>;
|
|
@@ -16,6 +16,9 @@ class QueryBuilder {
|
|
|
16
16
|
this.database = null;
|
|
17
17
|
this.query = [];
|
|
18
18
|
this.queryTable = "";
|
|
19
|
+
this.sort = [];
|
|
20
|
+
this.limitCount = null;
|
|
21
|
+
this.offsetCount = null;
|
|
19
22
|
this.mode = "get";
|
|
20
23
|
this.modelMapping = null;
|
|
21
24
|
}
|
|
@@ -36,6 +39,21 @@ class QueryBuilder {
|
|
|
36
39
|
});
|
|
37
40
|
return this;
|
|
38
41
|
}
|
|
42
|
+
orderBy(column, sort) {
|
|
43
|
+
this.sort.push({
|
|
44
|
+
column: column,
|
|
45
|
+
sort: sort,
|
|
46
|
+
});
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
take(count) {
|
|
50
|
+
this.limitCount = count;
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
offset(count) {
|
|
54
|
+
this.offsetCount = count;
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
39
57
|
get(options) {
|
|
40
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
59
|
this.mode = "get";
|
|
@@ -62,6 +80,28 @@ class QueryBuilder {
|
|
|
62
80
|
: null;
|
|
63
81
|
});
|
|
64
82
|
}
|
|
83
|
+
paginate(count, options) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
this.mode = "paginate";
|
|
86
|
+
this.take(count);
|
|
87
|
+
if (options && options.offset !== undefined && options.offset !== null && options.offset !== false) {
|
|
88
|
+
this.offset(parseInt(options.offset));
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// @ToDo: Load offset from request
|
|
92
|
+
this.offset(null);
|
|
93
|
+
}
|
|
94
|
+
const result = yield DBConnection_1.DBConnection.runQuery(this);
|
|
95
|
+
if (options && options.disableModelMapping) {
|
|
96
|
+
return result && result.length > 0 ? result : null;
|
|
97
|
+
}
|
|
98
|
+
return result && result.length > 0 && this.modelMapping !== null
|
|
99
|
+
? result.map((el) => DBConnection_1.DBConnection.mapDataToModel(this.modelMapping, el))
|
|
100
|
+
: result && result.length > 0
|
|
101
|
+
? result
|
|
102
|
+
: null;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
65
105
|
delete(options) {
|
|
66
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
107
|
this.mode =
|
package/package.json
CHANGED
package/src/Database/Model.ts
CHANGED
|
@@ -34,6 +34,65 @@ export class Model {
|
|
|
34
34
|
|
|
35
35
|
return queryBuilder;
|
|
36
36
|
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new query-builder object and adds a orderBy-clause
|
|
40
|
+
* @param column
|
|
41
|
+
* @param sort
|
|
42
|
+
* @returns QueryBulder
|
|
43
|
+
*/
|
|
44
|
+
static orderBy(column: any, sort: any): QueryBuilder {
|
|
45
|
+
const model = new this();
|
|
46
|
+
const queryBuilder = new QueryBuilder();
|
|
47
|
+
queryBuilder.setModelMapping(this);
|
|
48
|
+
queryBuilder.table(model.__table);
|
|
49
|
+
queryBuilder.orderBy(column, sort);
|
|
50
|
+
|
|
51
|
+
return queryBuilder;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Creates a new query-builder object and executes first()
|
|
56
|
+
* @param options?
|
|
57
|
+
* @returns QueryBulder
|
|
58
|
+
*/
|
|
59
|
+
static async first(options?: any) {
|
|
60
|
+
const model = new this();
|
|
61
|
+
const queryBuilder = new QueryBuilder();
|
|
62
|
+
queryBuilder.setModelMapping(this);
|
|
63
|
+
queryBuilder.table(model.__table);
|
|
64
|
+
|
|
65
|
+
return await queryBuilder.first(options);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Creates a new query-builder object and executes get()
|
|
70
|
+
* @param options?
|
|
71
|
+
* @returns QueryBulder
|
|
72
|
+
*/
|
|
73
|
+
static async get(options?: any) {
|
|
74
|
+
const model = new this();
|
|
75
|
+
const queryBuilder = new QueryBuilder();
|
|
76
|
+
queryBuilder.setModelMapping(this);
|
|
77
|
+
queryBuilder.table(model.__table);
|
|
78
|
+
|
|
79
|
+
return await queryBuilder.get(options);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Creates a new query-builder object and executes paginate()
|
|
84
|
+
* @param count
|
|
85
|
+
* @param options?
|
|
86
|
+
* @returns QueryBulder
|
|
87
|
+
*/
|
|
88
|
+
static async paginate(count: number, options?: any) {
|
|
89
|
+
const model = new this();
|
|
90
|
+
const queryBuilder = new QueryBuilder();
|
|
91
|
+
queryBuilder.setModelMapping(this);
|
|
92
|
+
queryBuilder.table(model.__table);
|
|
93
|
+
|
|
94
|
+
return await queryBuilder.paginate(count, options);
|
|
95
|
+
}
|
|
37
96
|
|
|
38
97
|
/**
|
|
39
98
|
* Executes a database-aggregation (mostly used by no-sql connections)
|
|
@@ -5,6 +5,9 @@ export class QueryBuilder {
|
|
|
5
5
|
database: string | null = null;
|
|
6
6
|
query: any[] = [];
|
|
7
7
|
queryTable: string = "";
|
|
8
|
+
sort: any[] = [];
|
|
9
|
+
limitCount: number | null = null;
|
|
10
|
+
offsetCount: number | null = null;
|
|
8
11
|
mode = "get";
|
|
9
12
|
modelMapping = null;
|
|
10
13
|
|
|
@@ -27,6 +30,24 @@ export class QueryBuilder {
|
|
|
27
30
|
});
|
|
28
31
|
return this;
|
|
29
32
|
}
|
|
33
|
+
|
|
34
|
+
orderBy(column: any, sort: any) {
|
|
35
|
+
this.sort.push({
|
|
36
|
+
column: column,
|
|
37
|
+
sort: sort,
|
|
38
|
+
});
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
take(count: number | null) {
|
|
43
|
+
this.limitCount = count;
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
offset(count: number | null) {
|
|
48
|
+
this.offsetCount = count;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
30
51
|
|
|
31
52
|
async get(options?: any) {
|
|
32
53
|
this.mode = "get";
|
|
@@ -57,6 +78,31 @@ export class QueryBuilder {
|
|
|
57
78
|
? DBConnection.mapDataToModel(this.modelMapping, result)
|
|
58
79
|
: null;
|
|
59
80
|
}
|
|
81
|
+
|
|
82
|
+
async paginate(count: number, options?: any) {
|
|
83
|
+
this.mode = "paginate";
|
|
84
|
+
this.take(count);
|
|
85
|
+
|
|
86
|
+
if (options && options.offset !== undefined && options.offset !== null && options.offset !== false) {
|
|
87
|
+
this.offset(parseInt(options.offset));
|
|
88
|
+
} else {
|
|
89
|
+
// @ToDo: Load offset from request
|
|
90
|
+
this.offset(null);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const result = await DBConnection.runQuery(this);
|
|
94
|
+
if (options && options.disableModelMapping) {
|
|
95
|
+
return result && result.length > 0 ? result : null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return result && result.length > 0 && this.modelMapping !== null
|
|
99
|
+
? result.map((el: Model) =>
|
|
100
|
+
DBConnection.mapDataToModel(this.modelMapping, el)
|
|
101
|
+
)
|
|
102
|
+
: result && result.length > 0
|
|
103
|
+
? result
|
|
104
|
+
: null;
|
|
105
|
+
}
|
|
60
106
|
|
|
61
107
|
async delete(options?: { mode: string }) {
|
|
62
108
|
this.mode =
|