Comparing version 0.4.1 to 0.4.3
@@ -6,2 +6,3 @@ var _ = require('underscore') | ||
, projections = {} | ||
, indexes = {} | ||
, positions = {} | ||
@@ -41,2 +42,3 @@ , keys = require('./bjorling-keys') | ||
} | ||
function getByKeySync(projectionName, key) { | ||
@@ -46,2 +48,6 @@ return getProjection(projectionName)[key] | ||
function getIndex(projectionName, index, key) { | ||
return indexes[projectionName][index][key] | ||
} | ||
function getState(projectionName, keyOrFilter, cb) { | ||
@@ -85,2 +91,8 @@ var projection = getProjection(projectionName) | ||
function setIndex(projectionName, index, key, val) { | ||
var i = indexes[projectionName] = indexes[projectionName] || {} | ||
i[index] = i[index] || {} | ||
i[index][key] = val | ||
} | ||
function getProjectionFile(projectionName) { | ||
@@ -113,2 +125,3 @@ return path.resolve(dataDir, projectionName + '.json') | ||
persistedProjection.state = projectionState | ||
persistedProjection.indexes = indexes[projectionName] || {} | ||
console.log('writing updates to "' + projectionName + '"') | ||
@@ -131,2 +144,3 @@ afs.writeFile(projectionFile, JSON.stringify(persistedProjection), function(err) { | ||
projections[projectionName] = persistedProjection.state | ||
indexes[projectionName] = persistedProjection.indexes | ||
cb(null, persistedProjection.lastProcessedPosition) | ||
@@ -144,2 +158,3 @@ }) | ||
module.exports.getByKeySync = getByKeySync | ||
module.exports.getIndex = getIndex | ||
module.exports.getProjection = getProjection | ||
@@ -151,4 +166,5 @@ module.exports.getState = getState | ||
module.exports.save = save | ||
module.exports.setIndex = setIndex | ||
module.exports.setDataLocation = function(dir) { | ||
dataDir = dir | ||
} |
@@ -61,2 +61,6 @@ var path = require('path') | ||
Bjorling.prototype.getIndex = function(index, key) { | ||
return storage.getIndex(this._projectionName, index, key) | ||
} | ||
Bjorling.prototype.load = function() { | ||
@@ -78,2 +82,6 @@ storage.load(this._projectionName) | ||
Bjorling.prototype.setIndex = function(index, key, val) { | ||
return storage.setIndex(this._projectionName, index, key, val) | ||
} | ||
Bjorling.prototype.setKey = function(key) { | ||
@@ -80,0 +88,0 @@ keys.add(this._projectionName, key) |
@@ -33,3 +33,3 @@ { | ||
, "main": "./bjorling.js" | ||
, "version": "0.4.1" | ||
, "version": "0.4.3" | ||
} |
18380
532