The best way to control Claude Code, Codex and more from any computer or phone
| 1 | # @alchemy.run/railway |
| 2 | |
| 3 | Railway for [Alchemy](https://alchemy.run). Run Effect programs as Railway Services, next to Postgres, MySQL, Redis, Mongo, volumes, and buckets, all in one TypeScript program. |
| 4 | |
| 5 | ```sh |
| 6 | npm install alchemy @alchemy.run/railway @alchemy.run/sql effect |
| 7 | ``` |
| 8 | |
| 9 | A Project with Postgres and a Service that queries it: |
| 10 | |
| 11 | ```typescript |
| 12 | // src/api.ts |
| 13 | import * as Railway from "@alchemy.run/railway"; |
| 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 Site = Railway.Project("Site"); |
| 19 | export const Db = Railway.Postgres("Db", { project: Site }); |
| 20 | |
| 21 | export default class Api extends Railway.Service<Api>()( |
| 22 | "Api", |
| 23 | { project: Site, main: import.meta.url, port: 3000 }, |
| 24 | Effect.gen(function* () { |
| 25 | const db = yield* Railway.ConnectPostgres(Db); |
| 26 | const sql = yield* SQL.Postgres({ url: db.connectionString }); |
| 27 | |
| 28 | return { |
| 29 | fetch: Effect.gen(function* () { |
| 30 | const users = yield* sql`SELECT * FROM users`; |
| 31 | return yield* HttpServerResponse.json(users); |
| 32 | }).pipe(Effect.orDie), |
| 33 | }; |
| 34 | }).pipe(Effect.provide(Railway.ConnectPostgresHttp)), |
| 35 | ) {} |
| 36 | ``` |
| 37 | |
| 38 | ```typescript |
| 39 | // alchemy.run.ts |
| 40 | import * as Alchemy from "alchemy"; |
| 41 | import * as Railway from "@alchemy.run/railway"; |
| 42 | import * as Effect from "effect/Effect"; |
| 43 | import Api from "./src/api.ts"; |
| 44 | |
| 45 | export default Alchemy.Stack( |
| 46 | "MyApp", |
| 47 | { |
| 48 | providers: Railway.providers(), |
| 49 | state: Alchemy.localState(), |
| 50 | }, |
| 51 | Effect.gen(function* () { |
| 52 | const api = yield* Api; |
| 53 | return { url: api.url }; |
| 54 | }), |
| 55 | ); |
| 56 | ``` |
| 57 | |
| 58 | ## Learn more |
| 59 | |
| 60 | - [Railway on alchemy.run](https://alchemy.run/railway) |
| 61 | - [Setup](https://alchemy.run/railway/setup) |
| 62 | - [Tutorial](https://alchemy.run/railway/tutorial/part-1) |
| 63 | - [API reference](https://alchemy.run/providers) |