Drivers
Browser
Browser based storages.
Local Storage
Store data in localStorage.
Usage
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 collisionlocalStorage
: Optionally providelocalStorage
objectwindow
: Optionally providewindow
object
Session Storage
Store data in sessionStorage.
import { createStorage } from "unstorage";
import sessionStorageDriver from "unstorage/drivers/session-storage";
const storage = createStorage({
driver: sessionStorageDriver({ base: "app:" }),
});
Options:
base
: Add${base}:
to all keys to avoid collisionsessionStorage
: Optionally providesessionStorage
objectwindow
: Optionally providewindow
object
IndexedDB
Store key-value in IndexedDB.
Usage
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.