I am trying to set up a search feature on my site, i'm trying to find IndexedDB code for
SELECT "column" FROM "table" WHERE "column" LIKE "%keyword%"
i found a solution in IndexedDB Fuzzy Search
db.transaction(['table'], 'readonly')
.objectStore('table')
.openCursor(IDBKeyRange.bound(keyword, keyword + '\uffff'), 'prev')
.onsuccess = function (e) {
e || (e = event);
var cursor = e.target.result;
if (cursor) {
console.log(cursor.value.column);
cursor.continue();
}
};
but how can i find "%keyword%" instead of "%keyword" ?
There is nothing similar to SQL WHERE in IndexedDB.
I would loop through the table/object store values and see if the current cursor column contains the keyword:
var keyword = "foo";
var transaction = db.transaction("table", "readwrite");
var objectStore = transaction.objectStore("table");
var request = objectStore.openCursor();
request.onsuccess = function(event) {
var cursor = event.target.result;
if (cursor) {
if (cursor.value.column.indexOf(keyword) !== -1) {
console.log("We found a row with value: " + JSON.stringify(cursor.value));
}
cursor.continue();
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With