How to search indexeddb for string

I am trying to set up a search function on my site, I am trying to find the IndexedDB code for

SELECT "column" FROM "table" WHERE "column" LIKE "%keyword%"

I found a solution in the Fuzzy Search IndexedDB

 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"?

+4
source share
1 answer

There is nothing like SQL WHERE in IndexedDB.

I would go through the table / object storage 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(); } }; 
+2
source

All Articles