@caolan/timi
v0.1.1
Published
JavaScript indexes with transactions
Downloads
34
Maintainers
Readme
Timi
A JavaScript library to build database-style indexes in memory. It uses B+trees with some advanced features:
- Fast sorted-order iteration
- Optional duplicate key support
- Transactions: both nested and spanning multiple indexes
- And cheap immutable snapshots
Timi is written using plain JavaScript modules with no external dependencies.
Download
Source code:
NPM package:
npm install @caolan/timi
Example
import { Transaction, Index } from "timi.js";
// All data lives within a transaction.
const txn = new Transaction();
// Create an index.
const tasks = txn.create(new Index('number'));
// Add some data to the index.
tasks.put(txn, 1, 'Try Timi');
tasks.put(txn, 2, 'Have a cup of tea');
tasks.put(txn, 3, 'Eat some cake');
// Read a given key.
const description = tasks.get(txn, 2);
// Iterate over all entries
tasks.entries(txn, (id, description) => {
console.log(`${id}: ${description}`);
});
Documentation
Tests
The unit tests are written for Deno.
deno test
Benchmarks
Despite the extra features, Timi benchmarks favourably against all JavaScript B-tree/B+tree implementations that I've found. If you know of another library, or you believe I'm using a library incorrectly, please contact me so I can update the benchmarks.
Support
There is no public issue tracker yet. I'd be grateful for an email with your bug reports or feedback. As with all my libraries, commercial support is available.