Creating an Object Store
Learn how to create an object store for a database.
The createObjectStore()
method
To create an object store, we can use the createObjectStore()
method.
Syntax
createObjectStore(name);createObjectStore(name, options);
The createObjectStore
method can take two arguments:
name
: This is the name for the new object store to be created.options
: Theoptions
object can contain thekeyPath(primaryKey)
andautoIncrement
attributes. It’s an optional argument.keyPath
(optional): This specifies the name of the property that will be used as the key for the objects in the object store. If this property is omitted, a unique key is generated for each object automatically.autoIncrement
(optional): This property is a boolean value that specifies whether the object store should automatically generate a new key value for each new object that’s added to the store.
The keyPath
vs. autoIncrement
attributes
autoIncrement
: For data that can’t be differentiated based on a specific property, we can set theautoIncrement
astrue
.keyPath
: This ...