this is a minimal example of running sqlite in the browser.
this automatically persists the database in the browser.
these two files need to be placed in the same folder on a static web server.
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <title>SQL browser demo</title> | |
| </head> | |
| <body> | |
| <script type="module"> | |
| import * as sql from "https://tombl.dev/sql/sql.js"; | |
| await sql.run`INSERT INTO test VALUES(5, ${5 + 5})`; | |
| console.table(await sql.query`SELECT * FROM test`); | |
| console.log(await sql.queryOne`SELECT * FROM test WHERE a=${1}`); | |
| </script> | |
| </body> | |
| </html> |
| CREATE TABLE test(a int, b int); | |
| INSERT INTO test VALUES(1, 2); | |
| INSERT INTO test VALUES(3, 4); |