How I made SQL run inside a single, offline HTML file (no WASM)
There's a whole genre of "single-file HTML data viewer" tools: you point them at a CSV and they emit one .html file you can email, drop on a share drive, or open on an air-gapped machine. They're great for looking at data. But the moment you want to actually ask a question — "how many rows per category?", "top 10 by revenue?" — you're back to sorting columns by hand or re-exporting from a real…
Dataloupe now includes a full SQL console that runs entirely within a single HTML file, without requiring any server, WASM download, or network requests. This is achieved by leveraging an existing, lightweight read-only query engine that already exists within the tool. The SQL feature is essentially a compiler that takes a string of SQL text and converts it into a query specification object that the engine can execute.
This compiler is a hand-written tokenizer and recursive-descent parser with no dependencies, keeping the overall code size tiny. The generated file size remains around 35KB even for small datasets. The SQL text is treated as data (a plan object), never as executable code, which allows it to run safely under the same content security policy (CSP) restrictions as the rest of the file.
Users can simply open the file, click on the SQL panel, and execute queries like "SELECT dept, COUNT(*), AVG(salary) FROM people WHERE salary > 100000 AND city IN (NYC, SF) GROUP BY dept ORDER BY AVG(salary) DESC LIMIT 10". All queries are executed client-side, with results displayed in a table below the editor. No network activity is visible in the browser's network tab, ensuring the tool remains entirely offline.
This approach of reusing an existing execution path for SQL queries, rather than adopting a full database engine or a WASM blob, is a cost-effective way to add SQL capabilities to an application, provided a structured query layer already exists.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.