Socket
Socket
Sign inDemoInstall

modella-glint

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    modella-glint

Glint Adapter persistence layer for [Modella](https://github.com/modella/modella/).


Version published
Weekly downloads
2
Maintainers
1
Install size
11.3 kB
Created
Weekly downloads
 

Readme

Source

modella-glint

Modella Storage Adapter for Glint Adapters

install

npm install modella-glint

usage

setup

var model = require('modella');
var Storage = require('modella-glint');
var Adapter = require('glint-adapter');
var Ajax = require('glint-adapter-ajax');

var adapter = Adapter(Ajax()).db('myDb');
var storage = Storage(adapter);

model definition (schema)


var User = model('user')
  .attr('id')
  .attr('name')
  .attr('email')
  .attr('password');

User.use(storage);

model instance

var user = new User;

user.id('hanswurst')
  .name('hans')
  .email('hans@wur.st')
  .password('grischuna');

user.save(function(err) {
  console.log(user.toJSON());
});

model functions

load(id, fn)

called on model

User.load('hanswurst', function (err, model) {
  var json = model.toJSON();
  // json.name == 'hans'
});
find(query, fn)

called on model query is dependent on the used adapter. e.g. for glint-adapter-fs, use the mingo syntax.

User.find({name: 'hans'}, function (err, model) {

  Object.keys(model).forEach(function (key) {
    var item = model[key].json();
    // item.name == 'gruyere'
    // item.email == 'gruyere@aoc.ch'
  });

});

instance functions

save(fn)

called on instance note: unlike described in the adapter plugin guide, this implementation requires the id to be set manually. if the id() aka primary() is not set, it will throw an Error.

user.save(function (err, model) {
  var json = model.toJSON();
  // json.id == 'hanswurst'
});
remove(fn)

called on instance note: modella only supports remove, but NOT delete, as it is used with glint-adapter.

user.remove(function (err, model) {
  var json = model.toJSON();
  // json.id == 'hanswurst'
});

Keywords

FAQs

Last updated on 24 Mar 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc