sectom
Version:
Sectom is a useful npm package that has multiple easy to use functions.
28 lines (25 loc) • 672 B
JavaScript
/**
* Deletes a section from the database from the string!
* @param {string} section
* @param {object} db
*
* @example
* const sectionName = "myUsers_123";
*
* deleteSectionFromDB(sectionName, db) // returns true if it was a success
*
*/
async function deleteSectionFromDB(section, db) {
if (!db) throw new TypeError('You must pass in the "db" parameter!');
try {
let toDelete = db
.all()
.map((entry) => entry.ID)
.filter((id) => id.startsWith(section));
toDelete.forEach(db.delete);
return true;
} catch (error) {
console.log(error);
}
}
exports.deleteSectionFromDB = deleteSectionFromDB;