2.2. Object Store

An object store is the primary storage mechanism for storing data in a database.

Each database has a set of object stores. The set of object stores can be changed, but only using an upgrade transaction, i.e. in response to an [upgradeneeded](#request-upgradeneeded) event. When a new database is created it doesn’t contain any object stores.

An object store has a list of records which hold the data stored in the object store. Each record consists of a key and a value. The list is sorted according to key in ascending order. There can never be multiple records in a given object store with the same key.

An object store has a name, which is a name. At any one time, the name is unique within the database to which it belongs.

An object store optionally has a key path. If the object store has a key path it is said to use in-line keys. Otherwise it is said to use out-of-line keys.

An object store optionally has a key generator.

An object store can derive a key for a record from one of three sources:

  1. A key generator. A key generator generates a monotonically increasing numbers every time a key is needed.

  2. Keys can be derived via a key path.

  3. Keys can also be explicitly specified when a value is stored in the object store.

2.2.1. Object Store Handle

Script does not interact with object stores directly. Instead, within a transaction, script has indirect access via an object store handle.

An object store handle has an associated object store and an associated transaction. Multiple handles may be associated with the same object store in different transactions, but there must be only one object store handle associated with a particular object store within a transaction.

An object store handle has an index set, which is initialized to the set of indexes that reference the associated object store when the object store handle is created. The contents of the set will remain constant except when an upgrade transaction is running.

An object store handle has a name, which is initialized to the name of the associated object store when the object store handle is created. The name will remain constant except when an upgrade transaction is running.