const MitDB = require('mit.db');
const db = new MitDB('file.db'); // this is the save file's name + extension
async function sample() {
// assuming 'somekey' exists in the Map and has a value { cool: false }
const data = db.get('somekey');
// reassigning the 'cool' property a new value
data.cool = true;
await db.set('somekey', data);
// now 'somekey' has a new value { cool: true }
}
With npm:
npm i mit.db
const MitDB = require('mit.db')
const db = new MitDB('database.json') // this is the save file's name + extension
await db.set('ciao', 'hello')
await db.set('arrivederci', 'bye')
var ansa = db.get('ciao') // ansa = hello
var asnb = db.has('arrivederci') // ansb = true
var ansc = db.entries() // ansc = [ 'ciao', 'hello' ], [ 'arrivederci', 'bye' ] ]
var ansd = db.keys() // ansd = [ 'ciao', 'arrivederci' ]
var anse = db.values() // anse = [ 'hello', 'bye' ]
db.forEach((value, key) => console.log(value, key)) // console.log = hello ciao
// console.log = bye arrivederci
// [{"key":"ciao","value":"hello"}, {"key":"arrivederci","value":"bye"}]
await db.delete('ciao')
// [{"key":"arrivederci","value":"bye"}]
// [{"key":"ciao","value":"hello"}, {"key":"arrivederci","value":"bye"}]
await db.delete('ciao')
// []
// [{"key":"ciao","value":"hello"}, {"key":"arrivederci","value":"bye"}]
var ansf = db.size() // size = 2