logoalt Hacker News

zackifyyesterday at 9:33 PM3 repliesview on HN

This is great... just got it working using bun:sqlite! Just need to have "LITESTREAM_REPLICA_URL" and the key id and secret env vars set when running the script.

  import { Database } from "bun:sqlite";
  Database.setCustomSQLite("/opt/homebrew/opt/sqlite/lib/libsqlite3.dylib");

  // Load extension first with a temp db
  const temp = new Database(":memory:");
  temp.loadExtension("/path/to/litestream.dylib", "sqlite3_litestreamvfs_init");

  // Now open with litestream VFS
  const db = new Database("file:my.db?vfs=litestream");

  const fruits = db.query("SELECT * FROM fruits;").all();
  console.log(fruits);

Replies

koengtoday at 2:06 AM

Neat! Would this mainly be used for JavaScript servers running bun (ie, not end users)?

seigelyesterday at 11:26 PM

Cool that you got this to work! How did you get the "dylib" location or file.

show 2 replies
seigeltoday at 2:28 AM

For anyone following this example, one thing to note that I figured out the hard way is that this line from @zackify SHOULD BE HIGHTLIGHTED...

* "Just need to have "LITESTREAM_REPLICA_URL" and the key id and secret env vars set when running the script"

... and that attempting to load the variables using `dotenv` will not work!!