t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/Railway/fixtures/postgres-fn.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

41 lines
1.4 KiB
TypeScript

import * as Drizzle from "@/Drizzle/Postgres.ts";
import { ConnectPostgres } from "@/Railway/ConnectPostgres.ts";
import { ConnectPostgresHttp } from "@/Railway/ConnectPostgresHttp.ts";
import { Function } from "@/Railway/Function.ts";
import * as Effect from "effect/Effect";
import * as HttpServerResponse from "effect/http/HttpServerResponse";
import { Partition, Site } from "./suite-env.ts";
import { Db } from "./postgres-shared.ts";
export { Db, Site };
/**
* Effect-native canvas Function that binds {@link Db} via
* {@link ConnectPostgres} and answers SELECT 1. Overflows Railway's 96KB
* encoded start command (`FunctionTooLarge`) — live HTTP coverage uses
* the async fixture in `async-postgres-fn.ts` instead.
*/
export default class PostgresFn extends Function<PostgresFn>()(
"PostgresFn",
{
project: Site,
environment: Partition,
main: import.meta.url,
build: { install: ["pg", "drizzle-orm"] },
},
Effect.gen(function* () {
const conn = yield* ConnectPostgres(Db);
const db = yield* Drizzle.Postgres(conn.connectionString);
return {
fetch: db.execute("select 1 as ok", "objects").pipe(
Effect.flatMap((rows) => HttpServerResponse.json({ rows })),
Effect.catch((error) =>
HttpServerResponse.json(
{ ok: false, error: String(error) },
{ status: 500 },
),
),
),
};
}).pipe(Effect.provide(ConnectPostgresHttp)),
) {}