Skip to content

Instantly share code, notes, and snippets.

@tombl
Last active May 3, 2022 10:18
Show Gist options
  • Save tombl/c35015b728d37c0f7005ce58586a0127 to your computer and use it in GitHub Desktop.
Save tombl/c35015b728d37c0f7005ce58586a0127 to your computer and use it in GitHub Desktop.
sqlite gaming

sqlite gaming

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment