The best way to control Claude Code, Codex and more from any computer or phone

main
md 43 lines 1.67 KB
Rendered Raw
1 # PSL-first Prisma and Effect
2
3 This example deploys the same Worker, Hyperdrive, and Neon application as
4 [the TypeScript-first example](../cloudflare-neon-prisma). Its authoritative schema
5 is `src/prisma/contract.psl`. There is no handwritten TypeScript contract.
6
7 `prisma.config.ts` registers `withEffect` on Prisma's ORM configuration. Generation
8 emits canonical `contract.json` and `contract.d.ts` plus a thin `makeDatabase`
9 factory and standalone Effect row schemas:
10
11 ```ts
12 import { makeDatabase } from "./prisma/generated/client.ts";
13 import { schemas } from "./prisma/generated/schemas.ts";
14
15 const db = yield* makeDatabase(connection.connectionString);
16 const users = yield* db.orm.public.User.all();
17 ```
18
19 `src/Api.ts` validates newly created rows through `schemas.public.User`. The schema
20 module can also be used without a database client. These are scalar database row
21 validators, not create inputs or public API definitions.
22
23 ## Run
24
25 From the repository root, install dependencies with `pnpm install`, then:
26
27 ```sh
28 cd examples/cloudflare-neon-prisma-psl
29 pnpm generate
30 pnpm exec tsc --noEmit
31 pnpm deploy
32 pnpm test
33 pnpm destroy
34 ```
35
36 Configure Alchemy's Cloudflare and Neon credentials first. The tests deploy real
37 resources and clean them up. Set `ALCHEMY_PROFILE=testing` when using that profile.
38 `deploy` and `dev` regenerate before loading the application. Generation itself
39 is offline; Prisma migration planning and application happen during deployment.
40
41 For source edits, run `pnpm generate:watch` alongside your development process.
42 Run generation before type checking and bundling in CI. Do not edit generated
43 files. This is Alchemy's Prisma 8 contract consumer, not a Prisma 7 generator block.