web:api:prisma-fastify

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

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 01:58] jcheronweb:api:prisma-fastify [2026/03/04 11:26] (Version actuelle) – [6. Prisma Client] jcheron
Ligne 69: Ligne 69:
 ----- -----
  
-==== 4. Configuration Prisma ====+ 
 +==== 2. Configuration Prisma avec SQLite ==== 
 + 
 +Modifier `prisma/schema.prisma` : 
 + 
 +<code prisma> 
 +datasource db { 
 +  provider = "sqlite" 
 +  url      = env("DATABASE_URL"
 +
 + 
 +generator client { 
 +  provider = "prisma-client-js" 
 +
 +</code> 
 + 
 +----- 
 + 
 +==== 3. Configuration du fichier .env ==== 
 + 
 +<code> 
 +DATABASE_URL="file:./dev.db" 
 +</code> 
 + 
 +Explication : 
 + 
 +  * Prisma va créer automatiquement un fichier `dev.db` 
 +  * Le fichier sera situé à la racine du projet 
 + 
 +----- 
 + 
 +==== 4. Lancer la migration ==== 
 + 
 +<sxh bash> 
 +npx prisma migrate dev --name init 
 +</sxh> 
 + 
 +Résultat : 
 + 
 +  * Fichier dev.db créé 
 +  * Tables générées 
 +  * Client Prisma généré 
 + 
 +Aucune base externe nécessaire. 
 + 
 +----- 
 + 
 +==== 4.a Structure projet avec SQLite ==== 
 + 
 +<code> 
 +fastify-prisma-api/ 
 + ├── prisma/ 
 + ├── src/ 
 + ├── dev.db 
 + ├── .env 
 + ├── package.json 
 +</code> 
 + 
 +----- 
 + 
 +==== 4.Configuration Prisma avec postgres ====
  
 Fichier `.env` : Fichier `.env` :
Ligne 79: Ligne 139:
 Modifier `prisma/schema.prisma` : Modifier `prisma/schema.prisma` :
  
-<sxh prisma>+<sxh ts>
 datasource db { datasource db {
   provider = "postgresql"   provider = "postgresql"
Ligne 120: Ligne 180:
  
 <sxh ts> <sxh ts>
-import { PrismaClient } from "@prisma/client"+import {PrismaClient} from "@prisma/client/extension";
  
 export const prisma = new PrismaClient() export const prisma = new PrismaClient()
  • web/api/prisma-fastify.1772585890.txt.gz
  • Dernière modification : il y a 32 heures
  • de jcheron