Persistent Enmaps
Using defer
// Load Enmap
const Enmap = require('enmap');
// Load EnmapSQLite
const EnmapSQLite = require('enmap-sqlite');
// Initialize the sqlite database with a table named "test"
const provider = new EnmapSQLite({ name: 'test' });
// Initialize the Enmap with the provider instance.
const myColl = new Enmap({ provider: provider });
// Persistent providers load in an **async** fashion
// and provide a handy defer property:
myColl.defer.then(() => {
// all data is loaded now.
console.log(myColl.size + "keys loaded");
});
// You can also await it if your function is async:
(async function() {
await myColl.defer;
console.log(myColl.size + "keys loaded");
// Do stuff here!
}());
// Persistent collections should be **closed** before shutdown:
await myColl.db.close();Last updated