Examples of using lowdb NPM package

Examples of using lowdb. Lowdb is a noSQL in memory node js NPM package. It is useful as a lightweight development database. More info about lowdb can be found at https://www.npmjs.com/package/lowdb module.exports.DBLocal = () => { const low = require('lowdb') const FileSync = require('lowdb/adapters/FileSync') const adapter = new FileSync('db.json') const db = low(adapter) if (db.getState().posts === undefined || db.getState().users === undefined) { db.defaults({ posts: [], users: [] }) .write() } const create = (table, item) => { db.get(table) .push(item) .write() } const updateBy = (table, id, fieldName, newValue) => { db.get(table).find({ id: id }) .assign({ [fieldName]: newValue }) .write() } const update = (table, item) => { db.get(table) .find({id: item.id}) .assign(item) .value() } const get = async (table) => { const items = await db.get(table).value() return items } const getBy = async (table, obj) => { const items = await db.get(table).find(obj).value() return items } return { create: create, get: get, getBy: getBy, updateBy: updateBy } }