refactoring database code (#4448)
* refactoring database code Starting to refactor the database code for better use of promises + ES6 generators, to prepare for ES7 await/async. * Update PostgresStorageAdapter.js * Update PostgresStorageAdapter.js naming the transaction.
This commit is contained in:
@@ -836,8 +836,6 @@ export class PostgresStorageAdapter {
|
||||
// Returns a Promise.
|
||||
deleteFields(className, schema, fieldNames) {
|
||||
debug('deleteFields', className, fieldNames);
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
fieldNames = fieldNames.reduce((list, fieldName) => {
|
||||
const field = schema.fields[fieldName]
|
||||
if (field.type !== 'Relation') {
|
||||
@@ -852,18 +850,11 @@ export class PostgresStorageAdapter {
|
||||
return `$${idx + 2}:name`;
|
||||
}).join(', DROP COLUMN');
|
||||
|
||||
const doBatch = (t) => {
|
||||
const batch = [
|
||||
t.none('UPDATE "_SCHEMA" SET "schema"=$<schema> WHERE "className"=$<className>', {schema, className})
|
||||
];
|
||||
return this._client.tx('delete-fields', function * (t) {
|
||||
yield t.none('UPDATE "_SCHEMA" SET "schema"=$<schema> WHERE "className"=$<className>', {schema, className});
|
||||
if (values.length > 1) {
|
||||
batch.push(t.none(`ALTER TABLE $1:name DROP COLUMN ${columns}`, values));
|
||||
yield t.none(`ALTER TABLE $1:name DROP COLUMN ${columns}`, values);
|
||||
}
|
||||
return batch;
|
||||
}
|
||||
return this._client.tx((t) => {
|
||||
return t.batch(doBatch(t));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user