Database Workflows & API Development with Prisma

Rate this content
Bookmark

Prisma is an open-source ORM for Node.js and TypeScript. In this workshop, you’ll learn the fundamental Prisma workflows to model data, perform database migrations and query the database to read and write data. You’ll also learn how Prisma fits into your application stack, building a REST API and a GraphQL API from scratch using SQLite as the database.


Table of contents:
- Setting up Prisma, data modeling & migrations

- Exploring Prisma Client to query the database

- Building REST API routes with Express

- Building a GraphQL API with Apollo Server

FAQ

Prisma is an Object Relational Mapper (ORM) that allows you to work with a relational database from an object-oriented programming language. It maps the data structures from the relational database into the object-oriented programming language, offering a type-safe database client for querying. Prisma differs from traditional ORMs by using a schema-based approach to model data and generate queries, providing a more intuitive and developer-friendly API.

No, prior knowledge of SQL or TypeScript is not required to start using Prisma. The workshop and resources provided by Prisma are designed to introduce you to all the necessary concepts from scratch, making it accessible for beginners.

In the workshop, you will learn the essential workflows for building an application using Prisma. This includes setting up Prisma with a SQLite database, data modeling, performing database migrations, and using Prisma Client to implement REST and GraphQL APIs. The workshop is structured into hands-on lessons that also cover querying databases and integrating Prisma into web applications.

Yes, the materials provided in the Prisma workshop, such as the Notion document, are freely available for reuse. You are encouraged to use these materials to host your own workshop sessions, whether to educate colleagues or friends interested in learning about Prisma and database management.

If you encounter issues with opening the Notion document during the workshop, the host can export the document as a PDF and share it with participants. This ensures everyone can access the content and follow along with the workshop tasks.

Prisma Client is a type-safe query builder used to facilitate direct operations on your database. It allows you to perform CRUD operations, run queries involving relations, filters, and pagination, and integrates seamlessly into your application to manage data effectively.

Prisma provides connectors for various databases including PostgreSQL, MySQL, SQLite, and SQL Server, among others. It allows developers to define their data model in a Prisma schema file, which abstracts the database-specific configurations and enhances cross-database compatibility and migration workflows.

Nikolas Burk
Nikolas Burk
98 min
14 Feb, 2022

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Welcome to the Database Workflows and API Development with Prisma workshop. Prisma is an ORM that allows you to work with a relational database from an object-oriented programming language. The workshop covers topics such as data modeling, migrations, using Prisma Client for querying the database, and implementing REST and GraphQL APIs. It also highlights the benefits of Prisma, including its intuitive data modeling language, type-safe database client, and migration tool. The workshop provides hands-on tasks and guidance for beginners to get started with Prisma.

1. Introduction to Prisma Workshop

Short description:

Welcome to the Database Workflows and API Development with Prisma workshop. Today, I'll introduce you to Prisma and cover the most important workflows for building an application with Prisma. We'll start by setting up Prisma with a SQLite database, then learn about data modeling, migrations, and using Prisma Client for querying the database. We'll also explore implementing REST and GraphQL APIs using Prisma Client. No prior knowledge is required, as I'll provide the necessary resources and guidance. Feel free to ask questions and follow along as I explain each lesson before giving you time to work on the tasks. I'm Nikolas, the host of this workshop, and you can connect with me on Twitter, GitHub, email, or the Prisma Slack. This workshop is free for you to use and share with others.

Welcome to the Database Workflows and API Development with Prisma workshop. I'm really excited to give this workshop today. Actually, these kinds of workshop are pretty much the favorite part of my job as a developer advocate who works at Prisma to work with people and show them kind of their first steps with Prisma. And that's exactly what you'll be doing today. So no need for any prior kind of knowledge about SQL or TypeScript or anything. We'll start from scratch and I'll introduce all the relevant concepts so that you don't need to know anything upfront.

