javascript - 如何在indexedDB中执行 "select * from table where indexA >= ' a' order by indexB ASC limit 10"?

标签 javascript indexeddb

目前我正在学习javascript IndexedDB,我发现使用它时我无法进行复杂的查询。现在我想做一个选择查询,例如
“从表中选择*,其中indexA >= 'a'按indexB ASC限制10排序”

我尝试使用
store.createIndex("indexA,indexB",["indexA","indexB"])
并尝试提出请求
store.index("indexA, indexB").openCursor(IDBKeyRange.lowerBound([1, "a"], true))
然而结果仅根据索引A排序。有什么办法可以做到吗?

最佳答案

你必须自己滚动这个。基本上有两种方法:

  • 像您所做的那样,在“indexA”上使用索引,打开一个下限为“a”的游标并进行迭代,累积所有结果,然后按 indexB 排序,并选择前 10 个。
  • 在“indexB”上使用索引,打开游标并迭代,跳过 indexA <“a”的任何条目,并在遇到 10 后停止。

链接的主题(谢谢其他 Josh!)提供了更多详细信息。

关于javascript - 如何在indexedDB中执行 "select * from table where indexA >= ' a' order by indexB ASC limit 10"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37807022/

相关文章:

javascript - 如何识别 Service Worker 中正确的持久数据?

javascript - AngularJS - 如何在非单页应用程序中从干净的 URL 读取 URL 参数

javascript - 如何在 indexedDB 上创建列/对象

javascript - React - 显示隐藏两个元素而不在页面加载时闪烁

javascript - 文字装饰 :underline with handwritten style?

javascript - 2011年为iOS/Android开发HTML5离线存储解决方案

javascript - Web 浏览器存储 : Security implications of allowing user-supplied Strings to be evaluated?

javascript - 如何使用 Vue.js 将选定的键传递给函数并为其设置值?

javascript - 如何在javascript中使用替换特殊字符

javascript - AngularJS 是否会在 jQuery 的回退中加载?