Performance: SQLite for embedded use
This affects page load speed and interaction responsiveness by how quickly data can be read and written locally without network delays.
const db = new DB(); // Use a worker thread or asynchronous API to run queries // Example using a worker thread or Deno subprocess const process = Deno.run({ cmd: ["sqlite3", "db.sqlite", "SELECT * FROM large_table"] }); await process.status(); process.close();
const db = new DB(); db.query("SELECT * FROM large_table"); // runs on main thread synchronously // heavy queries block UI and delay interaction
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous SQLite queries on main thread | Minimal | 0 | Low but blocks JS execution | [X] Bad |
| Asynchronous SQLite queries or worker threads | Minimal | 0 | Low and non-blocking | [OK] Good |
import { DB } from "https://deno.land/x/sqlite/mod.ts";
const db = new DB();
db.query("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)");
db.query("INSERT INTO users (name) VALUES (?)", ["Alice"]);
const result = [...db.query("SELECT name FROM users")];
console.log(result);
db.close();import { DB } from "https://deno.land/x/sqlite/mod.ts";
const db = new DB("mydb.sqlite");
db.query("CREATE TABLE items (id INTEGER PRIMARY KEY, name TEXT)");
db.query("INSERT INTO items (name) VALUES (?)", ["Book"]);
// Missing db.close()import { DB } from "https://deno.land/x/sqlite/mod.ts";
const db = new DB();
// Which code below is correct?Pass the test and this pattern moves unknown