IndexedDB中的OR或IN操作 [英] OR or IN operation in IndexedDB
问题描述
是否可以对IndexedDB中的相同属性进行OR或IN查询?
Is there a way to do an OR or IN query on the same property in IndexedDB?
换句话说,我如何得到结果,
Another word, how do I get the results for,
SELECT * FROM MyTable WHERE columnA IN ('ABC','DFT') AND columnB = '123thd'
谢谢!
推荐答案
如果没有多个请求,就无法直接进行类似OR
或IN
的查询.通常,此类问题的模式是超出范围,提取所需的更多条目,然后将其筛选为完全匹配".
There's no way to do a OR
or IN
-like query out of the box without during multiple requests. Usually the pattern for problems like this is "over reach, pulling more entries then you need and filtering those down to exact matches."
Chrome小组有 Kyaw Tun 的建议,他是SO的同伴,也是 ydn ),但是它不是标准的,也不是其他浏览器所采用的.
The Chrome team has proposed a openKeyCursor()
method as a solution for this kind of query (thanks to the suggestion of Kyaw Tun, a fellow SO participant and author of ydn), but it's not standard nor adopted in other browsers.
我能想到的最佳解决方案类似于评论w3线程的#4 :
The best solution I can think of is similar to Comment #4 of the w3 thread:
- 使用值'123thd'在
columnB
上打开精确的键光标 - 所有这些记录的游标,匹配
columnA
值'ABC'和'DFT'的对象
- Open exact key cursor on
columnB
using value '123thd' - Cursor across all those records, matching objects for
columnA
values 'ABC' and 'DFT'
如果通常您希望columnB
为'123thd'的结果数量很大,并且大多数没有值'ABC'或'DFT',那么您应该改而打开两个游标-一个在columnA
上,值为'ABC',另一个为'DFT'.这是一种更复杂的方法,因为您必须手动合并两个结果集.
If generally you expect the number of results where columnB
is '123thd' to be quite large, and most don't have values 'ABC' or 'DFT', then it may behoove you to open two cursors instead - one on columnA
w/value 'ABC' and another with value 'DFT'. It's a more complex approach because you'll have to merge the two results sets manually.
这篇关于IndexedDB中的OR或IN操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!