suma-db
Version:
A Brazilian database that supports JSON(JavaScript Object Notation)
23 lines (20 loc) • 743 B
JavaScript
module.exports = function (Class, { path }) {
if (!path) throw new RangeError("Cannot acess the path to filter de db")
if (typeof path !== 'string') throw new RangeError("Invalid path");
return {
get cache() {
const obj = {}
for(const [, value] of Object.entries(Class.all().filter(data => data.ID?.startsWith?.(path)))) obj[value.ID] = value.data
return obj
},
save() {
const setter = {}
Class.all().filter(a => a.ID.startsWith(path)).reduce((acc, arr, index) => {
acc[arr.ID] = arr.data
return acc
}, setter)
Class.put(setter)
return setter
}
}
}