0.0.4 • Published 12 years ago

entity-promises v0.0.4

Weekly downloads
3
License
-
Repository
github
Last release
12 years ago

Entity Promises

Promise functions for working with entity models.

Functions

  • createIntroducer: produce a function that augments objects with an id
  • introduce: pre-built introducer with an internal id generator
  • createCleaner: produce a function that removes persistence cruft

Example:

var entityp     = require("entity-promises"),
    u           = require("underscore"),
    mongocoll   = ...,
    introduce,
    clean;

introduce = entityp.createIntroducer(anIdGenerator);  // caller-suppplied id generator
clean = entityp.createCleaner("_id");                 // remove mongo identifiers

function entity(spec) {
    ....
}

/* create and persist entity instance from specification.  Return a promise of
 * the persisted instance data. 
 */
exports.create = function (spec) {

    return entity(spec)
        .then(introduce)
        .then(mq.insert)
        .then(u.first)
        .then(clean);

}
0.0.4

12 years ago

0.0.3

12 years ago

0.0.2

12 years ago