Skip to content

Commit 46f8bce

Browse files
vitaly-tflovilmart
authored andcommitted
improving database logic. (#4451)
improving database logic.
1 parent 89945ce commit 46f8bce

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
@@ -870,8 +870,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
870870
// rejection reason are TBD.
871871
getAllClasses() {
872872
return this._ensureSchemaCollectionExists()
873-
.then(() => this._client.map('SELECT * FROM "_SCHEMA"', null, row => ({ className: row.className, ...row.schema })))
874-
.then(res => res.map(toParseSchema))
873+
.then(() => this._client.map('SELECT * FROM "_SCHEMA"', null, row => toParseSchema({ className: row.className, ...row.schema })));
875874
}
876875

877876
// Return a promise for the schema with the given name, in Parse format. If
@@ -1408,7 +1407,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
14081407
const constraintName = `unique_${fieldNames.sort().join('_')}`;
14091408
const constraintPatterns = fieldNames.map((fieldName, index) => `$${index + 3}:name`);
14101409
const qs = `ALTER TABLE $1:name ADD CONSTRAINT $2:name UNIQUE (${constraintPatterns.join(',')})`;
1411-
return this._client.none(qs,[className, constraintName, ...fieldNames])
1410+
return this._client.none(qs, [className, constraintName, ...fieldNames])
14121411
.catch(error => {
14131412
if (error.code === PostgresDuplicateRelationError && error.message.includes(constraintName)) {
14141413
// Index already exists. Ignore error.
@@ -1558,8 +1557,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
15581557

15591558
const qs = `SELECT ${columns.join(',')} FROM $1:name ${wherePattern} ${sortPattern} ${limitPattern} ${skipPattern} ${groupPattern}`;
15601559
debug(qs, values);
1561-
return this._client.any(qs, values)
1562-
.then(results => results.map(object => this.postgresObjectToParseObject(className, object, schema)))
1560+
return this._client.map(qs, values, a => this.postgresObjectToParseObject(className, a, schema))
15631561
.then(results => {
15641562
if (countField) {
15651563
results[0][countField] = parseInt(results[0][countField], 10);
@@ -1585,7 +1583,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
15851583
});
15861584
return Promise.all(promises)
15871585
.then(() => {
1588-
return this._client.tx(t => {
1586+
return this._client.tx('perform-initialization', t => {
15891587
return t.batch([
15901588
t.none(sql.misc.jsonObjectSetKeys),
15911589
t.none(sql.array.add),

0 commit comments

Comments
 (0)