GitHub user phiresky recently published an interesting blog post on Hosting SQLite databases on Github Pages.
Using SQLite – or in fact any kind of SQL database – in the browser? Why should one want to do this? Now, while it’s certainly true that in the context of web applications SQL databases and RDBMS generally are relegated to the realm of back-end servers, depending on the requirements, a database in a front-end application or a self-contained application that doesn’t even have or require back-end systems can be quite useful.
For example, such an approach of having a static (i.e., not dynamically generated by a server) front-end application provide a database lends itself to the development of progressive web apps (PWA), which ideally act like locally installed applications that don’t require connectivity to external resources such as a database server.
While there certainly are APIs like IndexedDB and frameworks such as Dexie building upon those APIs that provide database-like functionality in the browser (as used in my gdpr-transparency project), there’s something to be said about the simplicity and elegance that comes with SQL and its declarative approach.
Unfortunately, Web SQL Database – a native browser API for SQL – for all intents and purposes is abandoned and support probably will be discontinued by most larger browser vendors in the not-too-distant future.
Hence, having SQL as an additional option for working with data in the browser, could come in handy, especially if you’re used to working with relational databases and the declarative data access patterns SQL entails.
Although it involves some more details, in a nutshell the solution described in the blog post revolves around compiling SQLite (which itself is written in C) to WebAssembly – an LLVM compiler target for web browsers.