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";
const txn = new Transaction();
const tasks = txn.create(new Index('number'));
tasks.put(txn, 1, 'Try Timi');
tasks.put(txn, 2, 'Have a cup of tea');
tasks.put(txn, 3, 'Eat some cake');
const description = tasks.get(txn, 2);
tasks.entries(txn, (id, description) => {
console.log(`${id}: ${description}`);
});
Documentation
API Reference
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.
B-Tree 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.
caolan@caolan.uk