### Open database and create object store with indexes Source: https://www.w3.org/TR/IndexedDB Opens the "library" database and creates the "books" object store with a primary key on "isbn", plus unique index "by_title" and non-unique index "by_author". The upgradeneeded handler populates initial data; the success handler saves the connection for later examples. ```javascript const request = indexedDB.open("library"); let db; request.onupgradeneeded = function() { // The database did not previously exist, so create object stores and indexes. const db = request.result; const store = db.createObjectStore("books", {keyPath: "isbn"}); const titleIndex = store.createIndex("by_title", "title", {unique: true}); const authorIndex = store.createIndex("by_author", "author"); // Populate with initial data. store.put({title: "Quarry Memories", author: "Fred", isbn: 123456}); store.put({title: "Water Buffaloes", author: "Fred", isbn: 234567}); store.put({title: "Bedrock Nights", author: "Barney", isbn: 345678}); }; request.onsuccess = function() { db = request.result; }; ``` -------------------------------- ### IDBObjectStore Interface Methods Source: https://www.w3.org/TR/IndexedDB Documentation for the IDBObjectStore interface methods, including clear, get, getKey, getAll, getAllKeys, getAllRecords, and count. ```APIDOC ## [IDBObjectStore] clear() ### Description Clears all records from the object store. This method does not allow null as a key to prevent accidental clearing of the entire store. ### Method clear() ### Parameters None. ### Response Returns an IDBRequest. On success, the request's result is undefined. ### Exceptions - InvalidStateError - If the store has been deleted. - TransactionInactiveError - If the transaction is not active. - ReadOnlyError - If the transaction is read-only. ``` ```APIDOC ## [IDBObjectStore] get(query) ### Description Retrieves the value of the first record matching the given key or key range. If successful, the request's result will be the value, or undefined if no matching record exists. ### Method get(query) ### Parameters - **query** (key or IDBKeyRange) - Required - The key or key range identifying the record to retrieve. ### Response Returns an IDBRequest. On success, the request's result is the value or undefined. ### Exceptions - InvalidStateError - If the store has been deleted. - TransactionInactiveError - If the transaction is not active. ``` ```APIDOC ## [IDBObjectStore] getKey(query) ### Description Retrieves the key of the first record matching the given key or key range. If successful, the request's result will be the key, or undefined if no matching record exists. ### Method getKey(query) ### Parameters - **query** (key or IDBKeyRange) - Required - The key or key range identifying the record to retrieve. ### Response Returns an IDBRequest. On success, the request's result is the key or undefined. ### Exceptions - InvalidStateError - If the store has been deleted. - TransactionInactiveError - If the transaction is not active. ``` ```APIDOC ## [IDBObjectStore] getAll(query [, count]) ### Description Retrieves the values of records matching the given key or key range, up to count if given. The direction option can be set to "next" or "prev" to control retrieval order. ### Method getAll(query [, count]) ### Parameters - **query** (key or IDBKeyRange) - Required - The key or key range to match. - **count** (number) - Optional - Limits the number of records returned. - **direction** (string) - Optional - "next" to retrieve the first count values, "prev" to return the last count values. ### Response Returns an IDBRequest. On success, the request's result is an Array of the values. ### Exceptions - InvalidStateError - If the store has been deleted. - TransactionInactiveError - If the transaction is not active. ``` ```APIDOC ## [IDBObjectStore] getAllKeys(query [, count]) ### Description Retrieves the keys of records matching the given key or key range, up to count if given. The direction option can be set to "next" or "prev" to control retrieval order. ### Method getAllKeys(query [, count]) ### Parameters - **query** (key or IDBKeyRange) - Required - The key or key range to match. - **count** (number) - Optional - Limits the number of records returned. - **direction** (string) - Optional - "next" to retrieve the first count keys, "prev" to return the last count keys. ### Response Returns an IDBRequest. On success, the request's result is an Array of the keys. ### Exceptions - InvalidStateError - If the store has been deleted. - TransactionInactiveError - If the transaction is not active. ``` ```APIDOC ## [IDBObjectStore] getAllRecords({query, count, direction}) ### Description Retrieves the keys and values of records. The query option specifies a key or key range to match, the count option limits the number of records, and the direction option controls retrieval order. ### Method getAllRecords({query, count, direction}) ### Parameters - **query** (key or IDBKeyRange) - Required - The key or key range to match. - **count** (number) - Optional - Limits the number of records matched. - **direction** (string) - Optional - "next" to retrieve the first count records, "prev" to return the last count records. ### Response Returns an IDBRequest. On success, the request's result is an Array of IDBRecord objects. ### Exceptions - InvalidStateError - If the store has been deleted. - TransactionInactiveError - If the transaction is not active. ``` ```APIDOC ## [IDBObjectStore] count(query) ### Description Retrieves the number of records matching the given key or key range. If successful, the request's result will be the count. ### Method count(query) ### Parameters - **query** (key or IDBKeyRange) - Required - The key or key range to match. ### Response Returns an IDBRequest. On success, the request's result is the count. ### Exceptions - InvalidStateError - If the store has been deleted. - TransactionInactiveError - If the transaction is not active. ``` -------------------------------- ### IDBFactory.databases() Source: https://www.w3.org/TR/IndexedDB Returns a promise which resolves to a list of objects giving a snapshot of the names and versions of databases within the storage key. This API is intended for web applications to introspect the use of databases, for example to clean up from earlier versions of a site's code. ```APIDOC ## [databases] IDBFactory.databases() ### Description Returns a promise which resolves to a list of objects giving a snapshot of the names and versions of databases within the storage key. This API is intended for web applications to introspect the use of databases, for example to clean up from earlier versions of a site's code. ### Method databases ### Endpoint IDBFactory.databases() ### Parameters None. ### Response #### Success Response - Returns a promise that resolves to a list of IDBDatabaseInfo dictionaries, each with name and version members. Databases with version 0 are omitted. #### Error Response - If obtaining a storage key fails, the promise is rejected with a SecurityError DOMException. - If the set of databases cannot be determined, the promise is rejected with an appropriate error (e.g. UnknownError DOMException). ``` -------------------------------- ### IDBIndex.get(query) Source: https://www.w3.org/TR/IndexedDB The get method returns an IDBRequest that retrieves the value for the given key or key range from the index. ```APIDOC ## [GET] IDBIndex.get(query) ### Description Retrieves the value for the given key or key range from the index. ### Method GET ### Endpoint IDBIndex.get(query) ### Parameters #### Query Parameters - **query** (any) - Required - The key or key range to retrieve. ### Response #### Success Response (200) - **IDBRequest** - A request that resolves to the value associated with the query, or undefined if not found. ``` -------------------------------- ### createObjectStore(name, options) Source: https://www.w3.org/TR/IndexedDB Creates a new object store in the connected database. Must be called within an upgrade transaction. ```APIDOC ## createObjectStore(name, options) ### Description Creates and returns a new object store with the given name in the connected database. Must only be called from within an upgrade transaction. ### Method createObjectStore ### Parameters - **name** (string) - Required - The name of the object store to create. - **options** (object) - Optional - An object with the following members: - **keyPath** (string or sequence) - Optional - The key path for the object store. If null or undefined, no key path is used. - **autoIncrement** (boolean) - Optional - If true, the object store uses a key generator. ### Exceptions - **InvalidStateError** - Thrown if there is no upgrade transaction associated with the database. - **TransactionInactiveError** - Thrown if the upgrade transaction is not active. - **SyntaxError** - Thrown if keyPath is not null and is not a valid key path. - **ConstraintError** - Thrown if an object store with the given name already exists. - **InvalidAccessError** - Thrown if autoIncrement is true and keyPath is an empty string or any sequence. ### Return Value Returns a new IDBObjectStore handle associated with the created object store and the upgrade transaction. ``` -------------------------------- ### Each object store has its own key generator Source: https://www.w3.org/TR/IndexedDB Shows that each object store has its own key generator, so both stores start at key 1 and increment independently. ```javascript store1 = db.createObjectStore("store1", { autoIncrement: true }); store1.put("a"); // Will get key 1 store2 = db.createObjectStore("store2", { autoIncrement: true }); store2.put("a"); // Will get key 1 store1.put("b"); // Will get key 2 store2.put("b"); // Will get key 2 ``` -------------------------------- ### IDBFactory.open(name, version) Source: https://www.w3.org/TR/IndexedDB Opens a connection to a database with the given name and version. If version is not given and a database with that name already exists, a connection is opened without changing the version. If version is not given and no database exists, a new database is created with version 1. ```APIDOC ## [open] IDBFactory.open(name, version) ### Description Opens a connection to a database with the given name and version. If version is not given and a database with that name already exists, a connection is opened without changing the version. If version is not given and no database exists, a new database is created with version 1. ### Method open ### Endpoint IDBFactory.open(name, version) ### Parameters #### Path Parameters - **name** (string) - Required - The name of the database. - **version** (unsigned long long) - Optional - The version to open the database with. If 0, a TypeError is thrown. ### Response #### Success Response - Returns an IDBOpenDBRequest object. The request's result is set to the opened database connection. A success event is fired on the request. #### Error Response - If version is 0, a TypeError is thrown. - If obtaining a storage key fails, a SecurityError DOMException is thrown. - If an error occurs during opening, an error event is fired on the request with the error set. ``` -------------------------------- ### IDBFactory.open Source: https://www.w3.org/TR/IndexedDB Opens a connection to a database, optionally specifying a version. Returns an IDBOpenDBRequest. ```APIDOC ## [open] IDBFactory.open ### Description Attempts to open a connection to the named database with the current version, or 1 if it does not already exist. If the request is successful, request's result will be the connection. ### Method open ### Endpoint indexedDB.open(name, version) ### Parameters #### Parameters - **name** (DOMString) - Required - The name of the database. - **version** (unsigned long long) - Optional - The version to open the database with. If omitted, the current version is used, or 1 if the database does not exist. ### Response #### Success Response - **result** (IDBDatabase) - The connection to the database. ### Response Example ``` IDBOpenDBRequest ``` ``` -------------------------------- ### Aborting transaction rolls back key generator Source: https://www.w3.org/TR/IndexedDB Shows that aborting a transaction rolls back key generator increases, so the next transaction starts again at key 1. ```javascript db.createObjectStore("store", { autoIncrement: true }); trans1 = db.transaction(["store"], "readwrite"); store_t1 = trans1.objectStore("store"); store_t1.put("a"); // Will get key 1 store_t1.put("b"); // Will get key 2 trans1.abort(); trans2 = db.transaction(["store"], "readwrite"); store_t2 = trans2.objectStore("store"); store_t2.put("c"); // Will get key 1 store_t2.put("d"); // Will get key 2 ``` -------------------------------- ### Migrate database from older version using indexedDB.open and onupgradeneeded Source: https://www.w3.org/TR/IndexedDB Opens the "library" database at version 3 and handles migration in onupgradeneeded. It creates the "books" object store with keyPath "isbn" and indexes by_title (unique), by_author, by_year, and a "magazines" object store with by_publisher and by_frequency indexes, depending on event.oldVersion. The onsuccess handler assigns the database to db, whose version will be 3. ```javascript const request = indexedDB.open("library", 3); // Request version 3. let db; request.onupgradeneeded = function(event) { const db = request.result; if (event.oldVersion < 1) { // Version 1 is the first version of the database. const store = db.createObjectStore("books", {keyPath: "isbn"}); const titleIndex = store.createIndex("by_title", "title", {unique: true}); const authorIndex = store.createIndex("by_author", "author"); } if (event.oldVersion < 2) { // Version 2 introduces a new index of books by year. const bookStore = request.transaction.objectStore("books"); const yearIndex = bookStore.createIndex("by_year", "year"); } if (event.oldVersion < 3) { // Version 3 introduces a new object store for magazines with two indexes. const magazines = db.createObjectStore("magazines"); const publisherIndex = magazines.createIndex("by_publisher", "publisher"); const frequencyIndex = magazines.createIndex("by_frequency", "frequency"); } }; request.onsuccess = function() { db = request.result; // db.version will be 3. }; ``` -------------------------------- ### Failed insertion does not update key generator Source: https://www.w3.org/TR/IndexedDB Demonstrates that a failed insertion due to a unique constraint violation does not advance the key generator; the next successful put gets key 2. ```javascript transaction.onerror = function(e) { e.preventDefault() }; store = db.createObjectStore("store1", { autoIncrement: true }); index = store.createIndex("index1", "ix", { unique: true }); store.put({ ix: "a"}); // Will get key 1 store.put({ ix: "a"}); // Will fail store.put({ ix: "b"}); // Will get key 2 ``` -------------------------------- ### Open database asynchronously with indexedDB.open Source: https://www.w3.org/TR/IndexedDB Opens the 'AddressBook' database at version 15 asynchronously and registers success and error event handlers on the returned IDBRequest. The handlers are placeholders to be filled with actual logic. ```javascript const request = indexedDB.open('AddressBook', 15); request.onsuccess = function(evt) {...}; request.onerror = function(evt) {...}; ``` -------------------------------- ### Populate database with a readwrite transaction Source: https://www.w3.org/TR/IndexedDB Populates the "books" object store using a readwrite transaction. The oncomplete handler fires after all put requests succeed and the transaction commits. ```javascript const tx = db.transaction("books", "readwrite"); const store = tx.objectStore("books"); store.put({title: "Quarry Memories", author: "Fred", isbn: 123456}); store.put({title: "Water Buffaloes", author: "Fred", isbn: 234567}); store.put({title: "Bedrock Nights", author: "Barney", isbn: 345678}); tx.oncomplete = function() { // All requests have succeeded and the transaction has committed. }; ``` -------------------------------- ### IDBFactory.databases Source: https://www.w3.org/TR/IndexedDB Lists all databases with their names and versions. Returns a promise. ```APIDOC ## [databases] IDBFactory.databases ### Description Returns a promise that resolves to a sequence of IDBDatabaseInfo objects, each containing the name and version of an existing database. ### Method databases ### Endpoint indexedDB.databases() ### Parameters None. ### Response #### Success Response - **result** (Promise>) - A promise that resolves to a sequence of database info objects. ### Response Example ``` Promise> ``` ``` -------------------------------- ### IDBDatabase.createObjectStore(name, options) Source: https://www.w3.org/TR/IndexedDB Creates a new object store in the database. ```APIDOC ## [METHOD] IDBDatabase.createObjectStore(name, options) ### Description Creates a new object store with the given name and options and returns a new IDBObjectStore. Throws an "InvalidStateError" DOMException if not called within an upgrade transaction. ### Method METHOD ### Endpoint connection.createObjectStore(name, options) ### Parameters - **name** (DOMString) - Required - The name of the object store to create. - **options** (IDBObjectStoreParameters) - Optional - An object with keyPath and autoIncrement properties. ### Response #### Success Response - **store** (IDBObjectStore) - The newly created object store. #### Error Response - **InvalidStateError** DOMException - Thrown if not called within an upgrade transaction. ``` -------------------------------- ### IDBObjectStore Interface Source: https://www.w3.org/TR/IndexedDB Documentation for the IDBObjectStore interface, including its properties and methods. ```APIDOC ## [IDBObjectStore] name ### Description Returns the name of the store. ### Method Getter ### Endpoint IDBObjectStore.name ### Parameters None ### Response #### Success Response - **name** (DOMString) - The name of the store. #### Response Example ```js const storeName = store.name; ``` ``` ```APIDOC ## [IDBObjectStore] name setter ### Description Updates the name of the store to newName. Throws an `InvalidStateError` `DOMException` if not called within an upgrade transaction. ### Method Setter ### Endpoint IDBObjectStore.name = newName ### Parameters #### Request Body - **newName** (DOMString) - Required - The new name for the store. ### Response #### Success Response No return value. #### Error Handling - **InvalidStateError** - Thrown if the store has been deleted or the transaction is not an upgrade transaction. - **TransactionInactiveError** - Thrown if the transaction is not active. - **ConstraintError** - Thrown if an object store with the same name already exists. ``` ```APIDOC ## [IDBObjectStore] keyPath ### Description Returns the key path of the store, or null if none. ### Method Getter ### Endpoint IDBObjectStore.keyPath ### Parameters None ### Response #### Success Response - **keyPath** (any) - The key path of the store, or null if none. #### Response Example ```js const keyPath = store.keyPath; ``` ``` ```APIDOC ## [IDBObjectStore] indexNames ### Description Returns a list of the names of indexes in the store. ### Method Getter ### Endpoint IDBObjectStore.indexNames ### Parameters None ### Response #### Success Response - **indexNames** (DOMStringList) - A sorted list of index names. #### Response Example ```js const indexNames = store.indexNames; ``` ``` ```APIDOC ## [IDBObjectStore] transaction ### Description Returns the associated transaction. ### Method Getter ### Endpoint IDBObjectStore.transaction ### Parameters None ### Response #### Success Response - **transaction** (IDBTransaction) - The associated transaction. #### Response Example ```js const transaction = store.transaction; ``` ``` ```APIDOC ## [IDBObjectStore] autoIncrement ### Description Returns true if the store has a key generator, and false otherwise. ### Method Getter ### Endpoint IDBObjectStore.autoIncrement ### Parameters None ### Response #### Success Response - **autoIncrement** (boolean) - True if the store has a key generator, false otherwise. #### Response Example ```js const autoIncrement = store.autoIncrement; ``` ``` ```APIDOC ## [IDBObjectStore] put(any value, optional any key) ### Description Stores a value in the object store. If a key is provided, it is used as the key; otherwise, the key is generated by the key generator or derived from the key path. ### Method put ### Endpoint IDBObjectStore.put(value, key) ### Parameters #### Request Body - **value** (any) - Required - The value to store. - **key** (any) - Optional - The key to use for the record. ### Response #### Success Response - **IDBRequest** - A request object that will fire a success event when the operation completes. ``` ```APIDOC ## [IDBObjectStore] add(any value, optional any key) ### Description Adds a value to the object store. If a key is provided, it is used as the key; otherwise, the key is generated by the key generator or derived from the key path. If a record with the same key already exists, the request fails. ### Method add ### Endpoint IDBObjectStore.add(value, key) ### Parameters #### Request Body - **value** (any) - Required - The value to add. - **key** (any) - Optional - The key to use for the record. ### Response #### Success Response - **IDBRequest** - A request object that will fire a success event when the operation completes. ``` ```APIDOC ## [IDBObjectStore] delete(any query) ### Description Deletes records from the object store that match the given query. ### Method delete ### Endpoint IDBObjectStore.delete(query) ### Parameters #### Request Body - **query** (any) - Required - The key or key range identifying the records to delete. ### Response #### Success Response - **IDBRequest** - A request object that will fire a success event when the operation completes. ``` ```APIDOC ## [IDBObjectStore] clear() ### Description Clears all records from the object store. ### Method clear ### Endpoint IDBObjectStore.clear() ### Parameters None ### Response #### Success Response - **IDBRequest** - A request object that will fire a success event when the operation completes. ``` ```APIDOC ## [IDBObjectStore] get(any query) ### Description Retrieves the first record that matches the given query. ### Method get ### Endpoint IDBObjectStore.get(query) ### Parameters #### Request Body - **query** (any) - Required - The key or key range identifying the record to retrieve. ### Response #### Success Response - **IDBRequest** - A request object that will fire a success event with the retrieved value. ``` ```APIDOC ## [IDBObjectStore] getKey(any query) ### Description Retrieves the key of the first record that matches the given query. ### Method getKey ### Endpoint IDBObjectStore.getKey(query) ### Parameters #### Request Body - **query** (any) - Required - The key or key range identifying the record. ### Response #### Success Response - **IDBRequest** - A request object that will fire a success event with the key. ``` ```APIDOC ## [IDBObjectStore] getAll(optional any queryOrOptions, optional unsigned long count) ### Description Retrieves all records that match the given query, optionally limited by count. ### Method getAll ### Endpoint IDBObjectStore.getAll(queryOrOptions, count) ### Parameters #### Request Body - **queryOrOptions** (any) - Optional - A key, key range, or options object. - **count** (unsigned long) - Optional - The maximum number of records to return. ### Response #### Success Response - **IDBRequest** - A request object that will fire a success event with an array of values. ``` ```APIDOC ## [IDBObjectStore] getAllKeys(optional any queryOrOptions, optional unsigned long count) ### Description Retrieves all keys that match the given query, optionally limited by count. ### Method getAllKeys ### Endpoint IDBObjectStore.getAllKeys(queryOrOptions, count) ### Parameters #### Request Body - **queryOrOptions** (any) - Optional - A key, key range, or options object. - **count** (unsigned long) - Optional - The maximum number of keys to return. ### Response #### Success Response - **IDBRequest** - A request object that will fire a success event with an array of keys. ``` ```APIDOC ## [IDBObjectStore] getAllRecords(optional IDBGetAllOptions options = {}) ### Description Retrieves all records that match the given options, including query, count, and direction. ### Method getAllRecords ### Endpoint IDBObjectStore.getAllRecords(options) ### Parameters #### Request Body - **options** (IDBGetAllOptions) - Optional - An object with `query`, `count`, and `direction` properties. ### Response #### Success Response - **IDBRequest** - A request object that will fire a success event with an array of records. ``` ```APIDOC ## [IDBObjectStore] count(optional any query) ### Description Counts the number of records that match the given query. ### Method count ### Endpoint IDBObjectStore.count(query) ### Parameters #### Request Body - **query** (any) - Optional - A key or key range to count. ### Response #### Success Response - **IDBRequest** - A request object that will fire a success event with the count. ``` ```APIDOC ## [IDBObjectStore] openCursor(optional any query, optional IDBCursorDirection direction = "next") ### Description Opens a cursor over the records that match the given query, iterating in the specified direction. ### Method openCursor ### Endpoint IDBObjectStore.openCursor(query, direction) ### Parameters #### Request Body - **query** (any) - Optional - A key or key range to iterate over. - **direction** (IDBCursorDirection) - Optional - The direction of iteration (default "next"). ### Response #### Success Response - **IDBRequest** - A request object that will fire a success event with a cursor. ``` ```APIDOC ## [IDBObjectStore] openKeyCursor(optional any query, optional IDBCursorDirection direction = "next") ### Description Opens a cursor over the keys of records that match the given query, iterating in the specified direction. ### Method openKeyCursor ### Endpoint IDBObjectStore.openKeyCursor(query, direction) ### Parameters #### Request Body - **query** (any) - Optional - A key or key range to iterate over. - **direction** (IDBCursorDirection) - Optional - The direction of iteration (default "next"). ### Response #### Success Response - **IDBRequest** - A request object that will fire a success event with a cursor. ``` ```APIDOC ## [IDBObjectStore] index(DOMString name) ### Description Returns an `IDBIndex` object representing the index with the given name. ### Method index ### Endpoint IDBObjectStore.index(name) ### Parameters #### Request Body - **name** (DOMString) - Required - The name of the index. ### Response #### Success Response - **IDBIndex** - The index object. ``` ```APIDOC ## [IDBObjectStore] createIndex(DOMString name, (DOMString or sequence) keyPath, optional IDBIndexParameters options = {}) ### Description Creates a new index on the object store with the given name and key path. ### Method createIndex ### Endpoint IDBObjectStore.createIndex(name, keyPath, options) ### Parameters #### Request Body - **name** (DOMString) - Required - The name of the index. - **keyPath** (DOMString or sequence) - Required - The key path(s) for the index. - **options** (IDBIndexParameters) - Optional - An object with `unique` and `multiEntry` properties. ### Response #### Success Response - **IDBIndex** - The newly created index. ``` ```APIDOC ## [IDBObjectStore] deleteIndex(DOMString name) ### Description Deletes the index with the given name from the object store. ### Method deleteIndex ### Endpoint IDBObjectStore.deleteIndex(name) ### Parameters #### Request Body - **name** (DOMString) - Required - The name of the index to delete. ### Response #### Success Response No return value. ``` -------------------------------- ### IDBCursor Interface Methods Source: https://www.w3.org/TR/IndexedDB Documentation for the IDBCursor interface methods: continuePrimaryKey, advance, and continue. ```APIDOC ## [IDBCursor] continuePrimaryKey(key, primaryKey) ### Description Advances the cursor to the next record in range matching or after key and primaryKey. Throws an "InvalidAccessError" DOMException if the source is not an index. ### Method continuePrimaryKey ### Parameters - **key** (any) - Required - The key to continue from. - **primaryKey** (any) - Required - The primary key to continue from. ### Exceptions - **InvalidAccessError** - Thrown if the source is not an index. ## [IDBCursor] advance(count) ### Description Advances the cursor by the specified count. Throws a TypeError if count is 0, and various DOMExceptions for invalid states. ### Method advance ### Parameters - **count** (unsigned long) - Required - The number of steps to advance the cursor. ### Exceptions - **TypeError** - Thrown if count is 0. - **TransactionInactiveError** - Thrown if the transaction is not active. - **InvalidStateError** - Thrown if the source or effective object store has been deleted, or if the cursor is being iterated or has iterated past its end. ## [IDBCursor] continue(key) ### Description Advances the cursor to the next record in range matching or after the specified key. Throws various DOMExceptions for invalid states. ### Method continue ### Parameters - **key** (any) - Optional - The key to continue from. If not given, the cursor continues to the next record. ### Exceptions - **TransactionInactiveError** - Thrown if the transaction is not active. - **InvalidStateError** - Thrown if the source or effective object store has been deleted, or if the cursor is being iterated or has iterated past its end. - **DataError** - Thrown if the key is invalid or if the key is not in the correct direction relative to the cursor's position. ``` -------------------------------- ### IDBObjectStore Interface Methods Source: https://www.w3.org/TR/IndexedDB Documentation for the IDBObjectStore interface methods that can be called directly by users. ```APIDOC ## IDBObjectStore.getAll(queryOrOptions, count) ### Description Retrieves multiple values from the object store. The query parameter can be a key or key range (an IDBKeyRange) identifying the record key to be retrieved. If a range is specified, the method retrieves the first existing key in that range. ### Method IDBObjectStore method ### Parameters - **queryOrOptions** (IDBValidKey | IDBKeyRange | IDBGetAllOptions) - Optional - A key, key range, or options object specifying the records to retrieve. - **count** (number) - Optional - The maximum number of records to retrieve. ### Returns - **IDBRequest** - A request whose result will be an array of values. ### Exceptions - Rethrows any exceptions from creating the request. ``` ```APIDOC ## IDBObjectStore.getAllKeys(queryOrOptions, count) ### Description Retrieves multiple keys from the object store. The query parameter can be a key or key range (an IDBKeyRange) identifying the record key to be retrieved. If a range is specified, the method retrieves the first existing key in that range. ### Method IDBObjectStore method ### Parameters - **queryOrOptions** (IDBValidKey | IDBKeyRange | IDBGetAllOptions) - Optional - A key, key range, or options object specifying the records to retrieve. - **count** (number) - Optional - The maximum number of records to retrieve. ### Returns - **IDBRequest** - A request whose result will be an array of keys. ### Exceptions - Rethrows any exceptions from creating the request. ``` ```APIDOC ## IDBObjectStore.getAllRecords(options) ### Description Retrieves multiple records (key and value pairs) from the object store. The options parameter specifies the records to retrieve. ### Method IDBObjectStore method ### Parameters - **options** (IDBGetAllRecordsOptions) - Required - Options specifying the records to retrieve. ### Returns - **IDBRequest** - A request whose result will be an array of records. ### Exceptions - Rethrows any exceptions from creating the request. ``` ```APIDOC ## IDBObjectStore.count(query) ### Description Counts the number of records in the object store that match the given query. The query parameter can be a key or key range (an IDBKeyRange) identifying the records to be counted. If null or not given, an unbounded key range is used. ### Method IDBObjectStore method ### Parameters - **query** (IDBValidKey | IDBKeyRange) - Optional - A key or key range to count records for. If null or not given, counts all records. ### Returns - **IDBRequest** - A request whose result will be the count of matching records. ### Exceptions - **InvalidStateError** - Thrown if the store has been deleted. - **TransactionInactiveError** - Thrown if the transaction is not active. ``` ```APIDOC ## IDBObjectStore.openCursor(query, direction) ### Description Opens a cursor over the records matching query, ordered by direction. If query is null, all records in store are matched. If successful, request's result will be an IDBCursorWithValue pointing at the first matching record, or null if there were no matching records. ### Method IDBObjectStore method ### Parameters - **query** (IDBValidKey | IDBKeyRange) - Optional - A key or key range to use as the cursor's range. If null or not given, an unbounded key range is used. - **direction** (IDBCursorDirection) - Optional - The direction of the cursor. Defaults to "next". ### Returns - **IDBRequest** - A request whose result will be an IDBCursorWithValue or null. ### Exceptions - **InvalidStateError** - Thrown if the store has been deleted. - **TransactionInactiveError** - Thrown if the transaction is not active. ``` ```APIDOC ## IDBObjectStore.openKeyCursor(query, direction) ### Description Opens a cursor with key only flag set to true over the records matching query, ordered by direction. If query is null, all records in store are matched. If successful, request's result will be an IDBCursor pointing at the first matching record, or null if there were no matching records. ### Method IDBObjectStore method ### Parameters - **query** (IDBValidKey | IDBKeyRange) - Optional - A key or key range to use as the cursor's range. If null or not given, an unbounded key range is used. - **direction** (IDBCursorDirection) - Optional - The direction of the cursor. Defaults to "next". ### Returns - **IDBRequest** - A request whose result will be an IDBCursor or null. ### Exceptions - **InvalidStateError** - Thrown if the store has been deleted. - **TransactionInactiveError** - Thrown if the transaction is not active. ``` -------------------------------- ### IDBIndex.getAll(queryOrOptions, count) Source: https://www.w3.org/TR/IndexedDB The getAll method on IDBIndex retrieves keys for records matching the given query or options. ```APIDOC ## IDBIndex.getAll(queryOrOptions, count) ### Description Creates a request to retrieve multiple items from the index, returning keys. The `queryOrOptions` parameter can be a key, key range, or an `IDBGetAllOptions` object. The optional `count` limits the number of results. ### Method Method call ### Endpoint `index.getAll(queryOrOptions, count)` ### Parameters - **queryOrOptions** (any) - Required - A key, `IDBKeyRange`, or `IDBGetAllOptions` object specifying the range of records to retrieve. - **count** (number) - Optional - Limits the number of records returned. ### Returns - **IDBRequest** - A request whose result will be an array of keys. ``` -------------------------------- ### IDBObjectStore Interface Source: https://www.w3.org/TR/IndexedDB Documentation for the IDBObjectStore interface methods: index(), createIndex(), and deleteIndex(). ```APIDOC ## [IDBObjectStore] index(name) ### Description Returns an IDBIndex for the index named name in the object store. ### Method index(name) ### Parameters - **name** (string) - Required - The name of the index to retrieve. ### Returns - **IDBIndex** - The index with the given name. ### Exceptions - **InvalidStateError** - If the object store has been deleted or the transaction is finished. - **NotFoundError** - If no index with the given name exists. ``` ```APIDOC ## [IDBObjectStore] createIndex(name, keyPath, options) ### Description Creates a new index in the object store with the given name, keyPath, and options, and returns a new IDBIndex. Must be called within an upgrade transaction. ### Method createIndex(name, keyPath, options) ### Parameters - **name** (string) - Required - The name of the index to create. - **keyPath** (string or sequence) - Required - The key path for the index. - **options** (object) - Optional - An object with the following members: - **unique** (boolean) - Optional - If true, the index will enforce uniqueness. - **multiEntry** (boolean) - Optional - If true, the index will contain an entry for each array element. ### Returns - **IDBIndex** - The newly created index. ### Exceptions - **InvalidStateError** - If not called within an upgrade transaction or if the object store has been deleted. - **TransactionInactiveError** - If the transaction is not active. - **ConstraintError** - If an index with the same name already exists. - **SyntaxError** - If keyPath is not a valid key path. - **InvalidAccessError** - If keyPath is a sequence and multiEntry is true. ``` ```APIDOC ## [IDBObjectStore] deleteIndex(name) ### Description Deletes the index with the given name from the object store. Must be called within an upgrade transaction. ### Method deleteIndex(name) ### Parameters - **name** (string) - Required - The name of the index to delete. ### Exceptions - **InvalidStateError** - If not called within an upgrade transaction. ``` -------------------------------- ### IDBKeyRange Interface Source: https://www.w3.org/TR/IndexedDB Static factory methods for creating IDBKeyRange instances and an instance method to check key inclusion. ```APIDOC ## IDBKeyRange.only(value) ### Description Creates a new IDBKeyRange that spans only the given key value. ### Method static IDBKeyRange only(any value) ### Parameters - **value** (any) - Required - The key value to include in the range. ### Exceptions - **DataError** - Thrown if the value cannot be converted to a valid key. ### Returns - **IDBKeyRange** - A new key range containing only the specified key. ``` ```APIDOC ## IDBKeyRange.lowerBound(lower, open) ### Description Creates a new IDBKeyRange that starts at the given lower bound and has no upper bound. If open is true, the lower bound is not included in the range. ### Method static IDBKeyRange lowerBound(any lower, optional boolean open = false) ### Parameters - **lower** (any) - Required - The lower bound key value. - **open** (boolean) - Optional - If true, the lower bound is excluded from the range. Defaults to false. ### Exceptions - **DataError** - Thrown if the lower value cannot be converted to a valid key. ### Returns - **IDBKeyRange** - A new key range with the specified lower bound and no upper bound. ``` ```APIDOC ## IDBKeyRange.upperBound(upper, open) ### Description Creates a new IDBKeyRange that has no lower bound and ends at the given upper bound. If open is true, the upper bound is not included in the range. ### Method static IDBKeyRange upperBound(any upper, optional boolean open = false) ### Parameters - **upper** (any) - Required - The upper bound key value. - **open** (boolean) - Optional - If true, the upper bound is excluded from the range. Defaults to false. ### Exceptions - **DataError** - Thrown if the upper value cannot be converted to a valid key. ### Returns - **IDBKeyRange** - A new key range with no lower bound and the specified upper bound. ``` ```APIDOC ## IDBKeyRange.bound(lower, upper, lowerOpen, upperOpen) ### Description Creates a new IDBKeyRange that spans from the given lower bound to the given upper bound. The open flags determine whether the bounds are included in the range. ### Method static IDBKeyRange bound(any lower, any upper, optional boolean lowerOpen = false, optional boolean upperOpen = false) ### Parameters - **lower** (any) - Required - The lower bound key value. - **upper** (any) - Required - The upper bound key value. - **lowerOpen** (boolean) - Optional - If true, the lower bound is excluded from the range. Defaults to false. - **upperOpen** (boolean) - Optional - If true, the upper bound is excluded from the range. Defaults to false. ### Exceptions - **DataError** - Thrown if either bound cannot be converted to a valid key, or if lower is greater than upper. ### Returns - **IDBKeyRange** - A new key range spanning from lower to upper with the specified open flags. ``` ```APIDOC ## IDBKeyRange.includes(key) ### Description Returns true if the given key is included in the range, and false otherwise. ### Method boolean includes(any key) ### Parameters - **key** (any) - Required - The key value to check. ### Exceptions - **DataError** - Thrown if the key cannot be converted to a valid key. ### Returns - **boolean** - True if the key is in the range, false otherwise. ```