SlideShare una empresa de Scribd logo
Luca Del Puppo - Senior Software Engineer
Prisma the ORM that node was waiting for
Luca Del Puppo
Senior Software Engineer
Javascript Enthusiastic
Typescript Lover
“Youtuber”
“Writer”
Love sport: running, hiking
Love animals
Agenda
. What is it?
. CLI
. Data Modeling
. Generation
. Client
. Migration
. Deploy
. Conclusion
What is it?
Prisma is an open source next-generation ORM.
(Node eco-system)
Prisma Client
Auto-generated and type-safe query builder for Node.js & TypeScript
Prisma Migrate
Migration system
Prisma Studio
GUI to view and edit data in your database
Control
Productivity
Orm
Plain SQL
SQL Builder
Prisma
Healty Constraint
Providers
PostgreSQL
MySQL
SQLite
Microsoft SQL Server
MongoDB
CockroachDB
Hey Bro!
Could you talk about
interesting stu ?
Image by on
catalyststu Freepik
CLI
Install CLI
Create Project
Prisma File
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
1
2
3
4
5
6
7
8
CLI commands
init
generate
migrate
Data Modelling
Schema
One le (schema.prisma)
Data sources
Generators
Data model de nition
Syntax - PSL (Prisma Schema Language)
N.B. Multiple Files is not supported yet
Generator & DataSource
generator client {
provider = "prisma-client-js"
}
1
2
3
4
datasource db {
5
provider = "postgresql"
6
url = env("DATABASE_URL")
7
}
8
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
1
provider = "prisma-client-js"
2
}
3
4
5
6
7
8
Models
model Ingredient {
1
id Int @id @default(autoincrement())
2
name String
3
createdAt DateTime @default(now())
4
updatedAt DateTime @updatedAt
5
pizzaIngredients PizzaIngredient[]
6
7
@@map("INGREDIENTS")
8
}
9
id Int @id @default(autoincrement())
model Ingredient {
1
2
name String
3
createdAt DateTime @default(now())
4
updatedAt DateTime @updatedAt
5
pizzaIngredients PizzaIngredient[]
6
7
@@map("INGREDIENTS")
8
}
9
createdAt DateTime @default(now())
model Ingredient {
1
id Int @id @default(autoincrement())
2
name String
3
4
updatedAt DateTime @updatedAt
5
pizzaIngredients PizzaIngredient[]
6
7
@@map("INGREDIENTS")
8
}
9
updatedAt DateTime @updatedAt
model Ingredient {
1
id Int @id @default(autoincrement())
2
name String
3
createdAt DateTime @default(now())
4
5
pizzaIngredients PizzaIngredient[]
6
7
@@map("INGREDIENTS")
8
}
9
@@map("INGREDIENTS")
model Ingredient {
1
id Int @id @default(autoincrement())
2
name String
3
createdAt DateTime @default(now())
4
updatedAt DateTime @updatedAt
5
pizzaIngredients PizzaIngredient[]
6
7
8
}
9
model Ingredient {
id Int @id @default(autoincrement())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
pizzaIngredients PizzaIngredient[]
@@map("INGREDIENTS")
}
1
2
3
4
5
6
7
8
9
Relations
ingredientId Int
ingredient Ingredient @relation(fields: [ingredientId], references: [id])
model PizzaIngredient {
1
2
pizzaId Int
3
4
pizza Pizza @relation(fields: [pizzaId], references: [id])
5
6
@@id([pizzaId, ingredientId])
7
8
@@map("PIZZA_INGREDIENTS")
9
}
10
pizzaId Int
pizza Pizza @relation(fields: [pizzaId], references: [id])
model PizzaIngredient {
1
ingredientId Int
2
3
ingredient Ingredient @relation(fields: [ingredientId], references: [id])
4
5
6
@@id([pizzaId, ingredientId])
7
8
@@map("PIZZA_INGREDIENTS")
9
}
10
@@id([pizzaId, ingredientId])
model PizzaIngredient {
1
ingredientId Int
2
pizzaId Int
3
ingredient Ingredient @relation(fields: [ingredientId], references: [id])
4
pizza Pizza @relation(fields: [pizzaId], references: [id])
5
6
7
8
@@map("PIZZA_INGREDIENTS")
9
}
10
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")
}
1
2
3
4
5
6
7
8
9
10
Generation
Generation
What does it generate?
Models
Convert Models to Typescript Types
Client
Query Models (type safe)
Constraint to build where clause
Constraint to build select
Constraint to build insert/update/delete with relation
Generated Type
export type Ingredient = {
id: number
name: string
createdAt: Date
updatedAt: Date
}
1
2
3
4
5
6
Client
Installation
What does it generate?
const prisma = new PrismaClient();
1
await prisma.$connect();
2
3
const pizza = await prisma.pizza.findUnique({
4
where: {
5
id: id,
6
},
7
include: {
8
pizzaIngredients: {
9
include: {
10
ingredient: true,
11
},
12
},
13
},
14
});
15
await prisma.$connect();
const prisma = new PrismaClient();
1
2
3
const pizza = await prisma.pizza.findUnique({
4
where: {
5
id: id,
6
},
7
include: {
8
pizzaIngredients: {
9
include: {
10
ingredient: true,
11
},
12
},
13
},
14
});
15
const pizza = await prisma.pizza.findUnique({
where: {
id: id,
},
include: {
pizzaIngredients: {
include: {
ingredient: true,
},
},
},
});
const prisma = new PrismaClient();
1
await prisma.$connect();
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const prisma = new PrismaClient();
await prisma.$connect();
const pizza = await prisma.pizza.findUnique({
where: {
id: id,
},
include: {
pizzaIngredients: {
include: {
ingredient: true,
},
},
},
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Image by on
catalyststu Freepik
Crud
SQLPrisma Single Multiple
Insert create createMany
Update update updateMany
Delete delete deleteMany
Select ndUnique/
ndFirst
ndMany
Insert/
Update
upsert
Image by on
catalyststu Freepik
Aggregation
Aggregate
Count
GroupBy
One for each model
Migration
Image by on
catalyststu Freepik
Prisma Schema Prisma CLI Database
1. update
2. prisma migrate dev
3. read schema
4. database schema
5. generate migration
6. update database
Migration ow
Image by on
catalyststu Freepik
Prisma Schema
Prisma CLI Database
2. prisma db pull
Introspection ow
1. Change database schema (SQL)
3. read schema
4. database schema
5. Update
Limitations
MongoDb is not supported (use prisma db push)
Switch DB Provider is not supported
Seeding
Prisma exposes us a command for seeding the db
It runs on
prisma migrate dev
prisma migrate reset
manually
It can be written in typescript, go, sql…
--skip-seed allows skipping
Deploy
N.B. Use a CI/CD ow for your deployment
Demo
Image by on
catalyststu Freepik
Conclusion
Cons
Newby
Don’t manage multiple provider concurrency
Splitting schema not implemented out-of-the-box (prisma-
aurora)
Pros
Wonderful developer experience
Type safe queries
Migrations
Custom queries
Active Community
Awesome documentation
Core team active in Github and Slack
Slides
Image by on
catalyststu Freepik
Prisma Series
Image by on
catalyststu Freepik
We are hiring
Image by on
catalyststu Freepik
Luca Del Puppo
@puppo92
Luca Del Puppo
Puppo_92
@puppo

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architecture
 
PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UX
 
Client-side JavaScript
Client-side JavaScriptClient-side JavaScript
Client-side JavaScript
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass Slides
 
What is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaWhat is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | Edureka
 
Object Relational Mapping in PHP
Object Relational Mapping in PHPObject Relational Mapping in PHP
Object Relational Mapping in PHP
 
Design patterns in PHP
Design patterns in PHPDesign patterns in PHP
Design patterns in PHP
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Flask – Python
Flask – PythonFlask – Python
Flask – Python
 
JDBC
JDBCJDBC
JDBC
 
ADP - Chapter 2 Exploring the java Servlet Technology
ADP - Chapter 2 Exploring the java Servlet TechnologyADP - Chapter 2 Exploring the java Servlet Technology
ADP - Chapter 2 Exploring the java Servlet Technology
 
Lambda and Stream Master class - part 1
Lambda and Stream Master class - part 1Lambda and Stream Master class - part 1
Lambda and Stream Master class - part 1
 
Javascript
JavascriptJavascript
Javascript
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
 
Cryptography 101 for Java Developers - JavaZone2019
Cryptography 101 for Java Developers - JavaZone2019Cryptography 101 for Java Developers - JavaZone2019
Cryptography 101 for Java Developers - JavaZone2019
 
RESTful API 제대로 만들기
RESTful API 제대로 만들기RESTful API 제대로 만들기
RESTful API 제대로 만들기
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 

Similar a Prisma the ORM that node was waiting for

A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
DataLeader.io
 
Making Things Work Together
Making Things Work TogetherMaking Things Work Together
Making Things Work Together
Subbu Allamaraju
 

Similar a Prisma the ORM that node was waiting for (20)

SPKonferenz 2017 - Introducing SDKs for Microsoft Graph
SPKonferenz 2017 - Introducing SDKs for Microsoft GraphSPKonferenz 2017 - Introducing SDKs for Microsoft Graph
SPKonferenz 2017 - Introducing SDKs for Microsoft Graph
 
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
 
SharePoint Saturday Belgium 2018 - APIs, APIs everywhere!
SharePoint Saturday Belgium 2018 - APIs, APIs everywhere!SharePoint Saturday Belgium 2018 - APIs, APIs everywhere!
SharePoint Saturday Belgium 2018 - APIs, APIs everywhere!
 
APIs, APIs Everywhere!
APIs, APIs Everywhere!APIs, APIs Everywhere!
APIs, APIs Everywhere!
 
SharePoint Saturday Chicago - Everything your need to know about the Microsof...
SharePoint Saturday Chicago - Everything your need to know about the Microsof...SharePoint Saturday Chicago - Everything your need to know about the Microsof...
SharePoint Saturday Chicago - Everything your need to know about the Microsof...
 
Making Things Work Together
Making Things Work TogetherMaking Things Work Together
Making Things Work Together
 
SharePoint Conference 2018 - APIs, APIs everywhere!
SharePoint Conference 2018 - APIs, APIs everywhere!SharePoint Conference 2018 - APIs, APIs everywhere!
SharePoint Conference 2018 - APIs, APIs everywhere!
 
Forge - DevCon 2016: Introduction to Forge 3D Print API Through Sample Applic...
Forge - DevCon 2016: Introduction to Forge 3D Print API Through Sample Applic...Forge - DevCon 2016: Introduction to Forge 3D Print API Through Sample Applic...
Forge - DevCon 2016: Introduction to Forge 3D Print API Through Sample Applic...
 
SharePoint Conference 2018 - Build an intelligent application by connecting i...
SharePoint Conference 2018 - Build an intelligent application by connecting i...SharePoint Conference 2018 - Build an intelligent application by connecting i...
SharePoint Conference 2018 - Build an intelligent application by connecting i...
 
Implementation of GUI Framework part3
Implementation of GUI Framework part3Implementation of GUI Framework part3
Implementation of GUI Framework part3
 
ql.io at NodePDX
ql.io at NodePDXql.io at NodePDX
ql.io at NodePDX
 
MongoDB.local Atlanta: Introduction to Serverless MongoDB
MongoDB.local Atlanta: Introduction to Serverless MongoDBMongoDB.local Atlanta: Introduction to Serverless MongoDB
MongoDB.local Atlanta: Introduction to Serverless MongoDB
 
Silverlight 5 whats new overview
Silverlight 5 whats new overviewSilverlight 5 whats new overview
Silverlight 5 whats new overview
 
SharePoint 2010 Client Object Model
SharePoint 2010 Client Object ModelSharePoint 2010 Client Object Model
SharePoint 2010 Client Object Model
 
Frontend APIs powering fast paced product iterations
Frontend APIs powering fast paced product iterationsFrontend APIs powering fast paced product iterations
Frontend APIs powering fast paced product iterations
 
Soap Toolkit Dcphp
Soap Toolkit DcphpSoap Toolkit Dcphp
Soap Toolkit Dcphp
 
Apache Pinot Meetup Sept02, 2020
Apache Pinot Meetup Sept02, 2020Apache Pinot Meetup Sept02, 2020
Apache Pinot Meetup Sept02, 2020
 
Evolving your Data Access with MongoDB Stitch - Drew Di Palma
Evolving your Data Access with MongoDB Stitch - Drew Di PalmaEvolving your Data Access with MongoDB Stitch - Drew Di Palma
Evolving your Data Access with MongoDB Stitch - Drew Di Palma
 
Microsoft Graph: Connect to essential data every app needs
Microsoft Graph: Connect to essential data every app needsMicrosoft Graph: Connect to essential data every app needs
Microsoft Graph: Connect to essential data every app needs
 
Microsoft Graph: Connect to essential data every app needs
Microsoft Graph: Connect to essential data every app needsMicrosoft Graph: Connect to essential data every app needs
Microsoft Graph: Connect to essential data every app needs
 

Más de Commit University

Más de Commit University (20)

Alla scoperta dei Vector Database e dei RAG
Alla scoperta dei Vector Database e dei RAGAlla scoperta dei Vector Database e dei RAG
Alla scoperta dei Vector Database e dei RAG
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
Breaking REST Chains_ A Fastify & Mercurius Pathway to GraphQL Glory.pdf
Breaking REST Chains_ A Fastify & Mercurius Pathway to GraphQL Glory.pdfBreaking REST Chains_ A Fastify & Mercurius Pathway to GraphQL Glory.pdf
Breaking REST Chains_ A Fastify & Mercurius Pathway to GraphQL Glory.pdf
 
Accelerating API Development: A Pit Stop with Gin-Gonic in Golang-Slide.pdf
Accelerating API Development: A Pit Stop with Gin-Gonic in Golang-Slide.pdfAccelerating API Development: A Pit Stop with Gin-Gonic in Golang-Slide.pdf
Accelerating API Development: A Pit Stop with Gin-Gonic in Golang-Slide.pdf
 
Slide-10years.pdf
Slide-10years.pdfSlide-10years.pdf
Slide-10years.pdf
 
Collaborazione, Decisionalità e Gestione della Complessità nel Tempo: cosa ...
Collaborazione, Decisionalità e Gestione della Complessità nel Tempo: cosa ...Collaborazione, Decisionalità e Gestione della Complessità nel Tempo: cosa ...
Collaborazione, Decisionalità e Gestione della Complessità nel Tempo: cosa ...
 
Vue.js slots.pdf
Vue.js slots.pdfVue.js slots.pdf
Vue.js slots.pdf
 
Commit - Qwik il framework che ti stupirà.pptx
Commit - Qwik il framework che ti stupirà.pptxCommit - Qwik il framework che ti stupirà.pptx
Commit - Qwik il framework che ti stupirà.pptx
 
Sviluppare da zero una Angular Web App per la PA
Sviluppare da zero una Angular Web App per la PASviluppare da zero una Angular Web App per la PA
Sviluppare da zero una Angular Web App per la PA
 
Backstage l'Internal Developer Portal Open Source per una migliore Developer ...
Backstage l'Internal Developer Portal Open Source per una migliore Developer ...Backstage l'Internal Developer Portal Open Source per una migliore Developer ...
Backstage l'Internal Developer Portal Open Source per una migliore Developer ...
 
Decision-making for Software Development Teams - Commit University
Decision-making for Software Development Teams - Commit UniversityDecision-making for Software Development Teams - Commit University
Decision-making for Software Development Teams - Commit University
 
Component Design Pattern nei Game Engine.pdf
Component Design Pattern nei Game Engine.pdfComponent Design Pattern nei Game Engine.pdf
Component Design Pattern nei Game Engine.pdf
 
Un viaggio alla scoperta dei Language Models e dell’intelligenza artificiale ...
Un viaggio alla scoperta dei Language Models e dell’intelligenza artificiale ...Un viaggio alla scoperta dei Language Models e dell’intelligenza artificiale ...
Un viaggio alla scoperta dei Language Models e dell’intelligenza artificiale ...
 
Prototipazione Low-Code con AWS Step Functions
Prototipazione Low-Code con AWS Step FunctionsPrototipazione Low-Code con AWS Step Functions
Prototipazione Low-Code con AWS Step Functions
 
KMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and SwiftKMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and Swift
 
Da Vuex a Pinia: come fare la migrazione
Da Vuex a Pinia: come fare la migrazioneDa Vuex a Pinia: come fare la migrazione
Da Vuex a Pinia: come fare la migrazione
 
Orchestrare Micro-frontend con micro-lc
Orchestrare Micro-frontend con micro-lcOrchestrare Micro-frontend con micro-lc
Orchestrare Micro-frontend con micro-lc
 
Fastify has defeated Lagacy-Code
Fastify has defeated Lagacy-CodeFastify has defeated Lagacy-Code
Fastify has defeated Lagacy-Code
 
SwiftUI vs UIKit
SwiftUI vs UIKitSwiftUI vs UIKit
SwiftUI vs UIKit
 

Último

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 

Último (20)

AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG Evaluation
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 

Prisma the ORM that node was waiting for

  • 1. Luca Del Puppo - Senior Software Engineer Prisma the ORM that node was waiting for
  • 2. Luca Del Puppo Senior Software Engineer Javascript Enthusiastic Typescript Lover “Youtuber” “Writer” Love sport: running, hiking Love animals
  • 3. Agenda . What is it? . CLI . Data Modeling . Generation . Client . Migration . Deploy . Conclusion
  • 5. Prisma is an open source next-generation ORM. (Node eco-system)
  • 6. Prisma Client Auto-generated and type-safe query builder for Node.js & TypeScript
  • 8. Prisma Studio GUI to view and edit data in your database
  • 11. Hey Bro! Could you talk about interesting stu ? Image by on catalyststu Freepik
  • 12. CLI
  • 15. Prisma File generator client { provider = "prisma-client-js" } datasource db { provider = "postgresql" url = env("DATABASE_URL") } 1 2 3 4 5 6 7 8
  • 18. Schema One le (schema.prisma) Data sources Generators Data model de nition Syntax - PSL (Prisma Schema Language) N.B. Multiple Files is not supported yet
  • 19. Generator & DataSource generator client { provider = "prisma-client-js" } 1 2 3 4 datasource db { 5 provider = "postgresql" 6 url = env("DATABASE_URL") 7 } 8 datasource db { provider = "postgresql" url = env("DATABASE_URL") } generator client { 1 provider = "prisma-client-js" 2 } 3 4 5 6 7 8
  • 20. Models model Ingredient { 1 id Int @id @default(autoincrement()) 2 name String 3 createdAt DateTime @default(now()) 4 updatedAt DateTime @updatedAt 5 pizzaIngredients PizzaIngredient[] 6 7 @@map("INGREDIENTS") 8 } 9 id Int @id @default(autoincrement()) model Ingredient { 1 2 name String 3 createdAt DateTime @default(now()) 4 updatedAt DateTime @updatedAt 5 pizzaIngredients PizzaIngredient[] 6 7 @@map("INGREDIENTS") 8 } 9 createdAt DateTime @default(now()) model Ingredient { 1 id Int @id @default(autoincrement()) 2 name String 3 4 updatedAt DateTime @updatedAt 5 pizzaIngredients PizzaIngredient[] 6 7 @@map("INGREDIENTS") 8 } 9 updatedAt DateTime @updatedAt model Ingredient { 1 id Int @id @default(autoincrement()) 2 name String 3 createdAt DateTime @default(now()) 4 5 pizzaIngredients PizzaIngredient[] 6 7 @@map("INGREDIENTS") 8 } 9 @@map("INGREDIENTS") model Ingredient { 1 id Int @id @default(autoincrement()) 2 name String 3 createdAt DateTime @default(now()) 4 updatedAt DateTime @updatedAt 5 pizzaIngredients PizzaIngredient[] 6 7 8 } 9 model Ingredient { id Int @id @default(autoincrement()) name String createdAt DateTime @default(now()) updatedAt DateTime @updatedAt pizzaIngredients PizzaIngredient[] @@map("INGREDIENTS") } 1 2 3 4 5 6 7 8 9
  • 21. Relations ingredientId Int ingredient Ingredient @relation(fields: [ingredientId], references: [id]) model PizzaIngredient { 1 2 pizzaId Int 3 4 pizza Pizza @relation(fields: [pizzaId], references: [id]) 5 6 @@id([pizzaId, ingredientId]) 7 8 @@map("PIZZA_INGREDIENTS") 9 } 10 pizzaId Int pizza Pizza @relation(fields: [pizzaId], references: [id]) model PizzaIngredient { 1 ingredientId Int 2 3 ingredient Ingredient @relation(fields: [ingredientId], references: [id]) 4 5 6 @@id([pizzaId, ingredientId]) 7 8 @@map("PIZZA_INGREDIENTS") 9 } 10 @@id([pizzaId, ingredientId]) model PizzaIngredient { 1 ingredientId Int 2 pizzaId Int 3 ingredient Ingredient @relation(fields: [ingredientId], references: [id]) 4 pizza Pizza @relation(fields: [pizzaId], references: [id]) 5 6 7 8 @@map("PIZZA_INGREDIENTS") 9 } 10 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") } 1 2 3 4 5 6 7 8 9 10
  • 24.
  • 25. What does it generate? Models Convert Models to Typescript Types Client Query Models (type safe) Constraint to build where clause Constraint to build select Constraint to build insert/update/delete with relation
  • 26. Generated Type export type Ingredient = { id: number name: string createdAt: Date updatedAt: Date } 1 2 3 4 5 6
  • 29. What does it generate? const prisma = new PrismaClient(); 1 await prisma.$connect(); 2 3 const pizza = await prisma.pizza.findUnique({ 4 where: { 5 id: id, 6 }, 7 include: { 8 pizzaIngredients: { 9 include: { 10 ingredient: true, 11 }, 12 }, 13 }, 14 }); 15 await prisma.$connect(); const prisma = new PrismaClient(); 1 2 3 const pizza = await prisma.pizza.findUnique({ 4 where: { 5 id: id, 6 }, 7 include: { 8 pizzaIngredients: { 9 include: { 10 ingredient: true, 11 }, 12 }, 13 }, 14 }); 15 const pizza = await prisma.pizza.findUnique({ where: { id: id, }, include: { pizzaIngredients: { include: { ingredient: true, }, }, }, }); const prisma = new PrismaClient(); 1 await prisma.$connect(); 2 3 4 5 6 7 8 9 10 11 12 13 14 15 const prisma = new PrismaClient(); await prisma.$connect(); const pizza = await prisma.pizza.findUnique({ where: { id: id, }, include: { pizzaIngredients: { include: { ingredient: true, }, }, }, }); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  • 30. Image by on catalyststu Freepik Crud SQLPrisma Single Multiple Insert create createMany Update update updateMany Delete delete deleteMany Select ndUnique/ ndFirst ndMany Insert/ Update upsert
  • 31. Image by on catalyststu Freepik Aggregation Aggregate Count GroupBy
  • 32. One for each model
  • 34. Image by on catalyststu Freepik Prisma Schema Prisma CLI Database 1. update 2. prisma migrate dev 3. read schema 4. database schema 5. generate migration 6. update database Migration ow
  • 35. Image by on catalyststu Freepik Prisma Schema Prisma CLI Database 2. prisma db pull Introspection ow 1. Change database schema (SQL) 3. read schema 4. database schema 5. Update
  • 36. Limitations MongoDb is not supported (use prisma db push) Switch DB Provider is not supported
  • 37. Seeding Prisma exposes us a command for seeding the db It runs on prisma migrate dev prisma migrate reset manually It can be written in typescript, go, sql… --skip-seed allows skipping
  • 39. N.B. Use a CI/CD ow for your deployment
  • 42. Cons Newby Don’t manage multiple provider concurrency Splitting schema not implemented out-of-the-box (prisma- aurora)
  • 43. Pros Wonderful developer experience Type safe queries Migrations Custom queries Active Community Awesome documentation Core team active in Github and Slack
  • 45. Prisma Series Image by on catalyststu Freepik
  • 46. We are hiring Image by on catalyststu Freepik
  • 47. Luca Del Puppo @puppo92 Luca Del Puppo Puppo_92 @puppo