Skip to content

starling-db

An embedded, single-user database whose copies merge. One file, read and written in-process, in Rust and in the browser.

Laptop

in memory
    Rootnone

    Phone

    in memory
      Rootnone

      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.

      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 like
      await phone.merge(changes); // safe to repeat, in any order
      await laptop.bookmark("phone"); // next time, get only what is new

      When two copies changed the same record, starling-db 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.

      Like SQLite, starling-db 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.

      starling-db SQLite
      Data JSON records in named collections Tables, queried with SQL
      Transactions Yes Yes
      Filters Equals, not equal, ranges, in, starts with, array contains, and, or All of those, and substrings, like, nested fields
      Sort One field, 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

      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 starling-db does.

      If you add an index on a field, SQLite filters on that field much faster than either column here.

      starling-db 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.

      starling-db is in alpha. The file format and the API can still change.

      To get started, choose your language: