UNPKG

suma-db

Version:

A Brazilian database that supports JSON(JavaScript Object Notation)

23 lines (20 loc) 739 B
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?.includes?.(path)))) obj[value.ID] = value.data return obj }, save() { const setter = {} Class.all().filter(a => a.ID.includes(path)).reduce((acc, arr, index) => { acc[arr.ID] = arr.data return acc }, setter) Class.put(setter) return setter } } }