IndexedDB中的OR或IN操作 [英] OR or IN operation in IndexedDB

查看:54
本文介绍了IndexedDB中的OR或IN操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以对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'

谢谢!

推荐答案

如果没有多个请求,就无法直接进行类似ORIN的查询.通常,此类问题的模式是超出范围,提取所需的更多条目,然后将其筛选为完全匹配".

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的同伴,也是

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