1
0
mirror of https://github.com/matt-fidd/stratos.git synced 2026-01-02 08:19:31 +00:00

Split db utility modules down into individual parts

This commit is contained in:
2022-02-27 01:12:55 +00:00
parent e1b5b3261e
commit 59467b8bde
6 changed files with 167 additions and 140 deletions

33
utility/db/cleanDb.js Normal file
View File

@@ -0,0 +1,33 @@
'use strict';
// Import required modules
const path = require('path');
// Import user defined modules
const DatabaseConnectionPool =
require(path.join(__dirname, '../../lib/DatabaseConnectionPool'));
// Import test data object
const { data } = require('./testData');
/**
* cleanDb() Removes all records from the tables in the database to be inserted
* into
*
* @return {void}
*/
async function cleanDb() {
const conn = await new DatabaseConnectionPool();
// Remove records from tables in reverse order to which they depend on
// each other
const tables = Object.keys(data).reverse();
tables.push('sessions');
for (const table of tables)
await conn.runQuery(`DELETE FROM ${table};`);
conn.close();
}
module.exports = cleanDb;