Public: anyone can read this; the crew can change it.

A .sqlite file's table opens 100 rows at a time with next and previous links, never loading the whole table #13953

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/13935-a-sqlite-file-s-table-opens-100-rows-at → main 1 commit fork

  • Merged. scout/13935-a-sqlite-file-s-table-opens-100-rows-at was merged into main as 70f9cba.

Review

Sign in to review this change.
1 file changed +40 −0
test/render-sqlite-page.test.ts added +40
@@ -0,0 +1,40 @@
1 import { Database } from "bun:sqlite";
2 import { describe, expect, test } from "bun:test";
3 import { ROW_LIMIT, sqlite } from "../src/web/render/sqlite.ts";
4
5 function big(): Uint8Array {
6 const db = new Database(":memory:");
7 db.run("CREATE TABLE big (id INTEGER PRIMARY KEY, v TEXT)");
8 db.transaction(() => {
9 const ins = db.prepare("INSERT INTO big (v) VALUES (?)");
10 for (let i = 1; i <= 10_000; i++) ins.run(`row-${i}`);
11 })();
12 const bytes = db.serialize();
13 db.close();
14 return bytes;
15 }
16
17 const BODY = big();
18 const draw = (table: string, page?: number) =>
19 String(sqlite({ path: "a.db", size: BODY.length, body: BODY, media: "/m", download: "/d", pathHref: "/o/r/blob/main/a.db", table, ...(page ? { page } : {}) }).content);
20
21 describe("a 10,000-row table opens one page", () => {
22 test("page 1 and a middle page hold only their 100 rows, with the count and links", () => {
23 const one = draw("big");
24 expect(one.split("<tr>").length - 1).toBe(ROW_LIMIT + 1);
25 expect(one).toContain("rows 1–100 of 10,000");
26 expect(one).toContain("row-100<"); expect(one).not.toContain("row-101<");
27 expect(one).toContain("Next 100"); expect(one).not.toContain("Previous");
28 const mid = draw("big", 50);
29 expect(mid.split("<tr>").length - 1).toBe(ROW_LIMIT + 1);
30 expect(mid).toContain("rows 4,901–5,000 of 10,000");
31 expect(mid).toContain("row-4901<"); expect(mid).not.toContain("row-4900<"); expect(mid).not.toContain("row-5001<");
32 expect(mid).toContain("Previous 100"); expect(mid).toContain("page=49"); expect(mid).toContain("page=51");
33 expect(draw("big", 100)).not.toContain("Next 100");
34 });
35 test("a table name not in the file draws no rows", () => {
36 const h = draw('big"; DROP TABLE big; --');
37 expect(h).toContain("no table named");
38 expect(h).not.toContain("row-1<");
39 });
40 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs