Fix issue #196: make memory provider DBs sharable

This commit is contained in:
David Humphrey 2014-05-22 13:37:15 -04:00
parent 247ebd113a
commit 185c05e742
1 changed files with 14 additions and 2 deletions

View File

@ -1,8 +1,20 @@
define(function(require) { define(function(require) {
var FILE_SYSTEM_NAME = require('src/constants').FILE_SYSTEM_NAME; var FILE_SYSTEM_NAME = require('src/constants').FILE_SYSTEM_NAME;
var asyncCallback = require('async').nextTick; var asyncCallback = require('async').nextTick;
/**
* Make shared in-memory DBs possible when using the same name.
*/
var createDB = (function() {
var pool = {};
return function getOrCreate(name) {
if(!pool[name]) {
pool[name] = {};
}
return pool[name];
};
}());
function MemoryContext(db, readOnly) { function MemoryContext(db, readOnly) {
this.readOnly = readOnly; this.readOnly = readOnly;
this.objectStore = db; this.objectStore = db;
@ -50,7 +62,7 @@ define(function(require) {
function Memory(name) { function Memory(name) {
this.name = name || FILE_SYSTEM_NAME; this.name = name || FILE_SYSTEM_NAME;
this.db = {}; this.db = createDB(this.name);
} }
Memory.isSupported = function() { Memory.isSupported = function() {
return true; return true;