@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 28 lines 1.3 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import * as D1 from "@alchemy.run/cloudflare/D1/SQL";
3 import * as Neon from "@alchemy.run/neon";
4 import * as Postgres from "@alchemy.run/sql/Postgres";
5 import * as Effect from "effect/Effect";
6 import * as Layer from "effect/Layer";
7
8 /** SQLite on Cloudflare D1. */
9 export const D1Storage = Layer.unwrap(
10 Effect.gen(function* () {
11 const db = yield* Cloudflare.D1.Database("Db", { migrations: "./migrations" });
12 return D1.D1Layer(yield* Cloudflare.D1.QueryDatabase(db));
13 }),
14 ).pipe(Layer.provide(Cloudflare.D1.QueryDatabaseBinding));
15
16 /** Postgres on Neon, pooled at the edge by Hyperdrive. Same migrations. */
17 export const NeonStorage = Layer.unwrap(
18 Effect.gen(function* () {
19 const db = yield* Neon.Project("Postgres", { migrations: "./migrations" });
20 const pool = yield* Cloudflare.Hyperdrive.Connection("Pool", {
21 origin: db.origin, // deployed: Hyperdrive pools Neon's direct endpoint
22 dev: db.pooledOrigin, // alchemy dev: straight to Neon's own pooler
23 caching: { disabled: true }, // links must be read-after-write
24 });
25 const connection = yield* Cloudflare.Hyperdrive.Connect(pool);
26 return Postgres.PostgresLayer({ url: connection.connectionString });
27 }),
28 ).pipe(Layer.provide(Cloudflare.Hyperdrive.ConnectBinding));