@squiz/db-lib 1.2.12 → 1.2.13-alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +5 -87
- 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,100 @@
|
|
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.
|
7
|
-
|
8
|
-
**Note:** Version bump only for package @squiz/db-lib
|
6
|
+
## [1.2.13-alpha.0](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.2...v1.2.13-alpha.0) (2023-01-13)
|
9
7
|
|
8
|
+
### Bug Fixes
|
10
9
|
|
10
|
+
- **deps:** update dependency constructs to v10.1.183 ([def2040](https://gitlab.squiz.net/developer-experience/cmp/commit/def204076fd709282067ccaa09f73f08824bdbf4))
|
11
11
|
|
12
|
+
## [1.2.12](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.2...v1.2.12) (2022-11-24)
|
12
13
|
|
14
|
+
**Note:** Version bump only for package @squiz/db-lib
|
13
15
|
|
14
16
|
## [1.2.11](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.2...v1.2.11) (2022-11-11)
|
15
17
|
|
16
18
|
**Note:** Version bump only for package @squiz/db-lib
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
20
|
## [1.2.10](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.2...v1.2.10) (2022-11-09)
|
23
21
|
|
24
22
|
**Note:** Version bump only for package @squiz/db-lib
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
24
|
## [1.2.9](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.2...v1.2.9) (2022-11-04)
|
31
25
|
|
32
26
|
**Note:** Version bump only for package @squiz/db-lib
|
33
27
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
28
|
## [1.2.2](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1...v1.2.2) (2022-09-26)
|
39
29
|
|
40
30
|
**Note:** Version bump only for package @squiz/db-lib
|
41
31
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
32
|
## [1.2.1](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1) (2022-09-23)
|
47
33
|
|
48
34
|
**Note:** Version bump only for package @squiz/db-lib
|
49
35
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
36
|
## [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
37
|
|
56
38
|
**Note:** Version bump only for package @squiz/db-lib
|
57
39
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
40
|
## [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
41
|
|
64
42
|
**Note:** Version bump only for package @squiz/db-lib
|
65
43
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
44
|
## [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
45
|
|
72
46
|
**Note:** Version bump only for package @squiz/db-lib
|
73
47
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
48
|
## [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
49
|
|
80
50
|
**Note:** Version bump only for package @squiz/db-lib
|
81
51
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
52
|
## [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
53
|
|
88
54
|
**Note:** Version bump only for package @squiz/db-lib
|
89
55
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
56
|
## [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
57
|
|
96
58
|
**Note:** Version bump only for package @squiz/db-lib
|
97
59
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
60
|
## [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
61
|
|
104
62
|
**Note:** Version bump only for package @squiz/db-lib
|
105
63
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
64
|
## [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
65
|
|
112
66
|
**Note:** Version bump only for package @squiz/db-lib
|
113
67
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
68
|
## [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
69
|
|
120
70
|
**Note:** Version bump only for package @squiz/db-lib
|
121
71
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
72
|
## [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
73
|
|
128
74
|
**Note:** Version bump only for package @squiz/db-lib
|
129
75
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
76
|
## [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
77
|
|
136
78
|
**Note:** Version bump only for package @squiz/db-lib
|
137
79
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
80
|
## [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
81
|
|
144
82
|
**Note:** Version bump only for package @squiz/db-lib
|
145
83
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
84
|
## [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
85
|
|
152
86
|
**Note:** Version bump only for package @squiz/db-lib
|
153
87
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
88
|
## [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
89
|
|
160
90
|
**Note:** Version bump only for package @squiz/db-lib
|
161
91
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
92
|
## [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
93
|
|
168
94
|
**Note:** Version bump only for package @squiz/db-lib
|
169
95
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
96
|
## [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
97
|
|
176
98
|
**Note:** Version bump only for package @squiz/db-lib
|
177
99
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
100
|
## [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
101
|
|
184
102
|
**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
|