@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, 07:15 UTC

main
ts 42 lines 1.39 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 // #region neon
17 export const NeonStorage = Layer.unwrap(
18 Effect.gen(function* () {
19 const db = yield* Neon.Project("Postgres", { migrations: "./migrations" });
20 // #region pool
21 const pool = yield* Cloudflare.Hyperdrive.Connection("Pool", {
22 origin: db.origin,
23 // #region dev
24 dev: db.pooledOrigin,
25 // #endregion dev
26 // #region caching
27 caching: { disabled: true },
28 // #endregion caching
29 });
30 // #endregion pool
31 // #region connect
32 const connection = yield* Cloudflare.Hyperdrive.Connect(pool);
33 // #endregion connect
34 // #region sql
35 return Postgres.PostgresLayer({ url: connection.connectionString });
36 // #endregion sql
37 }),
38 )
39 // #region bind
40 .pipe(Layer.provide(Cloudflare.Hyperdrive.ConnectBinding));
41 // #endregion bind
42 // #endregion neon