StarlingDB
Phone
in memoryOpening
These are two real databases, kept in memory until you leave the page. Go offline, rename a todo on the laptop and tick it on the phone, then reconnect: both changes are kept. When the roots match, the two hold the same records.
Merge two copies
Section titled “Merge two copies”Each copy of a database works on its own. To bring another copy up to date, send it your changes:
const changes = await laptop.changesSinceBookmark("phone"); // plain JSON: send it any way you likeawait phone.merge(changes); // safe to repeat, in any orderawait laptop.bookmark("phone"); // next time, get only what is newWhen two copies changed the same record, StarlingDB merges it field by field. A deletion always wins. Merging explains the rules.
Two databases that hold the same records have the same root, a short code. Compare the roots to check that two copies match.
How it compares with SQLite
Section titled “How it compares with SQLite”Like SQLite, StarlingDB is one file that your app reads and writes directly, with one writer. Unlike SQLite, it stores JSON records and not tables, it has no SQL, and its copies merge.
| StarlingDB | SQLite | |
|---|---|---|
| Data | JSON records in named collections | Tables, queried with SQL |
| Transactions | Yes | Yes |
| Filters | Equals, not equal, ranges, in, starts with, ends with, substrings, array contains, and, or |
All of those, and like, matching without case, nested fields |
| Sort | Any number of fields, then ID | Any expressions |
| Limit, offset, count, count by a field | Yes | Yes |
| Sum, min, max, average | No | Yes |
| Joins | No | Yes |
| Indexes | No. Every query reads its whole collection | Yes |
| Unique and foreign-key constraints | No | Yes |
| Full-text search | No | Yes |
| Concurrent readers | No | Yes |
| In memory | Yes | Yes |
| In a browser | Yes, with the npm package | Yes, with its WebAssembly build |
| Merge between copies | Yes, field by field, in any order | No. Its session extension records changes, but you must resolve conflicts |
| A quick check that two copies match | Yes, compare their roots | No |
Speed compared with SQLite
Section titled “Speed compared with SQLite”These timings are for 100,000 small to-do records on an Apple M2 Pro.
SQLite is set up the way an app might use it for the same data:
- It stores each record as JSON text in one table, and queries it with its JSON functions.
- It does not use a write-ahead log. This is its default.
- It waits for the disk on every commit (
synchronous=FULL), as StarlingDB does.
If you add an index on a field, SQLite filters on that field much faster than either column here.
| StarlingDB | SQLite | |
|---|---|---|
| Load 100,000 in one commit | 313 ms | 200 ms |
| Every record | 69 ms | 63 ms |
| One list (1 in 20) | 22 ms | 52 ms |
| Newest 25 | 17 ms | 60 ms |
| Count not done, by list | 25 ms | 85 ms |
| 10,000 gets by ID | 12 ms | 53 ms |
| 1,000 inserts, a commit each | 108 ms | 246 ms |
| 1,000 updates of two fields, a commit each | 170 ms | 237 ms |
| 1,000 deletes, a commit each | 122 ms | 227 ms |
To run the benchmark yourself, use cargo run --release --example bench_queries 100000. It checks
that both databases return the same records before it times them.
StarlingDB is in alpha. The file format and the API can still change.
To get started, choose your language:
- TypeScript quickstart, for the npm package
starlingdb - Rust quickstart, for the crate
starlingdb