npm install hyprmodelSimple model on top of hyperdb
A model is saved as a single hyperdb key with this pattern: /{model_name}.json.
Adding a new item to the model will replace this key with the updated structure.
Using the same id or name will update included keys and leave the original keys intact (uses Object.assign).
jsvar hyperdb = require ('hyperdb')
var hyprmodel = require('hyprmodel')
var crypto = require('crypto')
var http = require('http')
var db = new hyperdb ('example.db', { valueEncoding: 'utf-8' })
var m = hyprmodel (db, 'turnips')
// create hyperdb key: /turnips.json
m.add({
id: crypto.randomBytes(11).toString('hex'),
name: Math.random()
})
http.createServer(function (req, res) {
res.setHeader('Content-Type', 'application/json')
if (!req.url.startsWith('/api/turnips')) return res.end('no dice.')
m.get(function (e, i) {
if (!e) res.end(i)
else res.end('@')
})
}).listen(8000)
`$3
`sh
npm install hyprmodel --save
``