1.0.5 • Published 6 years ago

hyprmodel v1.0.5

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

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
1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago