1

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?

1 Answer 1

2

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);
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for this. I will give it a whirl and get back with result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.