mirror of
https://github.com/appy-one/acebase.git
synced 2026-05-25 22:01:21 -06:00
29 lines
No EOL
967 B
JavaScript
29 lines
No EOL
967 B
JavaScript
const { AceBase, ID } = require("..");
|
|
const { pfs } = require('../src/promise-fs');
|
|
|
|
module.exports = {
|
|
async createTempDB(enable = { transactionLogging: false, logLevel: 'log', config: (options) => { } }) {
|
|
// Create temp db
|
|
const dbname = 'test-' + ID.generate();
|
|
const options = { storage: { path: __dirname }, logLevel: enable.logLevel || 'verbose' };
|
|
if (enable.transactionLogging === true) {
|
|
options.transactions = { log: true };
|
|
}
|
|
if (typeof enable.config === 'function') {
|
|
enable.config(options);
|
|
}
|
|
const db = new AceBase(dbname, options);
|
|
await db.ready();
|
|
|
|
const removeDB = async () => {
|
|
// Close database
|
|
await db.close();
|
|
|
|
// Remove database
|
|
const dbdir = `${__dirname}/${dbname}.acebase`;
|
|
await pfs.rmdir(dbdir, { recursive: true });
|
|
}
|
|
|
|
return { db, removeDB };
|
|
}
|
|
} |