Reputation: 3
I have 2 objectstores in 1 indexeddb database. I can add, retrieve, show and delete the records from either without a problem.
However, what I cannot do is keep the data alive in some way after the transaction ends on one objectstore so I can use it together with the data from the second objectstore.
For example comparing values from one store to the other.
I have assigned arrays in each transaction and pushed the results into those arrays but when I come out of the transaction everything becomes undefined.
I am so tired of looking at 1 page "todo list" examples.
Maybe there isn't a way to do what I am trying. I had it working perfectly using websql but that's out now. If there is a way can someone point me to an example using multiple objectstores, please?
Upvotes: 0
Views: 943
Reputation: 13131
You can do it by opening a transaction of both object stores and using multiple cursors at the same time.
tx = db.transaction(['st1', 'st2'], 'readwrite');
ob1 = tx.objectStore('st1');
ob2 = tx.objectStore('st2');
ob1.openCursor().onsuccess = function(rs1) {
obj2.openCursor().onsuccess = function(rs2) {
rs2.result.put(rs1.result.value);
}
}
Upvotes: 1