function Sync(properties) { Base.call(this, properties); if (!this.entities) this.entities = group(); this._bus = mesh.attach({ collection: this.collection }, this.bus); this.initialize(); }
} extend(UserModel.prototype, { insert: function(onInsert) { this.bus({ name: "insert", data: this.toJSON() }) .on("data", extend.bind(void 0, this)) .on("end", onInsert || function() { }); }, toJSON: function() { return { _id : this._id, name : this.name, emailAddress : this.emailAddress } } }); // var bus = memory(); var bus = loki() // var bus = mongo({ host: "mongodb://127.0.0.1:27017/database" }); var user = new UserModel({ name: "Mad Max", emailAddress: "*****@*****.**", bus: mesh.attach({ collection: "users" }, bus) }); // insert user into mongodb, or any other database. The // API is the same. user.insert();
var mesh = require("mesh"); var sift = require("sift"); var http = require("mesh-http"); var bus = http(); // map CRUD operation to proper API request bus = mesh.accept( // mongodb query utility for operations sift({ name: "insert", collection: "users" }), // attach these properties to a running op mesh.attach({ url: "/register", method: "POST" }, bus), // else bus if sift() fails bus ); // POST /register { name: "blarg" } bus({ collection: "users", name: "insert", data: { name: "blarg" } });