Skip to content

Commit

Permalink
removed some functions and removed couchDb implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriano Raiano committed Mar 30, 2012
1 parent fdb22a2 commit 9eabd84
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 1,162 deletions.
5 changes: 0 additions & 5 deletions bench/storageAddEventsBench.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ util.prepare(function() {
deferred.resolve();
});
}, {defer: true})
.add('couchDbStorage#addEvents', function(deferred) {
util.couchDbStorage.addEvents([{streamId: uuid().toString(), commitId: uuid().toString(), payload: {event:'bla'}}], function() {
deferred.resolve();
});
}, {defer: true})
// add listeners
.on('cycle', function(event, bench) {
console.log(String(bench));
Expand Down
13 changes: 1 addition & 12 deletions bench/storageGetEventsBench.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,8 @@ util.prepare(function() {
util.redisStorage.addEvents(events, function(err) {
callback(err);
});
},

function(callback){
util.couchDbStorage.addEvents(events, function(err) {
callback(err);
});
}

],

function(err, results){
Expand All @@ -57,11 +51,6 @@ util.prepare(function() {
deferred.resolve();
});
}, {defer: true})
.add('couchDbStorage#getEvents', function(deferred) {
util.couchDbStorage.getEvents('2', 0, -1, function(err, events) {
deferred.resolve();
});
}, {defer: true})
// add listeners
.on('cycle', function(event, bench) {
console.log(String(bench));
Expand Down
5 changes: 0 additions & 5 deletions bench/storageGetIdBench.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ util.prepare(function() {
//deferred.resolve();
});
}, {defer: false})
.add('couchDbStorage#getId', function(deferred) {
util.couchDbStorage.getId(function(err, id) {
//deferred.resolve();
});
}, {defer: false})
// add listeners
.on('cycle', function(event, bench) {
console.log(String(bench));
Expand Down
7 changes: 0 additions & 7 deletions bench/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ index.prepare = function(clb) {
index.redisStorage = storage;
callback(err, storage);
});
},

function(callback){
require('../storage/couchDb/storage').createStorage(options, function(err, storage) {
index.couchDbStorage = storage;
callback(err, storage);
});
}

],
Expand Down
77 changes: 22 additions & 55 deletions lib/eventStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,80 +382,47 @@ Store.prototype = {
this.storage.getId(callback);

},

// __getAllEvents:__ loads the events from given storage.
//
// __warning:__ don't use this in production!!!

