Skip to content

Commit e0a31d2

Browse files
authored
improving database logic. (#4451)
improving database logic.
1 parent 08ba738 commit e0a31d2

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -863,8 +863,7 @@ export class PostgresStorageAdapter {
863863
// rejection reason are TBD.
864864
getAllClasses() {
865865
return this._ensureSchemaCollectionExists()
866-
.then(() => this._client.map('SELECT * FROM "_SCHEMA"', null, row => ({ className: row.className, ...row.schema })))
867-
.then(res => res.map(toParseSchema))
866+
.then(() => this._client.map('SELECT * FROM "_SCHEMA"', null, row => toParseSchema({ className: row.className, ...row.schema })));
868867
}
869868

870869
// Return a promise for the schema with the given name, in Parse format. If
@@ -1401,7 +1400,7 @@ export class PostgresStorageAdapter {
14011400
const constraintName = `unique_${fieldNames.sort().join('_')}`;
14021401
const constraintPatterns = fieldNames.map((fieldName, index) => `$${index + 3}:name`);
14031402
const qs = `ALTER TABLE $1:name ADD CONSTRAINT $2:name UNIQUE (${constraintPatterns.join(',')})`;
1404-
return this._client.none(qs,[className, constraintName, ...fieldNames])
1403+
return this._client.none(qs, [className, constraintName, ...fieldNames])
14051404
.catch(error => {
14061405
if (error.code === PostgresDuplicateRelationError && error.message.includes(constraintName)) {
14071406
// Index already exists. Ignore error.
@@ -1552,8 +1551,7 @@ export class PostgresStorageAdapter {
15521551

15531552
const qs = `SELECT ${columns} FROM $1:name ${wherePattern} ${sortPattern} ${limitPattern} ${skipPattern} ${groupPattern}`;
15541553
debug(qs, values);
1555-
return this._client.any(qs, values)
1556-
.then(results => results.map(object => this.postgresObjectToParseObject(className, object, schema)))
1554+
return this._client.map(qs, values, a => this.postgresObjectToParseObject(className, a, schema))
15571555
.then(results => {
15581556
if (countField) {
15591557
results[0][countField] = parseInt(results[0][countField], 10);
@@ -1579,7 +1577,7 @@ export class PostgresStorageAdapter {
15791577
});
15801578
return Promise.all(promises)
15811579
.then(() => {
1582-
return this._client.tx(t => {
1580+
return this._client.tx('perform-initialization', t => {
15831581
return t.batch([
15841582
t.none(sql.misc.jsonObjectSetKeys),
15851583
t.none(sql.array.add),

0 commit comments

Comments
 (0)