Storing values in a newly created objectStore

88 views Asked by At

In this example, the author uses the following line:

var customerObjectStore = 
  db.transaction("customers", "readwrite").objectStore("customers");

I don't understand why "customers" is used twice. I've tried renaming either one of them to see where it might make a difference and the example breaks, so it's clearly necessary that they retain the same name.

1

There are 1 answers

2
Alireza Ahmadi On BEST ANSWER

The transaction method gets two arguments. The first is an array of tables (Object stores) that you want to work with, and the second is the type of access. In your example, you only want to work with one table, so you have used a string instead of array. But if you want to work on large scale projects, you should work with multiple tables like this:

var trans = db.transaction(["customers", "payments"], "readwrite");
var customerObjectStore = trans.objectStore("customers");
var paymentObjectStore = trans.objectStore("payments");

Hope this example fixes your confusion.