@squiz/db-lib 1.2.12 → 1.2.13-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +9 -85
- package/lib/AbstractRepository.d.ts +2 -0
- package/lib/index.js +36 -6
- package/lib/index.js.map +2 -2
- package/package.json +7 -7
- package/src/AbstractRepository.ts +54 -6
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
@@ -3,182 +3,106 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
-
## [1.2.
|
6
|
+
## [1.2.13-alpha.1](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.2...v1.2.13-alpha.1) (2023-01-13)
|
7
7
|
|
8
|
-
|
8
|
+
### Bug Fixes
|
9
9
|
|
10
|
+
- **deps:** update dependency constructs to v10.1.183 ([def2040](https://gitlab.squiz.net/developer-experience/cmp/commit/def204076fd709282067ccaa09f73f08824bdbf4))
|
10
11
|
|
12
|
+
## [1.2.13-alpha.0](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.2...v1.2.13-alpha.0) (2023-01-13)
|
11
13
|
|
14
|
+
### Bug Fixes
|
12
15
|
|
16
|
+
- **deps:** update dependency constructs to v10.1.183 ([def2040](https://gitlab.squiz.net/developer-experience/cmp/commit/def204076fd709282067ccaa09f73f08824bdbf4))
|
13
17
|
|
14
|
-
## [1.2.
|
18
|
+
## [1.2.12](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.2...v1.2.12) (2022-11-24)
|
15
19
|
|
16
20
|
**Note:** Version bump only for package @squiz/db-lib
|
17
21
|
|
22
|
+
## [1.2.11](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.2...v1.2.11) (2022-11-11)
|
18
23
|
|
19
|
-
|
20
|
-
|
24
|
+
**Note:** Version bump only for package @squiz/db-lib
|
21
25
|
|
22
26
|
## [1.2.10](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.2...v1.2.10) (2022-11-09)
|
23
27
|
|
24
28
|
**Note:** Version bump only for package @squiz/db-lib
|
25
29
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
30
|
## [1.2.9](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.2...v1.2.9) (2022-11-04)
|
31
31
|
|
32
32
|
**Note:** Version bump only for package @squiz/db-lib
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
34
|
## [1.2.2](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1...v1.2.2) (2022-09-26)
|
39
35
|
|
40
36
|
**Note:** Version bump only for package @squiz/db-lib
|
41
37
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
38
|
## [1.2.1](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1) (2022-09-23)
|
47
39
|
|
48
40
|
**Note:** Version bump only for package @squiz/db-lib
|
49
41
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
42
|
## [1.2.1-alpha.107](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.107) (2022-09-21)
|
55
43
|
|
56
44
|
**Note:** Version bump only for package @squiz/db-lib
|
57
45
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
46
|
## [1.2.1-alpha.106](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.106) (2022-09-02)
|
63
47
|
|
64
48
|
**Note:** Version bump only for package @squiz/db-lib
|
65
49
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
50
|
## [1.2.1-alpha.105](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.105) (2022-08-26)
|
71
51
|
|
72
52
|
**Note:** Version bump only for package @squiz/db-lib
|
73
53
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
54
|
## [1.2.1-alpha.104](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.104) (2022-08-23)
|
79
55
|
|
80
56
|
**Note:** Version bump only for package @squiz/db-lib
|
81
57
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
58
|
## [1.2.1-alpha.103](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.103) (2022-08-23)
|
87
59
|
|
88
60
|
**Note:** Version bump only for package @squiz/db-lib
|
89
61
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
62
|
## [1.2.1-alpha.102](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.102) (2022-08-23)
|
95
63
|
|
96
64
|
**Note:** Version bump only for package @squiz/db-lib
|
97
65
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
66
|
## [1.2.1-alpha.101](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.101) (2022-08-19)
|
103
67
|
|
104
68
|
**Note:** Version bump only for package @squiz/db-lib
|
105
69
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
70
|
## [1.2.1-alpha.100](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.100) (2022-08-18)
|
111
71
|
|
112
72
|
**Note:** Version bump only for package @squiz/db-lib
|
113
73
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
74
|
## [1.2.1-alpha.99](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.99) (2022-08-18)
|
119
75
|
|
120
76
|
**Note:** Version bump only for package @squiz/db-lib
|
121
77
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
78
|
## [1.2.1-alpha.98](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.98) (2022-08-17)
|
127
79
|
|
128
80
|
**Note:** Version bump only for package @squiz/db-lib
|
129
81
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
82
|
## [1.2.1-alpha.97](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.97) (2022-08-17)
|
135
83
|
|
136
84
|
**Note:** Version bump only for package @squiz/db-lib
|
137
85
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
86
|
## [1.2.1-alpha.96](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.96) (2022-08-12)
|
143
87
|
|
144
88
|
**Note:** Version bump only for package @squiz/db-lib
|
145
89
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
90
|
## [1.2.1-alpha.95](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.95) (2022-08-10)
|
151
91
|
|
152
92
|
**Note:** Version bump only for package @squiz/db-lib
|
153
93
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
94
|
## [1.2.1-alpha.90](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.89...v1.2.1-alpha.90) (2022-08-05)
|
159
95
|
|
160
96
|
**Note:** Version bump only for package @squiz/db-lib
|
161
97
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
98
|
## [1.2.1-alpha.89](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.88...v1.2.1-alpha.89) (2022-08-05)
|
167
99
|
|
168
100
|
**Note:** Version bump only for package @squiz/db-lib
|
169
101
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
102
|
## [1.2.1-alpha.88](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.67...v1.2.1-alpha.88) (2022-08-05)
|
175
103
|
|
176
104
|
**Note:** Version bump only for package @squiz/db-lib
|
177
105
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
106
|
## [1.2.1-alpha.87](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.67...v1.2.1-alpha.87) (2022-08-05)
|
183
107
|
|
184
108
|
**Note:** Version bump only for package @squiz/db-lib
|
@@ -50,4 +50,6 @@ export declare abstract class AbstractRepository<T extends object, ObjT extends
|
|
50
50
|
findAll(): Promise<T[]>;
|
51
51
|
getCount(item?: Partial<T> | null): Promise<number>;
|
52
52
|
getPage(pageNumber: number, sortBy?: (keyof T)[], direction?: SortDirection, pageSize?: number | null, item?: Partial<T> | null): Promise<PageResult<T>>;
|
53
|
+
getCountRaw(whereClause?: string, values?: any[], tableRef?: string): Promise<number>;
|
54
|
+
getPageRaw(pageNumber: number, sortBy?: (keyof T)[], direction?: SortDirection, whereClause?: string, tableRef?: string, values?: any[], pageSize?: number | null): Promise<PageResult<T>>;
|
53
55
|
}
|
package/lib/index.js
CHANGED
@@ -31165,12 +31165,7 @@ var AbstractRepository = class {
|
|
31165
31165
|
if (item) {
|
31166
31166
|
whereClause = `WHERE ${this.createWhereStringFromPartialModel(item)}`;
|
31167
31167
|
}
|
31168
|
-
|
31169
|
-
`SELECT count(*)
|
31170
|
-
FROM ${this.tableName} ${whereClause}`,
|
31171
|
-
item ? Object.values(item) : []
|
31172
|
-
);
|
31173
|
-
return parseInt(result[0].count);
|
31168
|
+
return this.getCountRaw(whereClause, item ? Object.values(item) : []);
|
31174
31169
|
}
|
31175
31170
|
async getPage(pageNumber, sortBy = [], direction = "asc", pageSize = null, item = null) {
|
31176
31171
|
if (pageSize === null) {
|
@@ -31204,6 +31199,41 @@ var AbstractRepository = class {
|
|
31204
31199
|
pageSize
|
31205
31200
|
};
|
31206
31201
|
}
|
31202
|
+
async getCountRaw(whereClause = "", values = [], tableRef = "") {
|
31203
|
+
const result = await this.executeQueryRaw(
|
31204
|
+
`SELECT COUNT(*) FROM ${this.tableName} ${tableRef} ${whereClause}`,
|
31205
|
+
values
|
31206
|
+
);
|
31207
|
+
return parseInt(result[0].count);
|
31208
|
+
}
|
31209
|
+
async getPageRaw(pageNumber, sortBy = [], direction = "asc", whereClause = "", tableRef = "", values = [], pageSize = null) {
|
31210
|
+
if (pageSize === null) {
|
31211
|
+
pageSize = DEFAULT_PAGE_SIZE;
|
31212
|
+
}
|
31213
|
+
if (pageNumber <= 0) {
|
31214
|
+
throw new Error(`Page number value cannot be less than 1`);
|
31215
|
+
}
|
31216
|
+
if (pageSize <= 0) {
|
31217
|
+
throw new Error(`Page size value cannot be less than 1`);
|
31218
|
+
}
|
31219
|
+
let orderByClause = "";
|
31220
|
+
if (sortBy.length) {
|
31221
|
+
orderByClause = `ORDER BY ${sortBy.join(",")} ${direction}`;
|
31222
|
+
}
|
31223
|
+
const offset = (pageNumber - 1) * pageSize;
|
31224
|
+
const query = `
|
31225
|
+
SELECT *
|
31226
|
+
FROM ${this.tableName} ${tableRef} ${whereClause} ${orderByClause}
|
31227
|
+
OFFSET ${offset}
|
31228
|
+
LIMIT ${pageSize}
|
31229
|
+
`;
|
31230
|
+
const items = await this.executeQuery(query, values);
|
31231
|
+
return {
|
31232
|
+
items,
|
31233
|
+
totalCount: await this.getCountRaw(whereClause, values, tableRef),
|
31234
|
+
pageSize
|
31235
|
+
};
|
31236
|
+
}
|
31207
31237
|
};
|
31208
31238
|
|
31209
31239
|
// src/ConnectionManager.ts
|