@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 24 lines 779 Bytes
Raw
1 import { Client } from "pg";
2 import type { PostgresFnEnv } from "./async-postgres-fn.ts";
3
4 /**
5 * Async (non-Effect) canvas Function. `DATABASE_URL` is a string env var
6 * declared on the Function (`env: { DATABASE_URL: db.connectionUri }`).
7 * `InferEnv` types `env.DATABASE_URL` as `string`.
8 */
9 export default {
10 async fetch(_request: Request, env: PostgresFnEnv): Promise<Response> {
11 const client = new Client({
12 connectionString: env.DATABASE_URL,
13 });
14 await client.connect();
15 try {
16 const result = await client.query("select 1 as ok");
17 return Response.json({ rows: result.rows });
18 } catch (error) {
19 return Response.json({ ok: false, error: String(error) }, { status: 500 });
20 } finally {
21 await client.end();
22 }
23 },
24 };