Skip to content

subins2000/activerecord-ruby-wasm

Repository files navigation

ActiveRecord SQLite playground

Ruby on Rails ActiveRecord SQLite playground in the browser. Try it out at https://activerecord-ruby-wasm.subinsb.com/

It works by making use of two different WASMs: Ruby WASM and SQLite WASM.

ActiveRecord gem is baked into the ruby wasm binary. A custom SQLite driver is created for ActiveRecord (thanks to palkan). This custom driver (mix of Ruby and JavaScript) acts as the middleperson between ActiveRecord and SQLite WASM. ActiveRecord only expects a driver to execute raw SQL and return the result.

This was presented as a lightning talk at RubyConf India, 2024. The initial idea was to present something cool at the conf, I had this WASM idea for a while and decided to build it before/during the conf. Once I tweeted it out, I got to know that the same driver idea was already implemented but it was a full RoR app!

Deployment

SQLite WASM OPFS requires some specific headers.

npm run build
# use rsync

# Caddy config
activerecord-ruby-wasm.subinsb.com {
  root * /home/user/activerecord-ruby-wasm/dist
  file_server
  header {
    Cross-Origin-Embedder-Policy "require-corp"
    Cross-Origin-Opener-Policy "same-origin"
  }
}

About

Play with a SQLite DB on browser with ActiveRecord

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published