@mightylittle/transaction-log-idb
v0.2.0
Published
Replayable logs using IndexedDB.
Downloads
3
Readme
@mightylittle/transaction-log-idb
Replayable logs using IndexedDB
The package defines two exported classes:
- IDBSimpleTransactionLog
- IDBBatchedTransactionLog
Usage
IDBSimpleTransactionLog
JavaScript example:
import { IDBSimpleTransactionLog } from "@mightylittle/transaction-log-idb";
async function start () {
const log = new IDBSimpleTransactionLog();
await log.open();
await log.append("foo");
await log.append("bar");
await log.countTransactions(); // => 2
await log.replay((data) => console.log("data", data));
await console.log("transactions", await log.getSeqRangeTransactions(1, 2)); // returns the first and second entries
await log.close();
await log.clear();
}IDBBatchedTransactionLog
JavaScript example:
import { IDBBatchedTransactionLog } from "@mightylittle/transaction-log-idb";
async function start () {
const log = new IDBBatchedTransactionLog();
await log.open();
log.append("foo");
log.append("bar");
await log.commit();
await log.countTransactions(); // => 2
await log.countCommits(); // => 1
await log.replay((data) => console.log("data", data), true);
await console.log("transactions", await log.getSeqRangeTransactions(1, 2)); // prints the first and second entries
await console.log("commits", await log.getSeqRangeCommits(1)); // prints the first and any later commits
await log.close();
await log.clear();
}Installation
npm installDevelopment
Build:
npm run buildRun tests:
npm run testNOTE: the mocha tests run in-browser, where IndexedDB is supported.
Generate documentation:
npm run typedocDependencies
Author
- John Newton
Copyright
- John Newton
License
Apache-2.0
