abstract-nosql
Version:
An abstract prototype for nosql database with sync and streamable (LevelDOWN API)
45 lines (41 loc) • 1.27 kB
text/coffeescript
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 = class FakeDB
inherits FakeDB, AbstractNoSql
constructor: ->
return new FakeDB if not (this instanceof FakeDB)
super
IteratorClass: FakeIterator
_openSync: sinon.spy ->
= {}
true
_closeSync: sinon.spy ->
= {}
true
_isExistsSync: sinon.spy (key)->
.hasOwnProperty key
_mGetSync: sinon.spy ->
AbstractNoSql::_mGetSync.apply this, arguments
_getBufferSync: sinon.spy ->
AbstractNoSql::_getBufferSync.apply this, arguments
_getSync: sinon.spy (key, opts)->
if .hasOwnProperty key
[key]
else
throw new NotFoundError("NotFound:"+key)
_putSync: sinon.spy (key,value)->
[key]=value
_delSync: sinon.spy (key)->delete [key]
_batchSync: sinon.spy (operations, options)->
for op in operations
continue unless isObject op
if op.type is 'del'
delete [op.key]
else
[op.key] = op.value
true