sqlite-async
Advanced tools
Comparing version 1.0.8 to 1.0.9
{ | ||
"name": "sqlite-async", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "ES6 Promise-based interface to the sqlite3 module.", | ||
@@ -5,0 +5,0 @@ "main": "sqlite-async.js", |
@@ -33,5 +33,5 @@ # sqlite-async | ||
### Database#close() | ||
### Database#close([promise]) | ||
Closes the database and returns a promise. | ||
Closes the database and returns a promise. If the optional promise is specified, it is run before closing the database. The database is closed regardless whether the optional promise is resolved or rejected. If the optional promise is rejected, then the close method itself will return a rejected promise with the error from the optional promise. | ||
@@ -38,0 +38,0 @@ ### Database#run(sql, [param, ...]) |
@@ -44,7 +44,18 @@ /** | ||
close() { | ||
close(promise) { | ||
if (!this.db) { | ||
return Promise.reject(new Error('Database.close: database is not open')) | ||
} | ||
if (promise) { | ||
return promise(this).then(result => { | ||
return this.close().then(_ => { | ||
return result | ||
}) | ||
}).catch(err => { | ||
return this.close().then(_ => { | ||
return Promise.reject(err) | ||
}) | ||
}) | ||
} | ||
return new Promise((resolve, reject) => { | ||
if (!this.db) { | ||
return reject(new Error('Database.close: database is not open')) | ||
} | ||
this.db.close(err => { | ||
@@ -51,0 +62,0 @@ if (err) { |
@@ -184,2 +184,21 @@ const assert = require('assert') | ||
}) | ||
describe('open', function () { | ||
it('should open the database again', function () { | ||
return Database.open('test.db').then(_db => { | ||
db = _db | ||
}) | ||
}) | ||
}) | ||
describe('close', function () { | ||
it('should close database after executing the promise', function () { | ||
return db.close(db => { | ||
return Promise.resolve('success') | ||
}).then(result => { | ||
assert.strictEqual(result, 'success') | ||
}) | ||
}) | ||
it('should no longer be able to use the database', function () { | ||
assert(db.db === null) | ||
}) | ||
}) | ||
}) | ||
@@ -186,0 +205,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24807
483