@trenskow/pged 4.0.7 → 4.0.8
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.js +7 -1
- package/package.json +1 -1
- package/query-builder.js +16 -0
package/index.js
CHANGED
|
@@ -229,7 +229,7 @@ module.exports = exports = class PGed {
|
|
|
229
229
|
|
|
230
230
|
const [query, parameters] = queryBuilder._build();
|
|
231
231
|
|
|
232
|
-
|
|
232
|
+
let result = await this.exec(
|
|
233
233
|
query,
|
|
234
234
|
parameters,
|
|
235
235
|
{
|
|
@@ -237,6 +237,12 @@ module.exports = exports = class PGed {
|
|
|
237
237
|
transaction: queryBuilder._transaction
|
|
238
238
|
});
|
|
239
239
|
|
|
240
|
+
if (['null', 'undefined'].includes(typeof result)) {
|
|
241
|
+
result = queryBuilder._defaultResult;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return result;
|
|
245
|
+
|
|
240
246
|
});
|
|
241
247
|
}
|
|
242
248
|
|
package/package.json
CHANGED
package/query-builder.js
CHANGED
|
@@ -213,6 +213,22 @@ module.exports = exports = class QueryBuilder extends CustomPromise {
|
|
|
213
213
|
return this;
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
+
sum(key) {
|
|
217
|
+
|
|
218
|
+
if (key.key) {
|
|
219
|
+
if (key.table) key = `"${this._dbCase(key.table)}"."${this._dbCase(key.key)}"`;
|
|
220
|
+
else key = `"${this._dbCase(key.key)}"`;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
this._selectKeys = [`:sum(${key}) AS sum`];
|
|
224
|
+
this._limit = 1;
|
|
225
|
+
this._first = 'sum';
|
|
226
|
+
this._defaultResult = 0;
|
|
227
|
+
|
|
228
|
+
return this;
|
|
229
|
+
|
|
230
|
+
}
|
|
231
|
+
|
|
216
232
|
onConflict(keys, action) {
|
|
217
233
|
|
|
218
234
|
if (this._command !== 'insert') throw new Error('`onConflict` is only available when inserting.');
|