One thing that I would ask all of you to do is to take this link that I'm now also dropping in the chat and open it because then you can see also this Notion document that I'm using here right now. And just for logistics, I have a second screen here to my left where I'm monitoring the chat. So forgive me if I'm not always looking directly at you all. I'm just checking what's going on in the chat and if things don't work or if you have a question, you can always drop that in the chat or because as I already mentioned, we do a regular Zoom call here. You can also just unmute yourself and then ask a question. So that's definitely possible here as well. An issue that like Notion SO doesn't work for encrypting. I actually don't have another source. I didn't have problems so far with Notion, but it's also not too big of a deal if you cannot open it yourself because I will walk everybody through the document. And what I can do is I think I can export it as a PDF. I can do that later when you get to work on your first task and then I can send you over the PDF document. So we should be able to resolve that. All right. So welcome again, Database Workflows and API Development with Prisma. So what you're going to learn today is basically the most important workflows that you have to be aware of when you want to build an application with Prisma. And I'll explain in a little bit actually what Prisma actually is and what it does. But first I want to give you a rough overview of what we're covering in this workshop. So at first we start by setting up Prisma with a SQLite database. You learn about data modeling with Prisma and performing database migrations. Then you learn about Prisma Client, a typesafe query builder that can be used to query your database. And you're going to explore various queries there from plain CRUD to relation queries to filters and pagination. And next you'll learn how you can use Prisma Client to implement the routes of a REST API and then also the resolvers of a GraphQL API. And you don't have to know what a REST API actually looks like, what a GraphQL API looks like. I prepared kind of the boiler plate for you. The skeletons of the projects that you're going to be working with. So if you haven't heard of what a GraphQL resolver is for example, that's not a problem at all for this workshop. Ahem, so this is the high level agenda. Actually I realized that it's all one hour too early. So that should be like starting at four and then you add one hour each time. What does a lesson look like? So I prepared these four lessons that map to the different things that we want to do in the workshop. So setting up Prisma, data modeling and migrations, exploring Prisma Client, Rest API and GraphQL API are the lessons. And each lesson looks as follows that at first I'm going to give a walkthrough of the lesson. So for example, for the first one here, I click on it and then I'm going to explain what you are supposed to do in that particular lesson. And I'll even show you like here with my terminal, with my VS code, a little bit of the task that you're going to be working on. And after having shown you maybe three or four tasks per lesson, you'll get the time to work on the tasks of that lesson by yourself. And what I really want to emphasize for you all here to get the most out of this workshop is to not already code along when it's still me doing the walkthrough. So I think it's really best if when I show you what a lesson is going to look like, when I explain the individual tasks that you just pay attention and that you raise any kind of questions that cross your mind, but really focus on the things that I do, that I say, and try to understand that. And after that, you'll have plenty of time to actually finish these tasks yourself. So be a little bit patient when I'm explaining each task and each lesson and then you'll make the most out of the workshop for yourself.

My name is Nikolas, I'm the host of this workshop. I really like to educate other developers and as a developer advocate of Prisma, that's basically my main job. And you can follow me on Twitter, on GitHub, you can drop me an email or you can also find me on the official Prisma Slack. One final note before we dive into the topics is that this workshop, this like Notion document is completely free for you to use if you want to host this workshop for yourself at some point. So if you feel like what you've learned in this workshop today is really valuable and you would like to share it maybe with your colleagues or with friends and like maybe like some of them are up for like spending a few hours with you on this then you can just reuse all of these materials that I've put together here and use them when you're giving this workshop yourself.

2. Introduction to Prisma

Short description:

Before we start with the lessons, let me give you an overview of what Prisma is. We'll visit the Prisma website and explore the landing page together. Feel free to ask questions and join in the conversation about databases and object relational mappers.

All right, I think that's it with the overview for the logistics. All right, before we start with the actual lessons I would quickly like to give an overview of what Prisma actually is. And the way how I want to do that is actually just by going to the Prisma website and give you all a quick walkthrough over our landing page because I think that's probably most instructive here. And if you have any questions along the way also feel free to unmute yourself and drop in, I want to make this kind of as interactive as possible. And if we want to have a conversation here about databases and object relational mappers that's totally fine with me as well. So if anyone here actually has strong opinions about this topic, then feel free to join me here.

