如何在IndexedDB中进行JOIN类型的查询 [英] How do I do an JOIN-type query in IndexedDB
问题描述
我尝试按照 http://hacks上的教程进行操作. mozilla.org/2010/06/comparing-indexeddb-and-webdatabase/关于在IndexedDB中进行查询,但是它们的示例不起作用.
I have tried following the tutorial at http://hacks.mozilla.org/2010/06/comparing-indexeddb-and-webdatabase/ with regards to doing queries in IndexedDB, but their example does not work.
如何在IndexedDB中进行JOIN类型查询?我已经用索引设置了对象存储,但是我似乎无法获取语法?
How to I do a JOIN type query in IndexedDB? I have set my objectstores up with indexes, but I just cant seem to get the syntax?
推荐答案
IndexedDB是键值(文档)存储.它没有JOIN查询或查询多个对象存储.但是,您可以查询一个事务中的多个商店.这就是在IndexedDB中进行联接查询的方式.
IndexedDB is key-value (document) store. It doesn't have JOIN query or querying over multiple object store. However you can query multiple stores in a transaction. That is how suppose to make join query in IndexedDB.
我有一些书面建模关系 http://dev.yathit.com/ydn-db/schema.html 使用我的库.
I have a bit of writeup modeling relationship http://dev.yathit.com/ydn-db/schema.html using my library.
这里正在加入SELECT * FROM Supplier, Part WHERE Supplier.CITY = Part.CITY
的查询.
var iter_supplier = new ydn.db.IndexValueIterator('Supplier', 'CITY');
var iter_part = new ydn.db.IndexValueIterator('Part', 'CITY');
var req = db.scan(function(keys, values) {
var SID = keys[0];
var PID = keys[1];
console.log(SID, PID);
if (!SID || !PID) {
return []; // done
}
var cmp = ydn.db.cmp(SID, PID); // compare keys
if (cmp == 0) {
console.log(values[0], values[1]);
return [true, true]; // advance both
} else if (cmp == 1) {
return [undefined, SID]; // jump PID cursor to match SID
} else {
return [PID, undefined]; // jump SID cursor to match PID
}
}, [iter_supplier, iter_part]);
有关加入查询文章的详细信息.
这篇关于如何在IndexedDB中进行JOIN类型的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!