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, 07:15 UTC
| 1 | import * as Cloudflare from "@alchemy.run/cloudflare"; |
| 2 | import * as Neon from "@alchemy.run/neon"; |
| 3 | import * as Postgres from "@alchemy.run/sql/Postgres"; |
| 4 | import { Stack } from "alchemy/Stack"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as Layer from "effect/Layer"; |
| 7 | import * as SqlClient from "effect/sql/SqlClient"; |
| 8 | |
| 9 | // #region show |
| 10 | /** The Database module's interface: a SQL client. */ |
| 11 | export const Database = SqlClient.SqlClient; |
| 12 | |
| 13 | export const DatabaseLive = Layer.unwrap( |
| 14 | Effect.gen(function* () { |
| 15 | // #region stage |
| 16 | const { stage } = yield* Stack; |
| 17 | // #endregion stage |
| 18 | // #region db |
| 19 | const db = stage.startsWith("pr-") |
| 20 | ? yield* Neon.Branch("Db", { |
| 21 | project: yield* Neon.Project.ref("Db", { stage: "staging" }), |
| 22 | }) |
| 23 | : yield* Neon.Project("Db", { migrations: "./migrations" }); |
| 24 | // #endregion db |
| 25 | const pool = yield* Cloudflare.Hyperdrive.Connection("Pool", { origin: db.origin }); |
| 26 | const connection = yield* Cloudflare.Hyperdrive.Connect(pool); |
| 27 | return Postgres.PostgresLayer({ url: connection.connectionString }); |
| 28 | }), |
| 29 | ) /*hide*/ |
| 30 | .pipe(Layer.provide(Cloudflare.Hyperdrive.ConnectBinding)); /*end*/ |
| 31 | // #endregion show |