eng*_*ran 4 where-clause indexeddb
假设我们为todolist建立了一个数据库,并希望查询所有重要且尚未完成的项目.在SQL中,我将使用类似的东西
SELECT * FROM todolist WHERE important = true AND state <> 'done'
Run Code Online (Sandbox Code Playgroud)
我们如何在indexeddb nosql数据库中执行该类型的请求?有索引吗?其他方式?不可能?
据我所知过滤结果important = true:
objectstore.index('important').openCursor(IDBKeyRange.only('true'))
Run Code Online (Sandbox Code Playgroud)
但我不知道如何过滤,state <> 'done'因为我们只得到了IDBKeyRange.only(z).
我不知道如何过滤这两个条款.
注意:在MongoDB中我们做:
db.userdetails.find({"date_of_join" : "16/10/2010","education":"M.C.A."})
Run Code Online (Sandbox Code Playgroud)
在onupgradeneeded中,在使用数组的条件上创建索引:
todolistStore.createIndex('importantIncomplete', ['important','state'],{unique:false});
Run Code Online (Sandbox Code Playgroud)
对于您的查询做:
var lowerBound = ['true','started'];
var upperBound = ['true','almostdone'];
var range = IDBKeyRange.bound(lowerBound,upperBound);
var request = todolistStore.index('importantIncomplete').openCursor(range);
Run Code Online (Sandbox Code Playgroud)
Kri*_*ave -6
为此,您将需要索引,并且可以使用游标检索数据,您可以在游标中提供一个过滤器。
在我的博客(http://www.kristofdegrave.be/2012/01/indexed-db-reading-multiple-records.html?m=1)上,您可以找到有关它的更多信息。
| 归档时间: |
|
| 查看次数: |
5623 次 |
| 最近记录: |