https://github.com/rayriffy/datastore
Browser-level KV store, utilizing both IndexedDB and local storage.
https://github.com/rayriffy/datastore
indexeddb kv-store localstorage
Last synced: 6 months ago
JSON representation
Browser-level KV store, utilizing both IndexedDB and local storage.
- Host: GitHub
- URL: https://github.com/rayriffy/datastore
- Owner: rayriffy
- License: mit
- Created: 2023-06-16T10:16:56.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-06-30T12:07:22.000Z (over 2 years ago)
- Last Synced: 2025-02-14T05:25:54.347Z (8 months ago)
- Topics: indexeddb, kv-store, localstorage
- Language: TypeScript
- Homepage:
- Size: 113 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# datastore
Browser-level KV store, utilizing both IndexedDB and local storage.
This library will provide benefits of almost unlimited storage size of IndexedDB, with ease of use when interacting with interface like LocalStorage.
If browser does not have IndexedDB, this library will performs a fallback to LocalStorage by itself
## Install
```bash
pnpm add @rayriffy/datastore
```## Usage
```ts
// initialize (initialize once, use everywhere)
const instance = createInstance('indexedDb-database-name')// set (lib will JSON.stringify() for you in localStorage)
await instance.setItem('key1', {
message: 'amogus',
})// get (default to null) (lib will JSON.parse() for you in localStorage)
const val = await instance.getItem('key1')// delete
await instance.removeItem('key1')// clear
await instance.clear()
```## Publishing
This repository has been configured to automatically publish NPM packages by [Changesets](https://github.com/changesets/changesets). Run `pnpm changeset` command to publishing your changes before commit.