1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { Database } from "https://esm.sh/duckdb-async";
export default async function server(request: Request): Promise<Response> {
const url = new URL(request.url);
const dataUrl = url.searchParams.get('url');
if (!dataUrl) {
return new Response('Please provide a URL parameter', { status: 400 });
}
try {
const db = await Database.create(':memory:');
await db.all('LOAD httpfs');
const result = await db.all(`SELECT * FROM '${dataUrl}' LIMIT 5`);
await db.close();
return new Response(JSON.stringify(result, null, 2), {
headers: { 'Content-Type': 'application/json' },
});
} catch (error) {
return new Response(`Error: ${error.message}`, { status: 500 });
}
}