Sitemap

Running sqlite on the browser

2 min readJun 6, 2022

--

More and more e-learning platform, code interview platform, and online IDEs are using online code executing system. Such as leetcode, HackRank, Codility, w3school, etc.

Press enter or click to view image in full size

Some platforms even support estimating time and space complexity. These platforms contains at least two parts: the front end support code hight, and the backend support submit code , compile and run. There are lots of very popular & easy to use front end solutions, such as Prism.js, Highlight.js, etc. And in the backend, Judge0 is quite popular solution.

Today, I will introduce another solution, which does not need to run backend server, because it run the whole database on the frontend — sql.js.

At first, let’s get a basic feeling of this frontend database: https://sql.js.org/examples/GUI/

Press enter or click to view image in full size

sql.js uses emscripten to compile SQLite to webassembly (or to javascript code for compatibility with older browsers). It includes contributed math and string extension functions.

sql.js depends on wasm, to host it, you need to download sql-wasm.js & sql-wasm.wasm, they can be copy from node_modules/sql.js/, after you npm install sql.js. Example code can be found here.

Basically, it just run your SQL code in the db.run(“<SQL CODE>”) API, then you can get results into javascript objects by: stmt.getAsObject(). Because it purely runs in the frontend, refresh page or close browser will lost every thing, but it also support load & save db into sqlite db file.

--

--

go.fly
go.fly

Written by go.fly

Drone photographer, traveler, hacker

No responses yet

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy