Skip to content

Commit 271608b

Browse files
vitaly-tArthur Cinader
authored and
Arthur Cinader
committed
Update PostgresStorageAdapter.js (#3578)
* Update PostgresStorageAdapter.js proper database API, via transaction. * Update PostgresStorageAdapter.js fixing bracket. * Update PostgresStorageAdapter.js adding the same rejection approach as before, the functionality remains identical. * Update PostgresStorageAdapter.js * Update PostgresStorageAdapter.js lint fixing * Update PostgresStorageAdapter.js fixing misspelling.
1 parent 5c5ef03 commit 271608b

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,41 +1160,35 @@ export class PostgresStorageAdapter {
11601160
}
11611161

11621162
performInitialization({ VolatileClassesSchemas }) {
1163-
const now = new Date().getTime();
11641163
debug('performInitialization');
1165-
let promises = VolatileClassesSchemas.map((schema) => {
1166-
return this.createTable(schema.className, schema).catch((err) =>{
1164+
const promises = VolatileClassesSchemas.map((schema) => {
1165+
return this.createTable(schema.className, schema).catch((err) => {
11671166
if (err.code === PostgresDuplicateRelationError || err.code === Parse.Error.INVALID_CLASS_NAME) {
11681167
return Promise.resolve();
11691168
}
11701169
throw err;
11711170
});
11721171
});
1173-
/* eslint-disable no-console */
1174-
promises = promises.concat([
1175-
this._client.none(sql.misc.jsonObjectSetKeys).catch((err) => {
1176-
console.error(err);
1177-
}),
1178-
this._client.none(sql.array.add).catch((err) => {
1179-
console.error(err);
1180-
}),
1181-
this._client.none(sql.array.addUnique).catch((err) => {
1182-
console.error(err);
1183-
}),
1184-
this._client.none(sql.array.remove).catch((err) => {
1185-
console.error(err);
1186-
}),
1187-
this._client.none(sql.array.containsAll).catch((err) => {
1188-
console.error(err);
1189-
}),
1190-
this._client.none(sql.array.contains).catch((err) => {
1191-
console.error(err);
1172+
return Promise.all(promises)
1173+
.then(() => {
1174+
return this._client.tx(t => {
1175+
return t.batch([
1176+
t.none(sql.misc.jsonObjectSetKeys),
1177+
t.none(sql.array.add),
1178+
t.none(sql.array.addUnique),
1179+
t.none(sql.array.remove),
1180+
t.none(sql.array.containsAll),
1181+
t.none(sql.array.contains)
1182+
]);
1183+
});
1184+
})
1185+
.then(data => {
1186+
debug(`initializationDone in ${data.duration}`);
11921187
})
1193-
]);
1194-
/* eslint-enable no-console */
1195-
return Promise.all(promises).then(() => {
1196-
debug(`initialzationDone in ${new Date().getTime() - now}`);
1197-
}, () => {});
1188+
.catch(error => {
1189+
/* eslint-disable no-console */
1190+
console.error(error);
1191+
});
11981192
}
11991193
}
12001194

0 commit comments

Comments
 (0)