I'm an idiot - killer off-by-one ate the storage
This commit is contained in:
parent
943a291903
commit
13360c335b
@ -3,19 +3,27 @@ var nThen = require('nthen');
|
|||||||
|
|
||||||
var getIndex = function(db, cName, cb) {
|
var getIndex = function(db, cName, cb) {
|
||||||
db.get(cName+'=>index', function(e, out){
|
db.get(cName+'=>index', function(e, out){
|
||||||
if (e && !e.notFound) { throw e; }
|
if (e) {
|
||||||
cb(parseInt(out || 0));
|
if (e.notFound) {
|
||||||
|
cb(-1);
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cb(parseInt(out));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var insert = function (db, channelName, content, cb) {
|
var insert = function (db, channelName, content, cb) {
|
||||||
var index;
|
var index;
|
||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
getIndex(db, channelName, waitFor(function (i) { index = i; }));
|
getIndex(db, channelName, waitFor(function (i) { index = i+1; }));
|
||||||
}).nThen(function (waitFor) {
|
|
||||||
db.put(channelName+'=>index', ''+index, waitFor(function (e) { if (e) { throw e; } }));
|
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
db.put(channelName+'=>'+index, content, waitFor(function (e) { if (e) { throw e; } }));
|
db.put(channelName+'=>'+index, content, waitFor(function (e) { if (e) { throw e; } }));
|
||||||
|
}).nThen(function (waitFor) {
|
||||||
|
db.put(channelName+'=>index', ''+index, waitFor(function (e) { if (e) { throw e; } }));
|
||||||
|
console.log(index);
|
||||||
}).nThen(cb);
|
}).nThen(cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user