Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
| web:api:prisma-fastify [2026/03/04 10:46] – [4. Lancer la migration] jcheron | web:api:prisma-fastify [2026/05/04 14:17] (Version actuelle) – [6. Prisma Client] jcheron | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ====== API REST avec Fastify + Prisma ====== | ====== API REST avec Fastify + Prisma ====== | ||
| + | ====== Sommaire ====== | ||
| + | * [[web: | ||
| + | * [[web: | ||
| + | * [[web: | ||
| + | * [[web: | ||
| + | * [[web: | ||
| + | * [[web: | ||
| ===== Partie 1 ===== | ===== Partie 1 ===== | ||
| Ligne 130: | Ligne 137: | ||
| ==== 4.b Configuration Prisma avec postgres ==== | ==== 4.b Configuration Prisma avec postgres ==== | ||
| + | |||
| + | <sxh bash> | ||
| + | npm install @prisma/ | ||
| + | npm install -D @types/pg | ||
| + | </ | ||
| Fichier `.env` : | Fichier `.env` : | ||
| Ligne 180: | Ligne 192: | ||
| <sxh ts> | <sxh ts> | ||
| - | import { PrismaClient | + | import " |
| + | import { PrismaPg | ||
| + | import { PrismaClient } from " | ||
| - | export | + | const connectionString = `${process.env.DATABASE_URL}`; |
| + | const adapter = new PrismaPg({ connectionString }); | ||
| + | const prisma = new PrismaClient({ adapter }); | ||
| + | export { prisma }; | ||
| </ | </ | ||
| - | ----- | ||
| ==== 7. Serveur + Routes simples ==== | ==== 7. Serveur + Routes simples ==== | ||
| Ligne 229: | Ligne 245: | ||
| * GET http:// | * GET http:// | ||
| * POST http:// | * POST http:// | ||
| + | |||
| + | |||
| + | <button type=" | ||