Skip to content

mightylittle/transaction-log-idb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@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));
  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);
  console.log("transactions", await log.getSeqRangeTransactions(1, 2)); // prints the first and second entries
  console.log("commits", await log.getSeqRangeCommits(1)); // prints the first and any later commits
  await log.close();
  await log.clear();
}

Installation

npm install

Development

Build:

npm run build

Run tests:

npm run test

NOTE: the mocha tests run in-browser, where IndexedDB is supported.

Generate documentation:

npm run typedoc

Dependencies

Author

  • John Newton

Copyright

  • John Newton

License

Apache-2.0

About

Replayable logs using IndexedDB

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published