Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

Query All Public Vals

Example: val town leaderboard

import { zip } from "https://esm.town/v/pomdtr/sql"; import { db } from "https://esm.town/v/sqlite/db"; const res = await db.execute("SELECT author_username, COUNT(*) AS val_count FROM vals GROUP BY author_username ORDER BY 2 DESC LIMIT 10"); console.table(zip(res));

87766bc40d912e65680d7452ef6946c03b95369fedac5c1fa4cf2f941252b4c7.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { InStatement } from "https://esm.town/v/std/sqlite";
import type { ResultSet } from "npm:@libsql/client";
async function execute(statement: InStatement): Promise<ResultSet> {
const resp = await fetch("https://sqlite-execute.web.val.run", {
method: "POST",
body: JSON.stringify({
args: [statement],
}),
});
if (!resp.ok) {
throw new Error(await resp.text());
}
return resp.json();
}
export const db = {
execute,
};
sqlite-db.web.val.run
March 11, 2024