Luca Del Puppo - Senior Software Engineer
Luca Del Puppo
Love sport: running, hiking
Love animals
Control
Productivity
Orm
Plain SQL
SQL Builder
Prisma
Healty Constraint
Hey Bro!
Could you talk about interesting stuff?
Image by catalyststuff on Freepik
$ npm install prisma
npx prisma init --datasource-provider PostgreSQL
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
N.B. Multiple Files is not supported yet
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Ingredient {
id Int @id @default(autoincrement())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
pizzaIngredients PizzaIngredient[]
@@map("INGREDIENTS")
}
model PizzaIngredient {
ingredientId Int
pizzaId Int
ingredient Ingredient @relation(fields: [ingredientId], references: [id])
pizza Pizza @relation(fields: [pizzaId], references: [id])
@@id([pizzaId, ingredientId])
@@map("PIZZA_INGREDIENTS")
}
$ npx prisma generate
export type Ingredient = {
id: number
name: string
createdAt: Date
updatedAt: Date
}
$ npm install @prisma/client
const prisma = new PrismaClient();
await prisma.$connect();
const pizza = await prisma.pizza.findUnique({
where: {
id: id,
},
include: {
pizzaIngredients: {
include: {
ingredient: true,
},
},
},
});
Image by catalyststuff on Freepik
SQL\Prisma | Single | Multiple |
---|---|---|
Insert | create | createMany |
Update | update | updateMany |
Delete | delete | deleteMany |
Select | findUnique/ findFirst |
findMany |
Insert/ Update |
upsert |
Image by catalyststuff on Freepik
Image by catalyststuff on Freepik
Prisma Schema
Prisma CLI
Database
1. update
2. prisma migrate dev
3. read schema
4. database schema
5. generate migration
6. update database
Image by catalyststuff on Freepik
Prisma Schema
Prisma CLI
Database
2. prisma db pull
1. Change database schema (SQL)
3. read schema
4. database schema
5. Update
prisma db push
)Prisma exposes us a command for seeding the db
--skip-seed
allows skipping$ npx prisma migrate deploy
N.B. Use a CI/CD flow for your deployment
Image by catalyststuff on Freepik
Image by catalyststuff on Freepik
Image by catalyststuff on Freepik
Image by catalyststuff on Freepik
@puppo92
Luca Del Puppo
Puppo_92
@puppo