0.2.0 • Published 6 months ago
bun-storage v0.2.0
bun-storage
A ponyfill for the Storage API, utilizing SQLite
Installation
bun install bun-storage
Usage
API
createLocalStorage
Usage: createLocalStorage(dbFile: string)
Returns: [Storage, EventEmitter]
Creates an instance of the localStorage
API and a corresponding EventEmitter.
Example:
import { createLocalStorage } from 'bun-storage';
const [ localStorage, emitter ] = createLocalStorage('./db.sqlite');
// Listen for storage changes
emitter.addListener('storage', console.log);
createSessionStorage
Usage: createSessionStorage()
Returns: [Storage, EventEmitter]
Creates an instance of the sessionStorage
API and a corresponding EventEmitter.
Example:
import { createSessionStorage } from 'bun-storage';
const [ sessionStorage, emitter ] = createSessionStorage();
// Listen for storage changes
emitter.addListener('storage', console.log);
Storage
Usage: new Storage(filePath: string | ':memory:', options: StorageEventOptions)
This class is used internally by both of the above factory functions. However, instanting the class allows you more control over the EventEmitter, i.e. you pass an existing one from your application code.
Example:
import { Storage } from 'bun-storage';
import EventEmitter from 'events';
const myEmitter = new EventEmitter();
const localStorage = new Storage('./db.sqlite', {
emitter: myEmitter
});
// Listen for storage changes
myEmitter.addListener('storage', console.log);
License
This work is licensed under The MIT License.