hyprmodel

1.0.5 • Public • Published

hyprmodel

Simple 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).

Example

 
var 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)
 

Install

npm install hyprmodel --save

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.5
    8
    • latest

Version History

Package Sidebar

Install

npm i hyprmodel

Weekly Downloads

8

Version

1.0.5

License

MIT

Last publish

Collaborators

  • m-onz