Fireship · @fireship
Prisma in 100 Seconds
Uploaded January 26, 2022 · Length 2:34
Summary
prisma explained as an orm for modern app development with sql and nodejs
- prisma
- orm
- sql
- nodejs
- database
- relational database
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
prisma an open source tool that makes it
- 0:02
fun and safe to work with your database
- 0:04
the relational database is ancient
- 0:06
technology that has stood the test of
- 0:08
time but writing sql code is not an
- 0:10
ideal abstraction for modern app
- 0:12
development it provides too much low
- 0:14
level control and you'll probably blow
- 0:15
your foot off writing it to address this
- 0:17
concern orms like sqlize implement
- 0:20
object relational mapping to express
- 0:22
data with object oriented code like
- 0:24
javascript classes prisma is also an orm
- 0:26
that addresses similar problems but
- 0:28
instead it has its own declarative
- 0:30
schema definition language you write a
- 0:32
schema to express your data and
- 0:34
relationships in a human readable way or
- 0:36
the schema can be automatically inferred
- 0:38
from any existing database prisma then
- 0:40
converts the schema into type
- 0:42
definitions allowing you to perform
- 0:43
typesafe crud operations with your own
- 0:45
database models which means you get ide
- 0:47
autocompletion tailored to your own
- 0:49
custom schema in addition it handles
- 0:51
migrations as your data structure
- 0:53
evolves and if you want to visualize
- 0:54
your data prisma studio allows you to
- 0:56
view and manage all of your tables and
- 0:58
rows in the browser to get started
- 1:00
you'll need a relational database like
- 1:02
mysql or postgres although mongodb is
- 1:04
supported as well from a nodejs project
- 1:07
run npx prisma init this creates a env
- 1:10
file where you can add your database url
- 1:12
and a prisma directory to define the
- 1:14
schema if the existing database already
- 1:16
has data we can run prismadb pool to
- 1:19
introspect it and automatically generate
- 1:21
the schema from it notice how each table
- 1:23
is represented with the model keyword
- 1:24
then inside the braces we have column
- 1:26
names and their data types as well as
- 1:28
optional constraints like for example we
- 1:31
might use relation to create a foreign
- 1:33
key constraint between a weapon and a
- 1:35
human and we can also index the weapon
- 1:37
id while we're at it the beauty of this
- 1:38
is that the code is significantly more
- 1:40
concise than what you would write
- 1:41
otherwise in raw sql now if we decide to
- 1:44
modify our schema like add an extra
- 1:46
timestamp column we'll also need to
- 1:47
modify the database structure which can
- 1:49
be handled automatically with the prisma
- 1:51
migrate command now to interact with the
- 1:53
database on the server we tell prisma to
- 1:55
generate the client library import the
- 1:57
client into a javascript file and notice
- 1:59
how it auto-completes the models in the


