-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support clear() * Optimize clear() and fix IE & Edge
- Loading branch information
Showing
7 changed files
with
119 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict' | ||
|
||
var setImmediate = require('./immediate') | ||
|
||
module.exports = function clear (db, location, keyRange, options, callback) { | ||
if (options.limit === 0) return setImmediate(callback) | ||
|
||
var transaction = db.db.transaction([location], 'readwrite') | ||
var store = transaction.objectStore(location) | ||
var 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 | ||
var method = store.openKeyCursor ? 'openKeyCursor' : 'openCursor' | ||
var direction = options.reverse ? 'prev' : 'next' | ||
|
||
store[method](keyRange, direction).onsuccess = function (ev) { | ||
var 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() | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* global IDBKeyRange */ | ||
|
||
'use strict' | ||
|
||
var ltgt = require('ltgt') | ||
var NONE = {} | ||
|
||
module.exports = function createKeyRange (options) { | ||
var lower = ltgt.lowerBound(options, NONE) | ||
var upper = ltgt.upperBound(options, NONE) | ||
var lowerOpen = ltgt.lowerBoundExclusive(options, NONE) | ||
var upperOpen = ltgt.upperBoundExclusive(options, NONE) | ||
|
||
if (lower !== NONE && upper !== NONE) { | ||
return IDBKeyRange.bound(lower, upper, lowerOpen, upperOpen) | ||
} else if (lower !== NONE) { | ||
return IDBKeyRange.lowerBound(lower, lowerOpen) | ||
} else if (upper !== NONE) { | ||
return IDBKeyRange.upperBound(upper, upperOpen) | ||
} else { | ||
return null | ||
} | ||
} |