Skip to content

Commit ec2c0cb

Browse files
committed
pg clean up
1 parent 86aea28 commit ec2c0cb

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ export class PostgresStorageAdapter {
646646
.then(() => this._ensureSchemaCollectionExists())
647647
.then(() => {
648648
const values = [className, 'schema', 'indexes', JSON.stringify(existingIndexes)]
649-
return this._client.none(`UPDATE "_SCHEMA" SET $2:name = json_object_set_key($2:name, $3::text, $4::jsonb) WHERE "className"=$1 `, values);
649+
return conn.none(`UPDATE "_SCHEMA" SET $2:name = json_object_set_key($2:name, $3::text, $4::jsonb) WHERE "className"=$1 `, values);
650650
});
651651
}
652652

@@ -1453,22 +1453,13 @@ export class PostgresStorageAdapter {
14531453
}
14541454

14551455
createIndexes(className, indexes, conn) {
1456-
conn = conn || this._client;
1457-
return conn.tx(t => {
1458-
const batch = [];
1459-
indexes.forEach((index) => {
1460-
const fieldNames = Object.keys(index.key);
1461-
const pattern = fieldNames.map((key, index) => `$${index + 3}:name`);
1462-
const qs = t.none(`CREATE INDEX $1:name ON $2:name (${pattern.join(',')})`, [index.name, className, ...fieldNames]);
1463-
batch.push(qs);
1464-
});
1465-
return t.batch(batch);
1466-
});
1456+
return (conn || this._client).tx(t => t.batch(indexes.map(i => {
1457+
return t.none('CREATE INDEX $1:name ON $2:name ($3:name)', [i.name, className, i.key]);
1458+
})));
14671459
}
14681460

14691461
dropIndexes(className, indexes, conn) {
1470-
conn = conn || this._client;
1471-
return conn.tx(t => t.batch(indexes.map(i => t.none('DROP INDEX $1:name', i))));
1462+
return (conn || this._client).tx(t => t.batch(indexes.map(i => t.none('DROP INDEX $1:name', i))));
14721463
}
14731464

14741465
getIndexes(className) {

0 commit comments

Comments
 (0)