Drivers
Browser
Store data in localStorage, sessionStorage or IndexedDB
LocalStorage / SessionStorage
Usage
Driver name: localstorage
or sessionstorage
Store data in localStorage or sessionStorage
import { createStorage } from "unstorage";
import localStorageDriver from "unstorage/drivers/localstorage";
const storage = createStorage({
driver: localStorageDriver({ base: "app:" }),
});
Options:
base
: Add base to all keys to avoid collisionstorage
: (optional) providelocalStorage
orsessionStorage
compatible object.windowKey
: (optional) Can be"localStorage"
(default) or"sessionStorage"
window
: (optional) providewindow
object
IndexedDB
Store key-value in IndexedDB.
Usage
Driver name: indexeddb
To use it, you will need to install idb-keyval
in your project:
npm i idb-keyval
Usage:
import { createStorage } from "unstorage";
import indexedDbDriver from "unstorage/drivers/indexedb";
const storage = createStorage({
driver: indexedDbDriver({ base: "app:" }),
});
Options:
base
: Add${base}:
to all keys to avoid collisiondbName
: Custom name for database. Defaults tokeyval-store
storeName
: Custom name for store. Defaults tokeyval
IndexedDB is a browser database. Avoid using this preset on server environments.