bfx-hf-models-adapter-lowdb
Version:
LowDB adapter for the HF database
24 lines (17 loc) • 490 B
JavaScript
const ensureMap = require('../util/ensure_map')
const idFromDocOrID = require('../util/id_from_doc_or_id')
module.exports = async (db, { mapKey, path }, docOrID, value) => {
ensureMap(db, path)
const id = idFromDocOrID(mapKey, docOrID)
const fullPath = `${path}.${id}`
const v = db.get(fullPath).value()
if (!v) {
throw new Error(`value does not exist: ${fullPath}`)
}
db.set(fullPath, {
...v,
...value
}).write()
return 1 // updated rows
}