QnA

Watch more workshops on topic

Build with SvelteKit and GraphQL
GraphQL Galaxy 2021GraphQL Galaxy 2021
140 min
Build with SvelteKit and GraphQL
Top Content
Featured WorkshopFree
Scott Spence
Scott Spence
Have you ever thought about building something that doesn't require a lot of boilerplate with a tiny bundle size? In this workshop, Scott Spence will go from hello world to covering routing and using endpoints in SvelteKit. You'll set up a backend GraphQL API then use GraphQL queries with SvelteKit to display the GraphQL API data. You'll build a fast secure project that uses SvelteKit's features, then deploy it as a fully static site. This course is for the Svelte curious who haven't had extensive experience with SvelteKit and want a deeper understanding of how to use it in practical applications.

Table of contents:
- Kick-off and Svelte introduction
- Initialise frontend project
- Tour of the SvelteKit skeleton project
- Configure backend project
- Query Data with GraphQL
- Fetching data to the frontend with GraphQL
- Styling
- Svelte directives
- Routing in SvelteKit
- Endpoints in SvelteKit
- Deploying to Netlify
- Navigation
- Mutations in GraphCMS
- Sending GraphQL Mutations via SvelteKit
- Q&A
End-To-End Type Safety with React, GraphQL & Prisma
React Advanced Conference 2022React Advanced Conference 2022
95 min
End-To-End Type Safety with React, GraphQL & Prisma
Featured WorkshopFree
Sabin Adams
Sabin Adams
In this workshop, you will get a first-hand look at what end-to-end type safety is and why it is important. To accomplish this, you’ll be building a GraphQL API using modern, relevant tools which will be consumed by a React client.
Prerequisites: - Node.js installed on your machine (12.2.X / 14.X)- It is recommended (but not required) to use VS Code for the practical tasks- An IDE installed (VSCode recommended)- (Good to have)*A basic understanding of Node.js, React, and TypeScript
GraphQL for React Developers
GraphQL Galaxy 2022GraphQL Galaxy 2022
112 min
GraphQL for React Developers
Featured Workshop
Roy Derks
Roy Derks
There are many advantages to using GraphQL as a datasource for frontend development, compared to REST APIs. We developers in example need to write a lot of imperative code to retrieve data to display in our applications and handle state. With GraphQL you cannot only decrease the amount of code needed around data fetching and state-management you'll also get increased flexibility, better performance and most of all an improved developer experience. In this workshop you'll learn how GraphQL can improve your work as a frontend developer and how to handle GraphQL in your frontend React application.
Build a Headless WordPress App with Next.js and WPGraphQL
React Summit 2022React Summit 2022
173 min
Build a Headless WordPress App with Next.js and WPGraphQL
Top Content
WorkshopFree
Kellen Mace
Kellen Mace
In this workshop, you’ll learn how to build a Next.js app that uses Apollo Client to fetch data from a headless WordPress backend and use it to render the pages of your app. You’ll learn when you should consider a headless WordPress architecture, how to turn a WordPress backend into a GraphQL server, how to compose queries using the GraphiQL IDE, how to colocate GraphQL fragments with your components, and more.
Relational Database Modeling for GraphQL
GraphQL Galaxy 2020GraphQL Galaxy 2020
106 min
Relational Database Modeling for GraphQL
Top Content
WorkshopFree
Adron Hall
Adron Hall
In this workshop we'll dig deeper into data modeling. We'll start with a discussion about various database types and how they map to GraphQL. Once that groundwork is laid out, the focus will shift to specific types of databases and how to build data models that work best for GraphQL within various scenarios.
Table of contentsPart 1 - Hour 1      a. Relational Database Data Modeling      b. Comparing Relational and NoSQL Databases      c. GraphQL with the Database in mindPart 2 - Hour 2      a. Designing Relational Data Models      b. Relationship, Building MultijoinsTables      c. GraphQL & Relational Data Modeling Query Complexities
Prerequisites      a. Data modeling tool. The trainer will be using dbdiagram      b. Postgres, albeit no need to install this locally, as I'll be using a Postgres Dicker image, from Docker Hub for all examples      c. Hasura
Node.js Masterclass
Node Congress 2023Node Congress 2023
109 min
Node.js Masterclass
Top Content
Workshop
Matteo Collina
Matteo Collina
Have you ever struggled with designing and structuring your Node.js applications? Building applications that are well organised, testable and extendable is not always easy. It can often turn out to be a lot more complicated than you expect it to be. In this live event Matteo will show you how he builds Node.js applications from scratch. You’ll learn how he approaches application design, and the philosophies that he applies to create modular, maintainable and effective applications.

