1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/** @jsxImportSource https://esm.sh/hono@3.9.2/jsx **/
import { sqlite } from "https://esm.town/v/std/sqlite";
import { css } from "https://esm.town/v/stevekrouse/sqlite_admin_css";
export async function sqlite_admin_table(name: string) {
if (!name.match(/^[A-Za-z_][A-Za-z0-9_]*$/)) return <>Invalid table name</>;
let data = await sqlite.execute(`SELECT * FROM ${name}`);
return (
<div>
<h1>{name}</h1>
<style>{css}</style>
<table>
<tr>{data.columns.map(c => <th>{c}</th>)}</tr>
<tbody>
{data.rows.map(r => (
<tr>
{r.map(d => <td>{d?.toString ? d.toString() : JSON.stringify(d)}</td>)}
</tr>
))}
</tbody>
</table>
</div>
);
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
December 7, 2023