JSPM

modella-glint

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q18748F
  • License MIT

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

Package Exports

  • modella-glint

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (modella-glint) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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'
});