Skip to content

Instantly share code, notes, and snippets.

View deanlandolt's full-sized avatar

Dean Landolt deanlandolt

  • NowSecure
  • Washington, DC
View GitHub Profile
/**
* A wrapper store to aggregate stores of different types as nested child stores
*/
exports.MultiType = function(entityStores) {
openObjectStore: function(storeName){
// handle nested stores with nested paths
var store = entityStores[storeName];
if(store) {
return store;
var request = require("jsgi-client").request;
when(request({
method: "GET",
url: "http://google.com/"
}, function(response) {
print("why don't you print?!");
}));
/**
* A store wrapper for collecting multiple object stores into packages
*/
var Model = require("model").Model;
exports.Package = function(name, model, stores) {
if(!stores){
stores = model;
model = {};
/*
* CouchDB store
*/
var Model = require("model").Model,
request = require("jsgi-client").request,
when = require("promise").when,
error = require("jsgi/error");
var couch = require("store/couch");
var couchStore = couch.Database("test_suite_db");
var TestModel = require("model").Model("TestModel", couchStore, {
prototype: {
testMethod: function(){
return this.foo;
}
},
staticMethod: function(id){
return this.get(id);
// exports defined out here.
exports.foo = "bar"
require(
{sys: "sys", File: "file", sqlite: "persistence/sqlite3"}
)(function () {
sys.p(File);
// Rest of program here
});
var JSFile = require("store/js-file").JSFile;
var dataPath = (require("settings").dataFolder || "data") + "/";
var foo = Package("foo");
foo.bar = foo.Package("bar");
foo.bar.baz = foo.bar.SubModel("baz",
JSFile(dataPath + "foo.bar.baz.json"),
{
prototype: {
// this fails with MethodNotAllowedError: SubModel is not allowed
var JSFile = require("store/js-file").JSFile;
var dataPath = (require("settings").dataFolder || "data") + "/";
var Package = require("package").Package;
var foo = Package("foo");
foo.bar = foo.Package("bar");
foo.bar.baz = foo.bar.SubModel("baz",
var MyClass = Model("MyClass",
require("store/xmldb").PropertyStore()),
{
properties: {
foo: {type: String},
bar: {type: Integer, optional: true, index: true},
baz: {type: Date, optional: true},
xml: String /*perhaps some kind of special class I can test with instanceof*/
}
}
// simple repl test
var test = require("model").Model("test", require("store/js-file").JSFile(),
{
properties: {
foo: {type: "string"},
bar: {type: "integer", optional: true}
}
}
);