- Add GETTING_STARTED.md with quick start guide and development modes - Add INSTALL.sh automated installation script - Add INSTALLATION_CHECKLIST.md, INSTALLATION_SUCCESS.md, and INSTALLATION_SUMMARY.md - Add QUICK_REFERENCE.md for common commands - Add SETUP_GUIDE.md with detailed setup instructions - Update README.md with improved project overview - Add did-wallet app dependencies and node_modules
36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
'use strict'
|
|
|
|
module.exports = function clear (db, location, keyRange, options, callback) {
|
|
if (options.limit === 0) return db.nextTick(callback)
|
|
|
|
const transaction = db.db.transaction([location], 'readwrite')
|
|
const store = transaction.objectStore(location)
|
|
let count = 0
|
|
|
|
transaction.oncomplete = function () {
|
|
callback()
|
|
}
|
|
|
|
transaction.onabort = function () {
|
|
callback(transaction.error || new Error('aborted by user'))
|
|
}
|
|
|
|
// A key cursor is faster (skips reading values) but not supported by IE
|
|
// TODO: we no longer support IE. Test others
|
|
const method = store.openKeyCursor ? 'openKeyCursor' : 'openCursor'
|
|
const direction = options.reverse ? 'prev' : 'next'
|
|
|
|
store[method](keyRange, direction).onsuccess = function (ev) {
|
|
const cursor = ev.target.result
|
|
|
|
if (cursor) {
|
|
// Wait for a request to complete before continuing, saving CPU.
|
|
store.delete(cursor.key).onsuccess = function () {
|
|
if (options.limit <= 0 || ++count < options.limit) {
|
|
cursor.continue()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|