{"_id":"@coderundebug/indexeddb-promise","_rev":"5-e6dc09142be92162b38648962d560672","name":"@coderundebug/indexeddb-promise","dist-tags":{"latest":"1.0.4"},"versions":{"1.0.0":{"name":"@coderundebug/indexeddb-promise","version":"1.0.0","keywords":["frontend","promise","promises","indexeddb","database"],"author":{"url":"https://coderundebug.com/","name":"Stephen Paul Hassall","email":"StephenPaulHassall@hotmail.com"},"license":"MIT","_id":"@coderundebug/indexeddb-promise@1.0.0","maintainers":[{"name":"coderundebug","email":"StephenPaulHassall@hotmail.com"}],"homepage":"https://github.com/StephenHassall/indexeddb-promise","bugs":{"url":"https://github.com/StephenHassall/indexeddb-promise/issues","email":"StephenPaulHassall@hotmail.com"},"dist":{"shasum":"6e9d80d531b0b5d115e7d888c52c08776c461a8e","tarball":"https://registry.npmjs.org/@coderundebug/indexeddb-promise/-/indexeddb-promise-1.0.0.tgz","fileCount":13,"integrity":"sha512-qjG/rwPRZTabAGBsixQlf8mvyhQmit/RaWdqg6f2gwdJZtS5jbojCdupEtLW7sYgDHCDxAU4VOQIW6ky8lJOkA==","signatures":[{"sig":"MEYCIQDvih7Ucs+Ya2xNNpPSXmAfg7uINzv/ThQ2IChFxsdhFwIhANrlXkR0WE1G7n02Ia3o5xxw+E4M8MgFuMU5YNipMsJh","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":65913},"main":"index.js","type":"module","types":"./.d.js","funding":"https://github.com/StephenHassall/indexeddb-promise?sponsor=1","gitHead":"818b67323c2a85e806700ddae5f0e4ef135b558a","scripts":{},"_npmUser":{"name":"coderundebug","email":"StephenPaulHassall@hotmail.com"},"repository":{"url":"git+https://github.com/StephenHassall/indexeddb-promise.git","type":"git"},"_npmVersion":"10.2.4","description":"Use IndexedDB with promises.","directories":{},"_nodeVersion":"21.4.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/indexeddb-promise_1.0.0_1716901839527_0.025878486056313932","host":"s3://npm-registry-packages"}},"1.0.1":{"name":"@coderundebug/indexeddb-promise","version":"1.0.1","keywords":["frontend","promise","promises","indexeddb","database"],"author":{"url":"https://coderundebug.com/","name":"Stephen Paul Hassall","email":"StephenPaulHassall@hotmail.com"},"license":"MIT","_id":"@coderundebug/indexeddb-promise@1.0.1","maintainers":[{"name":"coderundebug","email":"StephenPaulHassall@hotmail.com"}],"homepage":"https://github.com/StephenHassall/indexeddb-promise","bugs":{"url":"https://github.com/StephenHassall/indexeddb-promise/issues","email":"StephenPaulHassall@hotmail.com"},"dist":{"shasum":"f9ef4824118aab8b1e96b3f36e1ff9d687addf7a","tarball":"https://registry.npmjs.org/@coderundebug/indexeddb-promise/-/indexeddb-promise-1.0.1.tgz","fileCount":13,"integrity":"sha512-WW0cSi1mXR5+tyHhEeEH0yeSMXGxX6SFLRztFfMMykFRH+Bi+eyFBH1kpzpV8hBYoqT/RifcpLNCR03zX+4vkQ==","signatures":[{"sig":"MEQCIDlhQ3Uqsk8x49/ga211Y/9ElpjhIB6DNOd7hK8Dbt8yAiADVM31lyUYVV1vYYcK23wkRJZpzZCOSZqRqJSF2nEypg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":65917},"main":"indexeddb.js","type":"module","types":"./.d.js","funding":"https://github.com/StephenHassall/indexeddb-promise?sponsor=1","gitHead":"818b67323c2a85e806700ddae5f0e4ef135b558a","scripts":{},"_npmUser":{"name":"coderundebug","email":"StephenPaulHassall@hotmail.com"},"repository":{"url":"git+https://github.com/StephenHassall/indexeddb-promise.git","type":"git"},"_npmVersion":"10.2.4","description":"Use IndexedDB with promises.","directories":{},"_nodeVersion":"21.4.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/indexeddb-promise_1.0.1_1716902031245_0.1692348510253754","host":"s3://npm-registry-packages"}},"1.0.2":{"name":"@coderundebug/indexeddb-promise","version":"1.0.2","keywords":["frontend","promise","promises","indexeddb","database"],"author":{"url":"https://coderundebug.com/","name":"Stephen Paul Hassall","email":"StephenPaulHassall@hotmail.com"},"license":"MIT","_id":"@coderundebug/indexeddb-promise@1.0.2","maintainers":[{"name":"coderundebug","email":"StephenPaulHassall@hotmail.com"}],"homepage":"https://github.com/StephenHassall/indexeddb-promise","bugs":{"url":"https://github.com/StephenHassall/indexeddb-promise/issues","email":"StephenPaulHassall@hotmail.com"},"dist":{"shasum":"c5b7b61fa82c6699cc1ca7050a42004c157939c3","tarball":"https://registry.npmjs.org/@coderundebug/indexeddb-promise/-/indexeddb-promise-1.0.2.tgz","fileCount":13,"integrity":"sha512-LDisABYmlH952YYdDmeqlyHAZ8QJbbCLZfEgK6YiOJ9c1TrSQ+et6YmFqAozCTatB4Qm3bEWj61C3JNRJkYd6Q==","signatures":[{"sig":"MEQCICdnB6L6sdhEnLwc+c0O91jWGeb93UPfV5Wdpxxeq+YnAiACaywZt6PHlz+pessC2Z0bBh1af+RGvEr0+OW8PY2ohA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":66026},"type":"module","types":"./.d.js","browser":"indexeddb.js","funding":"https://github.com/StephenHassall/indexeddb-promise?sponsor=1","gitHead":"51236213b85931e3a92f324d2ecda99650da6cf9","scripts":{},"_npmUser":{"name":"coderundebug","email":"StephenPaulHassall@hotmail.com"},"repository":{"url":"git+https://github.com/StephenHassall/indexeddb-promise.git","type":"git"},"_npmVersion":"10.2.4","description":"Use IndexedDB with promises.","directories":{},"_nodeVersion":"21.4.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/indexeddb-promise_1.0.2_1716986647009_0.7930662338562418","host":"s3://npm-registry-packages"}},"1.0.3":{"name":"@coderundebug/indexeddb-promise","version":"1.0.3","keywords":["frontend","promise","promises","indexeddb","database"],"author":{"url":"https://coderundebug.com/","name":"Stephen Paul Hassall","email":"StephenPaulHassall@hotmail.com"},"license":"MIT","_id":"@coderundebug/indexeddb-promise@1.0.3","maintainers":[{"name":"coderundebug","email":"StephenPaulHassall@hotmail.com"}],"homepage":"https://github.com/StephenHassall/indexeddb-promise","bugs":{"url":"https://github.com/StephenHassall/indexeddb-promise/issues","email":"StephenPaulHassall@hotmail.com"},"dist":{"shasum":"166222a625c0d50243295b57e77ebf5a4bcb7a78","tarball":"https://registry.npmjs.org/@coderundebug/indexeddb-promise/-/indexeddb-promise-1.0.3.tgz","fileCount":13,"integrity":"sha512-x9MoL7vWxql1LwHitJ8IlabRjxoAhoqDr01q91pjeybe9ifYPtjxEk5ifMp9eG8BJT82CZajSRm9JqwFAMSqjQ==","signatures":[{"sig":"MEQCIB5EZQcutfVXixw9FVAMVU1V6OJw6dTVVyQxX+6zG6pMAiA2GkAszXtoGa+t3LotmfFgS6rFxV78glntNOzT8gbyMg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":68647},"type":"module","types":"./.d.js","browser":"indexeddb.js","funding":"https://github.com/StephenHassall/indexeddb-promise?sponsor=1","gitHead":"00f1f3855b52774b41325d3bee2ee370091e28cf","scripts":{},"_npmUser":{"name":"coderundebug","email":"StephenPaulHassall@hotmail.com"},"repository":{"url":"git+https://github.com/StephenHassall/indexeddb-promise.git","type":"git"},"_npmVersion":"10.2.4","description":"Use IndexedDB with promises.","directories":{},"_nodeVersion":"21.4.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/indexeddb-promise_1.0.3_1726577743222_0.58194638009412","host":"s3://npm-registry-packages"}},"1.0.4":{"name":"@coderundebug/indexeddb-promise","type":"module","version":"1.0.4","description":"Use IndexedDB with promises.","repository":{"type":"git","url":"git+https://github.com/StephenHassall/indexeddb-promise.git"},"funding":"https://github.com/StephenHassall/indexeddb-promise?sponsor=1","homepage":"https://github.com/StephenHassall/indexeddb-promise","bugs":{"url":"https://github.com/StephenHassall/indexeddb-promise/issues","email":"StephenPaulHassall@hotmail.com"},"browser":"indexeddb.js","types":"./.d.js","scripts":{},"author":{"name":"Stephen Paul Hassall","email":"StephenPaulHassall@hotmail.com","url":"https://coderundebug.com/"},"keywords":["frontend","promise","promises","indexeddb","database"],"license":"MIT","_id":"@coderundebug/indexeddb-promise@1.0.4","gitHead":"b35b43ffeeec7d7f61159dee649ee1668afc0a8e","_nodeVersion":"22.15.0","_npmVersion":"11.3.0","dist":{"integrity":"sha512-b3sa72pAVsCNTUiK0Sshs6kIjGpFUBb2qBUwhsIWIrfX/F8eqbCi4EO/WD08gPSjgOsmQiC0VBorXBtb72Y/tw==","shasum":"896fa86e70dc4baad50d59ee5d42dbad448483e9","tarball":"https://registry.npmjs.org/@coderundebug/indexeddb-promise/-/indexeddb-promise-1.0.4.tgz","fileCount":13,"unpackedSize":68931,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQChj4MQxLr3KYEYRp9Ajze50icdo7PiNXCwuOSOVgH3ywIhANYHCw85o+f2sXT1Qrejmwy9m1vrFwv8rY7b8LLX7THH"}]},"_npmUser":{"name":"coderundebug","email":"StephenPaulHassall@hotmail.com"},"directories":{},"maintainers":[{"name":"coderundebug","email":"StephenPaulHassall@hotmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/indexeddb-promise_1.0.4_1747476598530_0.6363270720190641"},"_hasShrinkwrap":false}},"time":{"created":"2024-05-28T13:10:39.429Z","modified":"2025-05-17T10:09:58.939Z","1.0.0":"2024-05-28T13:10:39.728Z","1.0.1":"2024-05-28T13:13:51.395Z","1.0.2":"2024-05-29T12:44:07.227Z","1.0.3":"2024-09-17T12:55:43.428Z","1.0.4":"2025-05-17T10:09:58.752Z"},"bugs":{"url":"https://github.com/StephenHassall/indexeddb-promise/issues","email":"StephenPaulHassall@hotmail.com"},"author":{"name":"Stephen Paul Hassall","email":"StephenPaulHassall@hotmail.com","url":"https://coderundebug.com/"},"license":"MIT","homepage":"https://github.com/StephenHassall/indexeddb-promise","keywords":["frontend","promise","promises","indexeddb","database"],"repository":{"type":"git","url":"git+https://github.com/StephenHassall/indexeddb-promise.git"},"description":"Use IndexedDB with promises.","maintainers":[{"name":"coderundebug","email":"StephenPaulHassall@hotmail.com"}],"readme":"# IndexedDB Promise\r\n\r\n> **Important:** This is an ESM only package. It uses the browser’s IndexedDB API.\r\n\r\nYou can find tests and example code on the GitHub repository that will help you understand how to use this package. [github.com/StephenHassall/indexeddb-promise](https://github.com/StephenHassall/indexeddb-promise)\r\n\r\n> **Important:** Most of the functions return a `Promise` object and need to be used with the `await` keyword. Not doing this will create errors. If you do have problems using the package then the first thing you need to do is double check any missing `await` statements.\r\n\r\n## Installation\r\n\r\n```\r\nnpm install @coderundebug/indexeddb-promise\r\n```\r\n\r\n## Contents\r\n\r\n- [Introduction](#introduction)\r\n- [Database](#database)\r\n- [Transaction](#transaction)\r\n- [ObjectStore](#objectstore)\r\n- [Index](#index)\r\n- [Cursor](#cursor)\r\n- [CursorWithValue](#cursorwithvalue)\r\n- [Factory](#factory)\r\n\r\n## Introduction\r\n\r\nThe IndexedDB API is a database in the browser, however it is not the same as a large SQL like database, but more like a simple object store with indexes. It is different compared to other databases you may have used before, but once you understand how to use it, you will find it very useful for storing data on the client end.\r\n\r\nAll the API tasks are performed on a different thread and any request to do something is performed on that thread. Once the task is performed it sends an event to signal that it has finished (or failed). When doing a number of tasks together, adding and removing records, dealing with the events can become a pain. This package was created to add promises to the tasks, allowing you to use async/await to perform the steps one after the other.\r\n\r\n```javascript\r\n// Create instance of my database\r\nconst myDatabase = new MyDatabase();\r\n\r\n// Open the database\r\nawait myDatabase.open();\r\n\r\n// Create transaction\r\nconst transaction = myDatabase.transaction('my-object-store', 'readwrite');\r\n\r\n// Open my object store (table)\r\nconst myObjectStore = transaction.objectStore('my-object-store');\r\n\r\n// Add record (object/document)\r\nawait myObjectStore.add({ id: 1, text: 'hello' });\r\nawait myObjectStore.add({ id: 2, text: 'world' });\r\n\r\n// Commit changes\r\nawait transaction.commit();\r\n\r\n// Close my database\r\nmyDatabase.close();\r\n```\r\nAll the classes are wrappers to the IDB interfaces but with promises and one or two extra helpful functions. The goal of this package is to make using the IndexedDB API easier, more understandable, but without replacing the core functions with something totally new.\r\n\r\nYou will find information on how most of the functions work by looking at the related interface functions associated with them. Their functions and parameters are basically the same.\r\n\r\n## Database\r\n\r\nThis class is a wrapper to the `IDBDatabase` interface, but you cannot use it directly, it needs to be derived from. You create your own class that extends from the `Database` class and then override the `_upgrade` function. This is used to create the internal object stores and indexes.\r\n\r\n```javascript\r\nclass MyDatabase extends Database {\r\n  constructor() {\r\n    // Call base constructor to set database name and version\r\n    super('my-database', 1);\r\n  }\r\n\r\n  _upgrade(transaction, oldVersion, newVersion) {\r\n    // New version (or first time)\r\n    this.createObjectStore('objectStore1');\r\n    this.createObjectStore('objectStore2');\r\n  }\r\n}\r\n```\r\n\r\n|Name|Information|\r\n|---|---|\r\n|**constructor**(*name*, *version*)|When you have derived your own class from `Database`, make sure you call the `super` function with the name of the database and its current version.|\r\n|**iDbDatabase**|Get the `IDBDatabase` interface object associated with the database.|\r\n|**version**|Get the version of the database.|\r\n|**name**|Get the name of the database.|\r\n|**objectStoreNames**|Get a list of object store names contained within the database.|\r\n|**open**<br>`async/await`|Opens the database and calls the `_upgrade` override function if required.|\r\n|**close**|Closes the database.|\r\n|**createObjectStore**(*name*, [*options*])|While upgrading you can create new object stores.|\r\n|**deleteObjectStore**(*name*)|While upgrading you can delete existing object stores.|\r\n|**transaction**(*storeNames*, [*mode*], [*options*])|When the database is open you can create a transaction.|\r\n|**_upgrade**(*transaction*, *oldVersion*, *newVersion*)|When the open function is called, if there is a different version number, then the `_upgrade` function will be called. You need to override this function within your own class and perform any upgrading steps required. You can use `async` with this function if required.|\r\n|**_close**|Override this function to handle when the database is closed unexpectedly. This is not called when the `close` function is used. |\r\n|**_versionChange**|Override this function to handle when the database has changed from elsewhere, in another tab for example.|\r\n\r\n## Transaction\r\n\r\nThis class is a wrapper to the `IDBTransaction` interface.\r\n\r\n|Name|Information|\r\n|---|---|\r\n|**iDbTransaction**|Get the `IDBTransaction` interface object associated with the transaction.|\r\n|**db**|Get the `IDBDatabase` interface object that created the transaction object.|\r\n|**durability**|Get the `durability` setting used when the transaction was created.|\r\n|**mode**|Get the `mode` setting used when the transaction was created.|\r\n|**objectStoreNames**|Get the list of object store names used when the transaction was created.|\r\n|**error**|Get the error why the transaction failed.|\r\n|**commit**<br>`async/await`|Commits any changes made with the transaction to the database.|\r\n|**abort**<br>`async/await`|Aborts all the changes made with the transaction.|\r\n|**objectStore**(*name*)|Get the object store object. It can only return an object store that was selected when the transaction was created.|\r\n\r\n## ObjectStore\r\n\r\nThis class is a wrapper to the `IDBObjectStore` interface.\r\n\r\n|Name|Information|\r\n|---|---|\r\n|**iDbObjectStore**|Get the `IDBObjectStore` interface object associated with the object store.|\r\n|**transaction**|Get the `IDBTransaction` interface object that created the object store object.|\r\n|**autoIncrement**|Get the `autoIncrement` setting used when the objectStore was created (in the `_upgrade` override function).|\r\n|**keyPath**|Get the `keyPath` setting used when the objectStore was created (in the `_upgrade` override function).|\r\n|**name**|Get the name of the object store.|\r\n|**indexNames**|Get a list of all the index names within the object store.|\r\n|**clear**()<br>`async/await`|Deletes all the objects (records) within the object store.|\r\n|**count**([*query*])<br>`async/await`|Counts the number of objects (records) that match the query.|\r\n|**add**(*value*, [*key*])<br>`async/await`|Insert a new object (record) into the object store.|\r\n|**put**(*value*, [*key*])<br>`async/await`|Updates an existing object (record) within the object store.|\r\n|**delete**(*key*)<br>`async/await`|Delete one or more objects (records) from the object store.|\r\n|**get**(*key*)<br>`async/await`|Get the first found object (record) using the key or key range.|\r\n|**getAll**([*query*], [*count*])<br>`async/await`|Get all the found objects (records) using the key or key range. It will only return up to the given count.|\r\n|**getKey**([*key*])<br>`async/await`|Get the first found key using the key or key range.|\r\n|**getAllKeys**([*query*], [*count*])<br>`async/await`|Get all the found keys using the query. It will only return up to the given count.|\r\n|**createIndex**(*indexName*, *keyPath*, [*options*])|Create a new index for the object store to use (in the `_upgrade` override function).|\r\n|**deleteIndex**(*indexName*)|Delete an existing index from the object store (in the `_upgrade` override function).|\r\n|**index**(*name*)|Get the index object used by the object store.|\r\n|**openCursor**([*query*], [*direction*])<br>`async/await`|Opens a cursor that is used to move through the matching objects (records).|\r\n|**openKeyCursor**([*query*], [*direction*])<br>`async/await`|Opens a cursor that is used to move through the matching objects (records) and return only the key parts (not the whole object).|\r\n\r\n## Index\r\n\r\nThis class is a wrapper to the `IDBIndex` interface.\r\n\r\n|Name|Information|\r\n|---|---|\r\n|**iDbIndex**|Get the `IDBIndex` interface object associated with the index.|\r\n|**objectStore**|Get the `IDBObjectStore` interface object that created the index object.|\r\n|**keyPath**|Get the `keyPath` setting used when the index was created (in the `_upgrade` override function).|\r\n|**multiEntry**|Get the `multiEntry` setting used when the index was created (in the `_upgrade` override function).|\r\n|**unique**|Get the `unique` setting used when the index was created (in the `_upgrade` override function).|\r\n|**name**|Get the name of the index.|\r\n|**count**([*key*])<br>`async/await`|Counts the number of objects (records) that match the query.|\r\n|**get**(*key*)<br>`async/await`|Get the first found object (record) using the key or key range.|\r\n|**getAll**([*query*], [*count*])<br>`async/await`|Get all the found objects (records) using the key or key range. It will only return up to the given count.|\r\n|**getKey**([*key*])<br>`async/await`|Get the first found key using the key or key range.|\r\n|**getAllKeys**([*query*], [*count*])<br>`async/await`|Get all the found keys using the query. It will only return up to the given count.|\r\n|**openCursor**([*range*], [*direction*])<br>`async/await`|Opens a cursor that is used to move through the matching objects (records).|\r\n|**openKeyCursor**([*range*], [*direction*])<br>`async/await`|Opens a cursor that is used to move through the matching objects (records) and return only the key parts (not the whole object).|\r\n\r\n## Cursor\r\n\r\nThis class is a wrapper to the `IDBCursor` interface.\r\n\r\n|Name|Information|\r\n|---|---|\r\n|**iDbCursor**|Get the `IDBCursor` interface object associated with the cursor.|\r\n|**source**|Get either the `IDBObjectStore` or `IDBIndex` interface object that created the cursor object.|\r\n|**request**|Get the `IDBRequest` interface object linked to the cursor.|\r\n|**direction**|Get the `direction` setting used when creating the cursor object.|\r\n|**key**|Get the current key value of the object the cursor is looking at.|\r\n|**primaryKey**|Get the current primary key value for the object the cursor is looking at.|\r\n|**advance**(*count*)<br>`async/await`|Make the cursor jump forward by the given number of steps. The promise resolves with `true`, record found, or `false` (passed end of list).|\r\n|**continue**([*key*])<br>`async/await`|More on to the next object (record). The promise resolves with `true`, record found, or `false` (passed end of list).|\r\n|**continuePrimaryKey**(*key*, *primaryKey*)<br>`async/await`|More on to the next object (record). The promise resolves with `true`, record found, or `false` (passed end of list).|\r\n\r\n## CursorWithValue\r\n\r\nThis class is a wrapper to the `IDBCursorWithValue` interface. This is derived from the `Cursor` class therefore it also contains all the properties and functions from that class.\r\n\r\n|Name|Information|\r\n|---|---|\r\n|**iDbCursorWithValue**|Get the `IDBCursorWithValue` interface object associated with the cursor.|\r\n|**value**|Get the current value, the object (record) itself, where the cursor is positioned at.|\r\n|**delete()**<br>`async/await`|Deletes the object (record) the cursor is currently positioned at.|\r\n|**update**(*value*)<br>`async/await`|Updates the object (record) the cursor is currently positioned at. This replaces the whole object with the existing one. Any indexes will automatically be updated.|\r\n\r\n## Factory\r\n\r\nThis is not a wrapper like the other classes. It is used to add promises to one of the `IDBFactor` functions.\r\n\r\n|Name|Information|\r\n|---|---|\r\n|**databases**|Get a list of all the databases. This information includes the name and version.|\r\n|**deleteDatabase**(*name*, [*options*])<br>`async/await`|Deletes a database.|\r\n","readmeFilename":"readme.md"}