The best way to control Claude Code, Codex and more from any computer or phone
| 1 | # @alchemy.run/prisma |
| 2 | |
| 3 | Prisma Postgres and Prisma Compute for [Alchemy](https://alchemy.run). Declare projects, databases, connections, and deployed apps in the same TypeScript program as the code that uses them, with a zero-config local database in `alchemy dev`. |
| 4 | |
| 5 | ```sh |
| 6 | npm install alchemy @alchemy.run/prisma @alchemy.run/sql effect |
| 7 | ``` |
| 8 | |
| 9 | A Postgres database and an app on Prisma Compute that queries it: |
| 10 | |
| 11 | ```typescript |
| 12 | // src/api.ts |
| 13 | import * as Prisma from "@alchemy.run/prisma"; |
| 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 Project = Prisma.Project("Project", { createDatabase: false }); |
| 19 | |
| 20 | export const Connection = Effect.gen(function* () { |
| 21 | const database = yield* Prisma.Postgres("Db", { project: yield* Project }); |
| 22 | return yield* Prisma.Connection("Api", { database }); |
| 23 | }); |
| 24 | |
| 25 | export default class Api extends Prisma.Compute<Api>()( |
| 26 | "Api", |
| 27 | Effect.gen(function* () { |
| 28 | return { project: yield* Project, main: import.meta.filename, port: 3000 }; |
| 29 | }), |
| 30 | Effect.gen(function* () { |
| 31 | const db = yield* Prisma.Connect(yield* Connection); |
| 32 | const sql = yield* SQL.Postgres({ url: db.databaseUrl }); |
| 33 | |
| 34 | return { |
| 35 | fetch: Effect.gen(function* () { |
| 36 | const users = yield* sql`SELECT * FROM users`; |
| 37 | return yield* HttpServerResponse.json(users); |
| 38 | }).pipe(Effect.orDie), |
| 39 | }; |
| 40 | }).pipe(Effect.provide(Prisma.ConnectBinding)), |
| 41 | ) {} |
| 42 | ``` |
| 43 | |
| 44 | ```typescript |
| 45 | // alchemy.run.ts |
| 46 | import * as Alchemy from "alchemy"; |
| 47 | import * as Prisma from "@alchemy.run/prisma"; |
| 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: Prisma.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 | - [Prisma on alchemy.run](https://alchemy.run/prisma) |
| 67 | - [Setup](https://alchemy.run/prisma/setup) |
| 68 | - [Tutorial](https://alchemy.run/prisma/tutorial/part-1) |
| 69 | - [Prisma ORM with Alchemy](https://alchemy.run/sql/prisma/postgres) |