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
| 1 | # @alchemy.run/neon |
| 2 | |
| 3 | Neon for [Alchemy](https://alchemy.run). Declare Postgres projects and branches, Functions, object storage, Auth, and websites in the same TypeScript program as the code that uses them. |
| 4 | |
| 5 | ```sh |
| 6 | npm install alchemy @alchemy.run/neon @alchemy.run/sql effect |
| 7 | ``` |
| 8 | |
| 9 | A Neon Function on its own branch, with migrations applied on deploy: |
| 10 | |
| 11 | ```typescript |
| 12 | // src/api.ts |
| 13 | import * as Neon from "@alchemy.run/neon"; |
| 14 | import * as SQL from "@alchemy.run/sql/Postgres"; |
| 15 | import * as Effect from "effect/Effect"; |
| 16 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 17 | |
| 18 | export const Branch = Effect.gen(function* () { |
| 19 | const project = yield* Neon.Project("Project", { region: "aws-us-east-2" }); |
| 20 | return yield* Neon.Branch("Main", { project, migrations: "./migrations" }); |
| 21 | }); |
| 22 | |
| 23 | export default class Api extends Neon.Function<Api>()( |
| 24 | "Api", |
| 25 | Effect.gen(function* () { |
| 26 | return { branch: yield* Branch, main: import.meta.url }; |
| 27 | }), |
| 28 | Effect.gen(function* () { |
| 29 | const db = yield* Neon.Connect(yield* Branch); |
| 30 | const sql = yield* SQL.Postgres({ url: db.connectionString }); |
| 31 | |
| 32 | return { |
| 33 | fetch: Effect.gen(function* () { |
| 34 | const notes = yield* sql`SELECT * FROM notes`; |
| 35 | return yield* HttpServerResponse.json(notes); |
| 36 | }).pipe(Effect.orDie), |
| 37 | }; |
| 38 | }).pipe(Effect.provide(Neon.ConnectHttp)), |
| 39 | ) {} |
| 40 | ``` |
| 41 | |
| 42 | The Stack deploys it: |
| 43 | |
| 44 | ```typescript |
| 45 | // alchemy.run.ts |
| 46 | import * as Alchemy from "alchemy"; |
| 47 | import * as Neon from "@alchemy.run/neon"; |
| 48 | import * as Effect from "effect/Effect"; |
| 49 | import Api from "./src/api.ts"; |
| 50 | |
| 51 | export default Alchemy.Stack( |
| 52 | "MyApp", |
| 53 | { |
| 54 | providers: Neon.providers(), |
| 55 | state: Alchemy.localState(), |
| 56 | }, |
| 57 | Effect.gen(function* () { |
| 58 | const api = yield* Api; |
| 59 | return { url: api.url }; |
| 60 | }), |
| 61 | ); |
| 62 | ``` |
| 63 | |
| 64 | ## Learn more |
| 65 | |
| 66 | - [Neon on alchemy.run](https://alchemy.run/neon) |
| 67 | - [Setup](https://alchemy.run/neon/setup) |
| 68 | - [Tutorial](https://alchemy.run/neon/tutorial) |
| 69 | - [API reference](https://alchemy.run/providers) |