Support for lower-level queries on indexedDB
superfeedr has done a nice job with this backbone -> indexedDB adapter, but their query interface is somewhat limited. This commit adds an alternate interface that lets us specify the index and cursor bounds we want. This interface requires deeper knowledge of indexedDB indices, but is more powerful overall.
This commit is contained in:
parent
8c93101989
commit
14c53ff710
2 changed files with 38 additions and 0 deletions
|
@ -419,6 +419,25 @@
|
|||
}
|
||||
}
|
||||
});
|
||||
} else if (options.index) {
|
||||
index = store.index(options.index.name);
|
||||
if (index) {
|
||||
if (options.index.lower && options.index.upper) {
|
||||
bounds = IDBKeyRange.bound(options.index.lower, options.index.upper);
|
||||
} else if (options.index.lower) {
|
||||
bounds = IDBKeyRange.lowerBound(options.index.lower);
|
||||
} else if (options.index.upper) {
|
||||
bounds = IDBKeyRange.upperBound(options.index.upper);
|
||||
} else if (options.index.only) {
|
||||
bounds = IDBKeyRange.only(options.index.only);
|
||||
}
|
||||
|
||||
if (typeof options.index.order === 'string' && options.index.order.toLowerCase() === 'desc') {
|
||||
readCursor = index.openCursor(bounds, window.IDBCursor.PREV || "prev");
|
||||
} else {
|
||||
readCursor = index.openCursor(bounds, window.IDBCursor.NEXT || "next");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No conditions, use the index
|
||||
if (options.range) {
|
||||
|
|
|
@ -21777,6 +21777,25 @@ return jQuery;
|
|||
}
|
||||
}
|
||||
});
|
||||
} else if (options.index) {
|
||||
index = store.index(options.index.name);
|
||||
if (index) {
|
||||
if (options.index.lower && options.index.upper) {
|
||||
bounds = IDBKeyRange.bound(options.index.lower, options.index.upper);
|
||||
} else if (options.index.lower) {
|
||||
bounds = IDBKeyRange.lowerBound(options.index.lower);
|
||||
} else if (options.index.upper) {
|
||||
bounds = IDBKeyRange.upperBound(options.index.upper);
|
||||
} else if (options.index.only) {
|
||||
bounds = IDBKeyRange.only(options.index.only);
|
||||
}
|
||||
|
||||
if (typeof options.index.order === 'string' && options.index.order.toLowerCase() === 'desc') {
|
||||
readCursor = index.openCursor(bounds, window.IDBCursor.PREV || "prev");
|
||||
} else {
|
||||
readCursor = index.openCursor(bounds, window.IDBCursor.NEXT || "next");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No conditions, use the index
|
||||
if (options.range) {
|
||||
|
|
Loading…
Reference in a new issue