Level: intermediate

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

From GraphQL Zero to GraphQL Hero with RedwoodJS
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
From GraphQL Zero to GraphQL Hero with RedwoodJS
Top Content
We all love GraphQL, but it can be daunting to get a server up and running and keep your code organized, maintainable, and testable over the long term. No more! Come watch as I go from an empty directory to a fully fledged GraphQL API in minutes flat. Plus, see how easy it is to use and create directives to clean up your code even more. You're gonna love GraphQL even more once you make things Redwood Easy!
Local State and Server Cache: Finding a Balance
Vue.js London Live 2021Vue.js London Live 2021
24 min
Local State and Server Cache: Finding a Balance
Top Content
How many times did you implement the same flow in your application: check, if data is already fetched from the server, if yes - render the data, if not - fetch this data and then render it? I think I've done it more than ten times myself and I've seen the question about this flow more than fifty times. Unfortunately, our go-to state management library, Vuex, doesn't provide any solution for this.For GraphQL-based application, there was an alternative to use Apollo client that provided tools for working with the cache. But what if you use REST? Luckily, now we have a Vue alternative to a react-query library that provides a nice solution for working with server cache. In this talk, I will explain the distinction between local application state and local server cache and do some live coding to show how to work with the latter.
It's a Jungle Out There: What's Really Going on Inside Your Node_Modules Folder
Node Congress 2022Node Congress 2022
26 min
It's a Jungle Out There: What's Really Going on Inside Your Node_Modules Folder
Top Content
Do you know what’s really going on in your node_modules folder? Software supply chain attacks have exploded over the past 12 months and they’re only accelerating in 2022 and beyond. We’ll dive into examples of recent supply chain attacks and what concrete steps you can take to protect your team from this emerging threat.
You can check the slides for Feross' talk here.
Towards a Standard Library for JavaScript Runtimes
Node Congress 2022Node Congress 2022
34 min
Towards a Standard Library for JavaScript Runtimes
Top Content
You can check the slides for James' talk here.
Get rid of your API schemas with tRPC
React Day Berlin 2022React Day Berlin 2022
29 min
Get rid of your API schemas with tRPC
Do you know we can replace API schemas with a lightweight and type-safe library? With tRPC you can easily replace GraphQL or REST with inferred shapes without schemas or code generation. In this talk we will understand the benefit of tRPC and how apply it in a NextJs application. If you want reduce your project complexity you can't miss this talk.
ESM Loaders: Enhancing Module Loading in Node.js
JSNation 2023JSNation 2023
22 min
ESM Loaders: Enhancing Module Loading in Node.js
Native ESM support for Node.js was a chance for the Node.js project to release official support for enhancing the module loading experience, to enable use cases such as on the fly transpilation, module stubbing, support for loading modules from HTTP, and monitoring.
While CommonJS has support for all this, it was never officially supported and was done by hacking into the Node.js runtime code. ESM has fixed all this. We will look at the architecture of ESM loading in Node.js, and discuss the loader API that supports enhancing it. We will also look into advanced features such as loader chaining and off thread execution.