Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleanup stores and refactor DefaultStore

  • Loading branch information...
commit ed73b560d4afd9ecc0335d4b31d70e0f4ca88f7f 1 parent 28087f6
@kriszyp kriszyp authored
Showing with 12 additions and 38 deletions.
  1. +12 −4 lib/model.js
  2. +0 −34 lib/stores.js
View
16 lib/model.js
@@ -1,8 +1,8 @@
var Permissive = require("./facet").Permissive;
var stores = require("./stores"),
- DefaultStore = stores.DefaultStore,
registerStore = stores.registerStore,
+ JSFile = require("./store/js-file").JSFile,
NotFoundError = require("./errors").NotFoundError,
defineProperty = require("es5-helper").defineProperty;
@@ -17,10 +17,19 @@ exports.Model = function(name, store, schema){
}
if(!store){
- store= new DefaultStore(name);
+ store = JSFile((require("settings").dataFolder || "data") + "/" + name);
}
+ store.id = name;
+ if(!store.create){
+ // map create to put in case it only implements the WebSimpleDB API
+ store.create = store.put;
+ }
+
schema.id = name;
schemas[name] = schema;
+ if(typeof store.setSchema === "function"){
+ store.setSchema(schema);
+ }
if(typeof schema !== "function"){
schema = Permissive(store, schema);
}
@@ -32,8 +41,7 @@ exports.Model = function(name, store, schema){
};
}
});
- models[name] = schema;
- return registerStore(name, store, schema);
+ return models[name] = schema;
};
exports.openObjectStore = function(name){
View
34 lib/stores.js
@@ -3,14 +3,9 @@
* objects and the underlying data stores.
*/
-exports.DefaultStore = function(name){
- return JSFile((require("settings").dataFolder || "data") + "/" + name);
-};
var stores = {};
var storesForDefault = {};
-var schemas = {};
-var classes = {};
var defaultDatabase = {
transaction: function(){
// these for independent stores, and the main transaction handler calls the commit and abort for us
@@ -25,18 +20,6 @@ var defaultDatabase = {
var DatabaseError = require("./errors").DatabaseError,
NotFoundError = require("./errors").NotFoundError;
-exports.registerStore = function(name, store, schema){
- schema = schema || {};//(store.getSchema ? store.getSchema() : {});
- storesForDefault[name] = store;
- store.id = name;
- if(!store.create){
- // map create to put in case it only implements the WebSimpleDB API
- store.create = store.put;
- }
- stores[name] = defaultDatabase;
- classes[name] = schema;
- return schema;
-};
var nextDatabaseId = 1;
exports.registerDatabase = function(database, storeNames){
var previousDatabase = defaultDatabase;
@@ -44,22 +27,10 @@ exports.registerDatabase = function(database, storeNames){
previousDatabase = previousDatabase.nextDatabase
}
previousDatabase.nextDatabase = database;
- if(storeNames){
- storeNames.forEach(function(name){
- stores[name] = database;
- });
- }
database.id = nextDatabaseId++;
};
var transactions = {};
-exports.openObjectStore = function(storeName){
- var store = stores[storeName];
- if(!store){
- throw new NotFoundError(storeName + " not found");
- }
- return store;
-}
exports.transaction = function(){
var database = defaultDatabase;
@@ -133,8 +104,3 @@ exports.AutoTransaction = function(store, database){
}
return store;
}
-
-exports.classSchema = {};
-exports.classModel = exports.registerStore("Class", require("./store/memory").Memory({index: schemas}), exports.classSchema);
-
-var JSFile = require("./store/js-file").JSFile;
Please sign in to comment.
Something went wrong with that request. Please try again.