{"id":17234840,"url":"https://github.com/astoilkov/local-db-storage","last_synced_at":"2025-04-14T02:07:52.076Z","repository":{"id":209617852,"uuid":"724504781","full_name":"astoilkov/local-db-storage","owner":"astoilkov","description":"IndexedDB wrapper that mimics localStorage API","archived":false,"fork":false,"pushed_at":"2024-12-04T12:14:43.000Z","size":25,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-14T02:07:46.288Z","etag":null,"topics":["indexeddb","localstorage","persistent"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/astoilkov.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-28T08:05:48.000Z","updated_at":"2025-03-10T18:57:48.000Z","dependencies_parsed_at":"2023-11-28T17:12:05.478Z","dependency_job_id":"6f9c6d51-94bd-489d-97b4-bafc058cf46a","html_url":"https://github.com/astoilkov/local-db-storage","commit_stats":null,"previous_names":["astoilkov/db-storage","astoilkov/db-storage2"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astoilkov%2Flocal-db-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astoilkov%2Flocal-db-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astoilkov%2Flocal-db-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astoilkov%2Flocal-db-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/astoilkov","download_url":"https://codeload.github.com/astoilkov/local-db-storage/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248809044,"owners_count":21164896,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["indexeddb","localstorage","persistent"],"created_at":"2024-10-15T05:30:50.394Z","updated_at":"2025-04-14T02:07:52.052Z","avatar_url":"https://github.com/astoilkov.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `local-db-storage`\n\n\u003e `IndexedDB` wrapper that mimics `localStorage` API\n\n[![Gzipped Size](https://img.shields.io/bundlephobia/minzip/local-db-storage)](https://bundlephobia.com/result?p=local-db-storage)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/astoilkov/local-db-storage/main.yml?branch=main)](https://github.com/astoilkov/local-db-storage/actions/workflows/main.yml)\n\n## Install\n\n```bash\nnpm install local-db-storage\n```\n\n## Why\n\n- **Simple.** `localStorage` like API, without the complications of `IndexedDB`.\n- **Capacity.** `IndexedDB` can store hundred of megabytes to gigabytes of data. `localStorage` limit is around 5-10MB.\n- **Performance.** `IndexedDB` is async and doesn't block the UI. `IndexedDB` can store objects without serialization which shaves off the time to do `JSON.parse()` and `JSON.stringify()` that's needed when working with `localStorage`.\n- **No good alternatives.** The most popular library [`localForage`](https://github.com/localForage/localForage) (25k stars) is complex and unmaintained.\n- **Availability.** `IndexedDB` is available both in Web Worker and Service Worker, `localStorage` is not. You can write data in those places and then access it in the main thread.\n- **Maintenance.** I've been consistently maintaining many open-source libraries including [`use-local-storage-state`](https://github.com/astoilkov/use-local-storage-state) with ~500k downloaders per month.\n\n## Usage\n\n```ts\nimport dbStorage from 'local-db-storage'\n\nasync function addTodo(todo): Promise\u003cvoid\u003e {\n    await dbStorage.setItem(todo.id, todo)\n}\n\nasync function getTodo(id: string): Promise\u003cTodo\u003e {\n    await dbStorage.getItem\u003cTodo\u003e(id)\n}\n```\n\n## API\n\n#### `getItem\u003cT\u003e(key: string): Promise\u003cT\u003e`\n\nLike `localStorage.getItem()` but async.\n\n#### `setItem(key: string, value: any): Promise\u003cvoid\u003e`\n\nLike `localStorage.setItem()` but async.\n\n_Note:_ It supports non-primitive values (ex: objects). It also supports circular references.\n\n#### `removeItem(key: string): Promise\u003cvoid\u003e`\n\nLike `localStorage.removeItem()` but async.\n\n#### `clear(): Promise\u003cvoid\u003e`\n\nLike `localStorage.clear()` but async.\n\n#### `DBStorage(name: string)`\n\nCreates a new `DBStorage` instance.\n\n```ts\nimport { DBStorage } from 'local-db-storage'\n\nconst dbStorage = new DBStorage('my-custom-db-storage')\n\nawait dbStorage.setItem('initial', 'hello world')\n```\n\n## Related\n\n- [`use-db`](https://github.com/astoilkov/use-db) — React hook for `IndexedDB` that uses this library and mimics `setState` API.\n- [`use-local-storage-state`](https://github.com/astoilkov/use-local-storage-state) — React hook that persists data in `localStorage`.\n- [`use-session-storage-state`](https://github.com/astoilkov/use-session-storage-state) — React hook that persists data in `sessionStorage`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fastoilkov%2Flocal-db-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fastoilkov%2Flocal-db-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fastoilkov%2Flocal-db-storage/lists"}