Check out a free preview of the full Introduction to the JAMStack course:
The "Persist Data with Fauna" Lesson is part of the full, Introduction to the JAMStack course featured in this preview video. Here's what you'd learn in this lesson:

Jason introduces the last section of this course about how to handle databases in JAMStack using Fauna. Fauna is designed to be compatible with the serverless world and GraphQL.

Get Unlimited Access Now

Transcript from the "Persist Data with Fauna" Lesson

>> I want to look into how we would have data persist. So if I have an app, and I wanna be able to have somebody create something and save it, and then have that saved data still be there the next time they load up the app. Or if they move to another device, we wanna make sure that they can get access to that.

[00:00:18] So for that to work, we need to have access to a database. Traditionally, databases have been kind of a pain. If you've ever managed your own MySQL or Mongo or PostgreSQL or any of those instances, it's something that you have to stand up. You have to know enough about it to set it up and configure the tables.

[00:00:36] And then there's a whole bunch of boiler plates to write the cred operations and then making sure that it's all kinda sanitized and managed properly. That's all been getting progressively easier over time. And now, we've actually gotten to the point where it's effectively just like we did as front end developers.

[00:00:55] We don't really have to think about it. And so I'm super excited to show you this because this is all pretty new. So I'm going to move into the to-do folder, because what is a workshop if you don't build a to-do app, right? So let's get into this to-do folder, and I'm gonna clear out some old stuff here that I should have done before.

[00:01:23] Okay, so what we've got in this folder is just a .n.example. And for this, we're gonna be using a service called Fauna. Fauna is a very cool database. It does a lot of very computer science-y things. They're gonna talk about stuff like acid and transactions and stuff that honestly as a front-end developer, you want to never have to think about.

[00:01:49] And that is one of the reasons why I like it is that they offer these things but we don't have to care about them. The other thing that I think is exciting is that its designed to be compatible with the server-less world. And it's designed to be compatible with GraphQL.

[00:02:04] Who here has used GraphQL before? It's a couple hands, great. And if you haven't used GraphQL, don't worry, we're not going to go super deep here. We're going to be kind of skimming the surface. And I hope that it's enough to get you really excited about it because I think GraphQL is just amazing.

[00:02:20] It's such a good technology for front end development. So, what we're gonna do first is we're going to actually just set up a fauna account. So let me jump in over here. And I'm gonna go to And so fauna is effectively designed from the API up to be really easy to use with serverless and that's why I think it's kind of nice.

[00:02:49] So I already have an account, I'm gonna sign in with Telefi. And now that we get in, I already created this database so that I wouldn't have to show API tokens. But what we would do here is, we just create a new database and that'll get us set.

[00:03:09] So no special anything. We don't wanna pre-populate with demo data. We're just creating a database. So inside of this, I'm going to get my keys out. And so this is the key that I've created, you would just create a new one here. When you create a new key, you're gonna click this button, make sure you've selected your current database.

[00:03:31] And then for the role, we wanna choose a server key. You can add a name for it if you want. But that name is completely optional. And then once you've done that, you can save it. And then once you have that key, you're gonna open up the .env or you're gonna create a .env and just use this .env example as the setting and just replace it here.