Skip to content

Commit bbae55d

Browse files
authored
Update PostgresStorageAdapter.js (#6989)
* Update PostgresStorageAdapter.js Improve `createClass` transaction: * `await` makes it a more consistent sequence of queries * `batch` is not needed there * No need for an extra `.then` section * Update PostgresStorageAdapter.js Remove batch-dependent error code check, as it should happen automatically without batch result. * Update PostgresStorageAdapter.js Removing unused variable.
1 parent c983202 commit bbae55d

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const PostgresDuplicateColumnError = '42701';
1212
const PostgresMissingColumnError = '42703';
1313
const PostgresDuplicateObjectError = '42710';
1414
const PostgresUniqueIndexViolationError = '23505';
15-
const PostgresTransactionAbortedError = '25P02';
1615
const logger = require('../../../logger');
1716

1817
const debug = function (...args: any) {
@@ -986,29 +985,21 @@ export class PostgresStorageAdapter implements StorageAdapter {
986985
conn = conn || this._client;
987986
return conn
988987
.tx('create-class', async t => {
989-
const q1 = this.createTable(className, schema, t);
990-
const q2 = t.none(
988+
await this.createTable(className, schema, t);
989+
await t.none(
991990
'INSERT INTO "_SCHEMA" ("className", "schema", "isParseClass") VALUES ($<className>, $<schema>, true)',
992991
{ className, schema }
993992
);
994-
const q3 = this.setIndexesWithSchemaFormat(
993+
await this.setIndexesWithSchemaFormat(
995994
className,
996995
schema.indexes,
997996
{},
998997
schema.fields,
999998
t
1000999
);
1001-
// TODO: The test should not verify the returned value, and then
1002-
// the method can be simplified, to avoid returning useless stuff.
1003-
return t.batch([q1, q2, q3]);
1004-
})
1005-
.then(() => {
10061000
return toParseSchema(schema);
10071001
})
10081002
.catch(err => {
1009-
if (err.data[0].result.code === PostgresTransactionAbortedError) {
1010-
err = err.data[1].result;
1011-
}
10121003
if (
10131004
err.code === PostgresUniqueIndexViolationError &&
10141005
err.detail.includes(className)

0 commit comments

Comments
 (0)