35
36async function execute(statement: InStatement, args?: InArgs): Promise<ResultSet> {
37 const res = await fetch(`${API_URL}/v1/sqlite/execute`, {
38 method: "POST",
39 headers: {
50
51async function batch(statements: InStatement[], mode?: TransactionMode): Promise<ResultSet[]> {
52 const res = await fetch(`${API_URL}/v1/sqlite/batch`, {
53 method: "POST",
54 headers: {
182
183 try {
184 const response = await fetch("/", {
185 method: "POST",
186 body: JSON.stringify({
1async function createWorker(url: string) {
2 const workerScript = await fetch(url);
3 const workerURL = URL.createObjectURL(await workerScript.blob());
4 return new Worker(workerURL, { type: "module" });
24 : Math.floor((Date.now() - 2 * 24 * 60 * 60 * 1000) / 1000);
25
26 // Fetch and log tweets
27 const response = await socialDataSearch(`${query} since_time:${since}`);
28 console.log("Response from socialDataSearch:", response);
1import { fetch } from "https://esm.town/v/std/fetch"
2import { getDuckDB } from "https://esm.town/v/tmcw/getDuckDB"
3
4export const duckDbCsv = (async () => {
5 const db = await getDuckDB()
6 const r = await fetch(
7 "https://raw.githubusercontent.com/fivethirtyeight/data/master/san-andreas/earthquake_data.csv",
8 )
32
33 const imagePromises = variations.map(variation =>
34 fetch(`https://maxm-imggenurl.web.val.run/${encodeURIComponent(`${prompt} - ${variation}`)}`)
35 .then(res => {
36 if (!res.ok) throw new Error('Image generation failed');
1Fetches details about media files (images, video, audio, etc) using [Mediainfo.js](https://mediainfo.js.org/). e.g. codecs used, duration, file sizes, ID3 tags, etc. Check out https://jamiedubs-mediainfo.web.val.run/ for a little interactive example
2
3Beta! API response not 100% stable, I might move things around still. Especially this `summary` field idea
1import { fetch } from "https://esm.town/v/std/fetch";
2
3export let duckdbExample = await (async () => {
8 }
9 // For browser environments (keeping the original logic)
10 const workerScript = await fetch(url);
11 const workerURL = URL.createObjectURL(await workerScript.blob());
12 return new Worker(workerURL, { type: "module" });
1# DuckDB
2
3[DuckDB](https://duckdb.org/) works on Val Town, with only one small tweak! We're basically using DuckDB in the same way you'd use it with a browser - using the WASM package with its dependencies fetched from [jsdelivr](https://www.jsdelivr.com/).
4
5The only trick is to create the worker ourselves rather than using `duckdb.createWorker`. DuckDB's built-in createWorker method doesn't specify a worker type, which causes `type` to default to `classic`, and Deno (our runtime) doesn't support classic workers.
11
12 try {
13 const response = await fetch("/submit", {
14 method: "POST",
15 body: JSON.stringify({ deckText }),
56
57 useEffect(() => {
58 fetchCards();
59 }, []);
60
61 async function fetchCards() {
62 try {
63 const response = await fetch("/view");
64 if (!response.ok) {
65 throw new Error("Failed to fetch cards");
66 }
67 const data = await response.json();
124 const handleEditSave = async (id: number, field: string, newValue: string) => {
125 try {
126 const response = await fetch("/update", {
127 method: "POST",
128 body: JSON.stringify({ id, field, value: newValue }),
267 const [error, setError] = useState("");
268
269 const fetchRandomCard = async () => {
270 try {
271 const response = await fetch("/random");
272 if (!response.ok) {
273 throw new Error("Failed to fetch random card");
274 }
275 const data = await response.json();
284 <h1>🎲 Random Card</h1>
285 <button
286 onClick={fetchRandomCard}
287 style={{
288 backgroundColor: "#28a745",