@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 38 lines 1.41 KB
Raw
1 import * as Drizzle from "@alchemy.run/drizzle/Postgres";
2 import { ConnectPostgres } from "@alchemy.run/railway/ConnectPostgres";
3 import { ConnectPostgresHttp } from "@alchemy.run/railway/ConnectPostgresHttp";
4 import { Function } from "@alchemy.run/railway/Function";
5 import * as Effect from "effect/Effect";
6 import * as HttpServerResponse from "effect/http/HttpServerResponse";
7 import { Db } from "./postgres-shared.ts";
8 import { Partition, Site } from "./suite-env.ts";
9
10 export { Db, Site };
11
12 /**
13 * Effect-native canvas Function that binds {@link Db} via
14 * {@link ConnectPostgres} and answers SELECT 1. Overflows Railway's 96KB
15 * encoded start command (`FunctionTooLarge`) — live HTTP coverage uses
16 * the async fixture in `async-postgres-fn.ts` instead.
17 */
18 export default class PostgresFn extends Function<PostgresFn>()(
19 "PostgresFn",
20 {
21 project: Site,
22 environment: Partition,
23 main: import.meta.url,
24 build: { install: ["drizzle-orm"] },
25 },
26 Effect.gen(function* () {
27 const conn = yield* ConnectPostgres(Db);
28 const db = yield* Drizzle.Postgres(conn.connectionString);
29 return {
30 fetch: db.execute("select 1 as ok", "objects").pipe(
31 Effect.flatMap((rows) => HttpServerResponse.json({ rows })),
32 Effect.catch((error) =>
33 HttpServerResponse.json({ ok: false, error: String(error) }, { status: 500 }),
34 ),
35 ),
36 };
37 }).pipe(Effect.provide(ConnectPostgresHttp)),
38 ) {}