Skip to content

Commit 1f2f831

Browse files
vitaly-tflovilmart
authored andcommitted
Update PostgresStorageAdapter.js (#2094)
this isn't just a simplification, but also fixing a bug: the result of `count(*)` is always returned as a string that needs conversion, not as a number, because it is 64-bit, and all 64-bit numbers are returned as strings. So, the previous `=== 0` would have never worked.
1 parent e4cfe5a commit 1f2f831

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,12 @@ export class PostgresStorageAdapter {
286286
// If no objects match, reject with OBJECT_NOT_FOUND. If objects are found and deleted, resolve with undefined.
287287
// If there is some other error, reject with INTERNAL_SERVER_ERROR.
288288
deleteObjectsByQuery(className, schema, query) {
289-
return this._client.query(`WITH deleted AS (DELETE FROM $<className:name> RETURNING *) SELECT count(*) FROM deleted`, { className })
290-
.then(result => {
291-
if (result[0].count === 0) {
289+
return this._client.one(`WITH deleted AS (DELETE FROM $<className:name> RETURNING *) SELECT count(*) FROM deleted`, { className }, res=>parseInt(res.count))
290+
.then(count => {
291+
if (count === 0) {
292292
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Object not found.');
293293
} else {
294-
return result[0].count;
294+
return count;
295295
}
296296
});
297297
}

0 commit comments

Comments
 (0)