Skip to content

astoilkov/local-db-storage

Repository files navigation

local-db-storage

Tiny wrapper around IndexedDB that mimics localStorage API

Gzipped Size Build Status

Install

npm install local-db-storage

Why

  • If you want to use IndexedDB but don't want to deal with its complex API.
  • If you want to store more data than what localStorage supports but still want the same API.
  • The most popular library localForage is bloated and unmaintained.

Usage

import dbStorage from 'local-db-storage'

async function addTodo(todo): Promise<void> {
    await dbStorage.setItem(todo.id, todo)
}

async function getTodo(id: string): Promise<Todo> {
    await dbStorage.getItem<Todo>(id)
}

API

getItem<T>(key: string): Promise<T>

Like localStorage.getItem() but async.

setItem(key: string, value: any): Promise<void>

Like localStorage.setItem() but async. It supports non-primitive values like objects. It also supports circular references.

removeItem(key: string): Promise<void>

Like localStorage.removeItem() but async.

clear(): Promise<void>

Like localStorage.clear() but async.

Related

About

Tiny wrapper around IndexedDB that mimics localStorage API

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project