2

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.

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?

4

1 回答 1

2

IndexedDB 是键值(文档)存储。它没有 JOIN 查询或对多个对象存储的查询。但是,您可以在一个事务中查询多个商店。这就是假设如何在 IndexedDB 中进行连接查询。

我有一些使用我的库 的写作建模关系http://dev.yathit.com/ydn-db/schema.html 。

这是加入查询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]);

请参阅加入查询文章的更多详细信息。

于 2013-05-15T03:22:18.670 回答