forked from Level/abstract-leveldown
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfake-nosql.js
89 lines (67 loc) · 2.19 KB
/
fake-nosql.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Generated by CoffeeScript 1.12.7
(function() {
var AbstractNoSql, FakeDB, FakeIterator, NotFoundError, errors, inherits, isObject, sinon;
AbstractNoSql = require('./');
sinon = require('sinon');
inherits = require('inherits-ex/lib/inherits');
isObject = require('util-ex/lib/is/type/object');
errors = require('abstract-error');
FakeIterator = require('./fake-iterator');
NotFoundError = errors.NotFoundError;
module.exports = FakeDB = (function() {
inherits(FakeDB, AbstractNoSql);
function FakeDB() {
if (!(this instanceof FakeDB)) {
return new FakeDB;
}
FakeDB.__super__.constructor.apply(this, arguments);
}
FakeDB.prototype.IteratorClass = FakeIterator;
FakeDB.prototype._openSync = sinon.spy(function() {
this.data = {};
return true;
});
FakeDB.prototype._closeSync = sinon.spy(function() {
this.data = {};
return true;
});
FakeDB.prototype._isExistsSync = sinon.spy(function(key) {
return this.data.hasOwnProperty(key);
});
FakeDB.prototype._mGetSync = sinon.spy(function() {
return AbstractNoSql.prototype._mGetSync.apply(this, arguments);
});
FakeDB.prototype._getBufferSync = sinon.spy(function() {
return AbstractNoSql.prototype._getBufferSync.apply(this, arguments);
});
FakeDB.prototype._getSync = sinon.spy(function(key, opts) {
if (this.data.hasOwnProperty(key)) {
return this.data[key];
} else {
throw new NotFoundError("NotFound:" + key);
}
});
FakeDB.prototype._putSync = sinon.spy(function(key, value) {
return this.data[key] = value;
});
FakeDB.prototype._delSync = sinon.spy(function(key) {
return delete this.data[key];
});
FakeDB.prototype._batchSync = sinon.spy(function(operations, options) {
var i, len, op;
for (i = 0, len = operations.length; i < len; i++) {
op = operations[i];
if (!isObject(op)) {
continue;
}
if (op.type === 'del') {
delete this.data[op.key];
} else {
this.data[op.key] = op.value;
}
}
return true;
});
return FakeDB;
})();
}).call(this);