abstract-nosql
Advanced tools
Comparing version 1.2.1 to 1.3.0
@@ -79,2 +79,3 @@ /* Copyright (c) 2013 Rod Vagg, MIT License */ | ||
var result = this._openSync(options) | ||
this._opened = result | ||
return result | ||
@@ -89,2 +90,3 @@ } | ||
var result = this._closeSync() | ||
this._opened = !result | ||
return result | ||
@@ -255,4 +257,9 @@ } | ||
if (callback) | ||
this._open(options, callback) | ||
if (callback) { | ||
var that = this | ||
this._open(options, function(err, result){ | ||
that._opened = !err && (result == null || result === true) | ||
callback(err, result) | ||
}) | ||
} | ||
else | ||
@@ -264,4 +271,9 @@ return this.openSync(options) | ||
if (callback) { | ||
if (typeof callback === 'function') | ||
this._close(callback) | ||
if (typeof callback === 'function') { | ||
var that = this | ||
this._close(function(err, result){ | ||
that._opened = !(err == null && (result == null || result === true)) | ||
callback(err, result) | ||
}) | ||
} | ||
else | ||
@@ -503,2 +515,5 @@ throw new Error('close() requires callback function argument') | ||
} | ||
AbstractNoSQL.prototype.isOpen = function() { | ||
return !!this._opened | ||
} | ||
@@ -505,0 +520,0 @@ module.exports.AbstractLevelDOWN = AbstractNoSQL |
@@ -15,3 +15,5 @@ module.exports.setUp = function (test, testCommon) { | ||
t.error(err) | ||
t.ok(db.isOpen()) | ||
db.close(function () { | ||
t.notOk(db.isOpen()) | ||
t.end() | ||
@@ -28,3 +30,5 @@ }) | ||
t.error(err) | ||
t.ok(db.isOpen()) | ||
db.close(function () { | ||
t.notOk(db.isOpen()) | ||
t.end() | ||
@@ -39,7 +43,11 @@ }) | ||
t.error(err) | ||
t.ok(db.isOpen()) | ||
db.close(function (err) { | ||
t.error(err) | ||
t.notOk(db.isOpen()) | ||
db.open(function (err) { | ||
t.error(err) | ||
t.ok(db.isOpen()) | ||
db.close(function () { | ||
t.notOk(db.isOpen()) | ||
t.end() | ||
@@ -59,2 +67,3 @@ }) | ||
t.ok(err, 'error') | ||
t.notOk(db.isOpen()) | ||
t.ok(/does not exist/.test(err.message), 'error is about dir not existing') | ||
@@ -72,4 +81,6 @@ t.end() | ||
t.error(err) | ||
t.ok(db.isOpen()) | ||
db.close(function (err) { | ||
t.error(err) | ||
t.notOk(db.isOpen()) | ||
@@ -80,2 +91,3 @@ // open again with 'errorIfExists' | ||
t.ok(err, 'error') | ||
t.notOk(db.isOpen()) | ||
t.ok(/exists/.test(err.message), 'error is about already existing') | ||
@@ -82,0 +94,0 @@ t.end() |
{ | ||
"name": "abstract-nosql", | ||
"description": "An abstract prototype for nosql database(LevelDOWN API)", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"contributors": [ | ||
@@ -6,0 +6,0 @@ "Riceball LEE <snowyu.lee@gmail.com> (https://github.com/snowyu)", |
@@ -91,3 +91,3 @@ const tap = require('tap') | ||
t.deepEqual(spy.getCall(0).args[0], expectedOptions, 'got default options argument') | ||
t.equal(spy.getCall(0).args[1], expectedCb, 'got expected cb argument') | ||
//t.equal(spy.getCall(0).args[1], expectedCb, 'got expected cb argument') | ||
@@ -102,3 +102,3 @@ test.open({ options: 1 }, expectedCb) | ||
t.deepEqual(spy.getCall(1).args[0], expectedOptions, 'got expected options argument') | ||
t.equal(spy.getCall(1).args[1], expectedCb, 'got expected cb argument') | ||
//t.equal(spy.getCall(1).args[1], expectedCb, 'got expected cb argument') | ||
t.end() | ||
@@ -126,3 +126,3 @@ }) | ||
t.equal(spy.getCall(0).args.length, 1, 'got one arguments') | ||
t.equal(spy.getCall(0).args[0], expectedCb, 'got expected cb argument') | ||
//t.equal(spy.getCall(0).args[0], expectedCb, 'got expected cb argument') | ||
t.end() | ||
@@ -129,0 +129,0 @@ }) |
142937
3307