// __getEvents:__ loads the eventstream from _revMin_ to _revMax_.
//
// `eventStore.getAllEvents(callback)`
// `eventStore.getEventStream(streamId, minRev, maxRev, callback)`
//
// - __streamId:__ id for requested stream (equal to aggregateId)
// - __revMin:__ revision startpoint [optional]
// - __revMax:__ revision endpoint (hint: -1 = to end) [optional]
// - __callback:__ `function(err, events){}`
getAllEvents: function(callback) {
getEvents: function(streamId, revMin, revMax, callback) {

if (this.hasConfigurationErrors(callback)) return;

this.storage.getAllEvents(function(err, events) {

if (typeof callback === 'function') {
callback(err, events);
}
});

},

// __getLastEventOfStream:__ loads the last event from the given stream in storage.
//
// `eventStore.getLastEventOfStream(streamId, callback)`
//
// - __streamId:__ the stream id
// - __callback:__ `function(err, event){}`
getLastEventOfStream: function(streamId, callback) {
if (typeof revMin === 'function') {
callback = revMin;
revMin = 0;
revMax = -1;
} else if (typeof revMax === 'function') {
callback = revMax;
revMax = -1;
}

if (this.hasConfigurationErrors(callback)) return;

this.storage.getLastEventOfStream(streamId, function(err, event) {

if (typeof callback === 'function') {
callback(err, event);
}
});

},

// __getEventRange:__ loads the events from given storage.
//
// `eventStore.getEventRange(index, amount, callback)`
//
// - __index:__ entry index
// - __amount:__ amount of events
// - __callback:__ `function(err, events){}`
getEventRange: function(index, amount, callback) {
var self = this;
this.storage.getEvents(streamId, revMin, revMax, callback);

if (this.hasConfigurationErrors(callback)) return;

this.storage.getEventRange(index, amount, function(err, events) {

if (typeof callback === 'function') {
callback(err, events);
}
});

},

// __getEventRangeMatching:__ loads the range of events from given storage.
// __getEventRange:__ loads the range of events from given storage.
//
// `storage.getEventRangeMatching(match, amount, callback)`
// `storage.getEventRange(match, amount, callback)`
//
// - __match:__ match query in inner event (payload)
// - __amount:__ amount of events
// - __callback:__ `function(err, events){}`
getEventRangeMatching: function(match, amount, callback) {
getEventRange: function(match, amount, callback) {

if (this.hasConfigurationErrors(callback)) return;

var self = this;

this.storage.getEventRangeMatching(match, amount, function(err, events) {
this.storage.getEventRange(match, amount, function(err, events) {

events.next = function(callback) {

Expand All @@ -468,7 +435,7 @@ Store.prototype = {
}
}

self.getEventRangeMatching(match, amount, callback);
self.getEventRange(match, amount, callback);

};

Expand Down
71 changes: 3 additions & 68 deletions lib/storage/inMemory/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Storage.prototype = {
// - __streamId:__ id for requested stream
// - __minRev:__ revision startpoint
// - __maxRev:__ revision endpoint (hint: -1 = to end) [optional]
// - __callback:__ `function(err, snapshot, eventStream){}`
// - __callback:__ `function(err, events){}`
getEvents: function(streamId, minRev, maxRev, callback) {

if (typeof maxRev === 'function') {
Expand All @@ -117,80 +117,15 @@ Storage.prototype = {
}
}
},

// __getAllEvents:__ loads the events.
//
// __warning:__ don't use this in production!!!
//
// `storage.getAllEvents(callback)`
//
// - __callback:__ `function(err, events){}`
getAllEvents: function(callback) {
var events = [];
for (var i in this.store) {
events = events.concat(this.store[i]);
}

events.sort(function(a, b){
return a.commitStamp - b.commitStamp;
});

callback(null, events);
},

// __getLastEventOfStream:__ loads the last event from the given stream in storage.
//
// `storage.getLastEventOfStream(streamId, callback)`
//
// - __streamId:__ the stream id
// - __callback:__ `function(err, event){}`
getLastEventOfStream: function(streamId, callback) {

if (!this.store[streamId]) {
callback(null, null);
}
else if (this.store[streamId].length) {
callback(null, this.store[streamId][this.store[streamId].length - 1]);
} else {
callback(null, null);
}

},

// __getEventRange:__ loads the range of events from given storage.
//
// `storage.getEventRange(index, amount, callback)`
//
// - __index:__ entry index
// - __amount:__ amount of events
// - __callback:__ `function(err, events){}`
getEventRange: function(index, amount, callback) {
var events = [];
for (var i in this.store) {
events = events.concat(this.store[i]);

if (events.length >= (index + amount)) {
break;
}
}

events = events.slice(index, (index + amount));

events.sort(function(a, b){
return a.commitStamp - b.commitStamp;
});

callback(null, events);
},

// __getEventRangeMatching:__ loads the range of events from given storage.
//
// `storage.getEventRangeMatching(match, amount, callback)`
// `storage.getEventRange(match, amount, callback)`
//
// - __match:__ match query in inner event (payload)
// - __amount:__ amount of events
// - __callback:__ `function(err, events){}`
getEventRangeMatching: function(match, amount, callback) {
getEventRange: function(match, amount, callback) {
var events = [];
for (var e in this.store) {
events = events.concat(this.store[e]);
Expand Down
1 change: 0 additions & 1 deletion storage/couchDb/.npmignore

This file was deleted.

12 changes: 0 additions & 12 deletions storage/couchDb/index.js

This file was deleted.

5 changes: 0 additions & 5 deletions storage/couchDb/npmlink.js

This file was deleted.

24 changes: 0 additions & 24 deletions storage/couchDb/package.json

This file was deleted.

Loading

0 comments on commit 9eabd84

Please sign in to comment.