clarkie/dynogels

How to delete tables for all defined models?

rasovica opened this issue · 2 comments

I am writing tests,
In beforeAll I call createTables where all the tables are created prefixed by Test in their name,
How can I delete all tables after I am done with tests?
Is there deleteTables or something similar?
I know i can delete each one calling Model.deleteTable but,
that just results in 15+ lines of code inside afterAll

Shouldn't be too hard to aggregate a promise for this in your code?

function deleteAllTables() {
  return Promise.all(
    Object.values(dynogels.models).map(m =>
      new Promise((r, j) => m.deleteTable(err => err ? j(err) : r()))
    )
  );
}

Or using async:

function deleteAllTables(callback) {
  async.parallel(
    Object.values(dynogels.models).map(m => m.deleteTable.bind(m)),
    callback
  );
}

Yes, this is simple and sexy, thank you, it would be nice if you implemented it in the library however.