{"_id":"@biodiv-platform/use-indexeddb","name":"@biodiv-platform/use-indexeddb","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.1":{"name":"@biodiv-platform/use-indexeddb","version":"1.0.1","description":"Lightweight hooks with promises for easy IndexedDB access in React","author":{"name":"Harsh Zalavadiya"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/biodiv-platform/use-indexeddb.git"},"module":"dist/index.esm.js","main":"dist/index.js","typings":"dist/index.d.ts","engines":{"node":">=18"},"scripts":{"start":"tsup src/index.tsx --watch","build":"tsup src/index.tsx --format cjs,esm --dts --minify","prepare":"tsup src/index.tsx --format cjs,esm --dts --minify"},"peerDependencies":{"react":">=18"},"devDependencies":{"@types/react":"^18.3.1","@types/react-dom":"^18.3.1","react":"^18.3.1","react-dom":"^18.3.1","tsup":"^8.4.0","typescript":"^5.8.0"},"_id":"@biodiv-platform/use-indexeddb@1.0.1","gitHead":"f6e5deed3f3c1010c4b314d72b25b5a4f454f07f","bugs":{"url":"https://github.com/biodiv-platform/use-indexeddb/issues"},"homepage":"https://github.com/biodiv-platform/use-indexeddb#readme","_nodeVersion":"22.13.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-HyXq18sXVUUN5TwmzUYgwqv/hH/Hx4smywYi5NkcA4cBJHm2vzEUdEMgSPBaRRuni4Vsx0jmdkarDqeeYJptEQ==","shasum":"bbf96da4e9526dd6e2b79f1b6ab5fa099abc12d2","tarball":"https://registry.npmjs.org/@biodiv-platform/use-indexeddb/-/use-indexeddb-1.0.1.tgz","fileCount":12,"unpackedSize":26094,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIE/WMNYBBWfxT7DbpfzNl+nS/ndIKxL9fCBsUU2YdgGPAiEAgoko39HhNn8++LPhQGitqJQEgN2Q+IogkNJcJ2g0mYE="}]},"_npmUser":{"name":"indiabiodiversity","email":"biodiv@indiabiodiversity.org"},"directories":{},"maintainers":[{"name":"indiabiodiversity","email":"biodiv@indiabiodiversity.org"},{"name":"arunstrandls","email":"arunbala.balasubramani@strandls.com"},{"name":"prakhardevsingh","email":"prakhar.singh@strandls.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/use-indexeddb_1.0.1_1782113993175_0.351785657569643"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-22T07:39:53.003Z","1.0.1":"2026-06-22T07:39:53.318Z","modified":"2026-06-22T07:39:53.566Z"},"maintainers":[{"name":"indiabiodiversity","email":"biodiv@indiabiodiversity.org"},{"name":"arunstrandls","email":"arunbala.balasubramani@strandls.com"},{"name":"prakhardevsingh","email":"prakhar.singh@strandls.com"}],"description":"Lightweight hooks with promises for easy IndexedDB access in React","homepage":"https://github.com/biodiv-platform/use-indexeddb#readme","repository":{"type":"git","url":"git+https://github.com/biodiv-platform/use-indexeddb.git"},"author":{"name":"Harsh Zalavadiya"},"bugs":{"url":"https://github.com/biodiv-platform/use-indexeddb/issues"},"license":"MIT","readme":"# use-indexeddb\n\nLightweight (1KB gzipped) hooks w/ promises for easy IndexedDB access in React ⚓\n\n[![Storybook](https://cdn.jsdelivr.net/gh/storybookjs/brand@master/badge/badge-storybook.svg)](https://use-indexeddb.pages.dev)\n[![GitHub Actions Status](https://github.com/harshzalavadiya/use-indexeddb/workflows/CI/badge.svg)](https://github.com/harshzalavadiya/use-indexeddb/actions)\n[![NPM](https://img.shields.io/npm/v/use-indexeddb.svg)](https://npm.im/use-indexeddb)\n[![gzip](https://badgen.net/bundlephobia/minzip/use-indexeddb@latest)](https://bundlephobia.com/result?p=use-indexeddb@latest)\n\n## 🔧 Installation\n\n```bash\nnpm i use-indexeddb    # npm\nyarn add use-indexeddb # yarn\n```\n\n## 📚 Storybook\n\n[see demo on storybook](https://use-indexeddb.pages.dev/)\n\n## ✨ Features\n\n- 🍃 Lightweight (~3KB gzipped) [no dependencies]\n- 🧠 Automatic modal type inference like `useIndexedDBStore<YourInterface>()`\n- ✅ SSR Safe\n- 🤞 Simple [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) based api\n\n## 📦 Examples\n\n1. [add](#addvalue-key)\n2. [getByID](#getbyidid)\n3. [getAll](#getall)\n4. [getOneByKey](#getonebykeykeypath-value)\n5. [getManyByKey](#getmanybykeykeypath-value)\n6. [update](#updatevalue-key)\n7. [deleteByID](#deletebyidid)\n8. [deleteAll](#deleteall)\n9. [openCursor](#opencursorcursorcallback-keyrange)\n\n### Full Example\n\n```tsx\nimport React from \"react\";\nimport setupIndexedDB, { useIndexedDBStore } from \"use-indexeddb\";\n\n// Database Configuration\nconst idbConfig = {\n  databaseName: \"fruity-db\",\n  version: 1,\n  stores: [\n    {\n      name: \"fruits\",\n      id: { keyPath: \"id\", autoIncrement: true },\n      indices: [\n        { name: \"name\", keyPath: \"name\", options: { unique: false } },\n        { name: \"quantity\", keyPath: \"quantity\" },\n      ],\n    },\n  ],\n};\n\nconst Example = () => {\n  useEffect(() => {\n    setupIndexedDB(idbConfig)\n      .then(() => console.log(\"success\"))\n      .catch(e => console.error(\"error / unsupported\", e));\n  }, []);\n\n  const { add } = useIndexedDBStore(\"fruits\");\n\n  const insertFruit = () => {\n    add({ name: \"Mango 🥭\", quantity: 2 }).then(console.log);\n  };\n\n  return <button onClick={insertFruit}>Insert</button>;\n};\n\nexport default Example;\n```\n\n### `add(value, key?)`\n\nInserts given `value` record to selected store, second param is optional key useful if auto-increment is disabled\n\nBy default commit is enabled after each transaction so changes are reflected in indexedDB instantly\n\n```jsx\nimport { useIndexedDBStore } from \"use-indexeddb\";\n\nfunction Example() {\n  const { add } = useIndexedDBStore(\"fruits\");\n\n  const onClick = () => {\n    add({ name: \"Mango 🥭\", quantity: 2 })\n      .then(d => console.log(`Added Fruit with ID ${d}`))\n      .catch(console.error);\n  };\n\n  return <button onClick={onClick}>Add</button>;\n}\n```\n\n### `getByID(id)`\n\nRetrive record by ID\n\n```jsx\nimport { useIndexedDBStore } from \"use-indexeddb\";\n\nfunction Example() {\n  const { getByID } = useIndexedDBStore(\"fruits\");\n\n  const onClick = () => {\n    getByID(1)\n      .then(console.log)\n      .catch(console.error);\n  };\n\n  return <button onClick={onClick}>Get - ID 1</button>;\n}\n```\n\n### `getAll()`\n\nRetrive all records from provided store\n\n```jsx\nimport { useIndexedDBStore } from \"use-indexeddb\";\n\nfunction Example() {\n  const { getAll } = useIndexedDBStore(\"fruits\");\n\n  const onClick = () => {\n    getAll()\n      .then(console.log)\n      .catch(console.error);\n  };\n\n  return <button onClick={onClick}>Get All Fruits</button>;\n}\n```\n\n### `getOneByKey(keyPath, value)`\n\nRetrives single record if any row matches with given `keyPath` having `value`\n\n```jsx\nimport { useIndexedDBStore } from \"use-indexeddb\";\n\nfunction Example() {\n  const { getOneByKey } = useIndexedDBStore(\"fruits\");\n\n  const onClick = () => {\n    getOneByKey(\"quantity\", 2)\n      .then(console.log)\n      .catch(console.error);\n  };\n\n  return <button onClick={onClick}>Get Fruit w/ Qty 2</button>;\n}\n```\n\n### `getManyByKey(keyPath, value)`\n\nRetrives multiple records in form of array if row matches with given `keyPath` having `value`\n\n```jsx\nimport { useIndexedDBStore } from \"use-indexeddb\";\n\nfunction Example() {\n  const { getManyByKey } = useIndexedDBStore(\"fruits\");\n\n  const onClick = () => {\n    getManyByKey(\"quantity\", 2)\n      .then(console.log)\n      .catch(console.error);\n  };\n\n  return <button onClick={onClick}>Get All Fruits w/ Qty 2</button>;\n}\n```\n\n### `update(value, key?)`\n\nInserts or Updates given `value` in store by `ID`\n\n```jsx\nimport { useIndexedDBStore } from \"use-indexeddb\";\n\nfunction Example() {\n  const { update } = useIndexedDBStore(\"fruits\");\n\n  const onClick = () => {\n    update({ id: 1, name: \"Strawberry 🍓\", quantity: 20 })\n      .then(console.log)\n      .catch(console.error);\n  };\n\n  return <button onClick={onClick}>Update Fruid #1 to Strawberry</button>;\n}\n```\n\n### `deleteByID(id)`\n\nDeletes record by ID\n\n```jsx\nimport { useIndexedDBStore } from \"use-indexeddb\";\n\nfunction Example() {\n  const { deleteByID } = useIndexedDBStore(\"fruits\");\n\n  const onClick = () => {\n    deleteByID(1)\n      .then(console.log)\n      .catch(console.error);\n  };\n\n  return <button onClick={onClick}>Delete Fruit with ID 1</button>;\n}\n```\n\n### `deleteAll()`\n\nDeletes all records\n\n```jsx\nimport { useIndexedDBStore } from \"use-indexeddb\";\n\nfunction Example() {\n  const { deleteAll } = useIndexedDBStore(\"fruits\");\n\n  const onClick = () => {\n    deleteAll()\n      .then(console.log)\n      .catch(console.error);\n  };\n\n  return <button onClick={onClick}>Delete All Fruits</button>;\n}\n```\n\n### `openCursor(cursorCallback, keyRange?)`\n\nYou can use `openCursor` to iterate over objects one by one within given `keyRange`\n\n```jsx\nimport { useIndexedDBStore } from \"use-indexeddb\";\n\nfunction Example() {\n  const { openCursor } = useIndexedDBStore(\"fruits\");\n\n  const onClick = () => {\n    openCursor(e => {\n      const c = e.target.result;\n      if (c) {\n        console.log(c);\n        c.continue();\n      } else {\n        console.log(\"that's all folks\");\n      }\n    });\n  };\n\n  return <button onClick={onClick}>Open Cursor</button>;\n}\n```\n\n## 🤠 Credits\n\n- This library takes inspiration from [react-indexed-db](https://github.com/assuncaocharles/react-indexed-db)\n- [TypeScript](https://github.com/microsoft/typescript)\n- [TSDX](https://github.com/jaredpalmer/tsdx)\n\n## 📜 License\n\nMIT &copy; [harshzalavadiya](https://github.com/harshzalavadiya)\n","readmeFilename":"README.md","_rev":"1-8d49ec0779abc54dd492002608eacd5b"}