Transcript from the "Prisma Schema" Lesson
>> So Prisma syntax looks like this, it's actually really cool. So they have this schema syntax that where you can define your schemas and something that looks like this and I think it's actually pretty intuitive. It's not really difficult at all and it abstracts away the type of database that you're using.
[00:00:20] So it doesn't matter if using Mongo or Postgres or SQL, this is all gonna look the same. It's pretty cool, I think they were heavily influenced by Graph QLs, language because I know Prisma did Graph QL stuff Prisma version 1 out of version 2 which is just an Oreo.
[00:00:36] So it's heavily influenced by that which was heavily influenced by JSON. So to me this kind of just looks like JSON with decorators. Now we need to define some models for our app. So we can get some real data in here, and we'll go from there. Let's make some models.
[00:00:52] So inside of our Prisma schema, we're gonna do is we can type in the word model, like this, followed by a name. So the first thing I'll do is I'll make a User model, like this. And then I want to say id. And then for id is, there's gonna be this, typically it's a number and then you can do this default auto increment thing.
[00:01:12] So basically what this is saying is, I want an id field, its type is integer, so it'll be a number. I'm literally saying this is the id field of this model. So it's going to make it unique. I'm pretty sure what this does is set, gives it an index like a foreign key and then default, I want to (autoincrement).
[00:01:33] So every time a new user is saved go up by 1. So in Postgres, you have to increment your ids yourself, right? But something like Mongo, it just generates random ids for you. So that's what this does. The next thing is, I want a created at so we can do that createdAt so that, createdAt will be a DateTime, and then we can give it a default of, think it's like now.
[00:01:58] Yeah, there we go, so we can say default(now) and then when I hit save you can see that it formatted it for me like cleaned up the indents and line everything up really nice. This is what I was talking about that plugin that I highly recommend downloading, also one and updatedAt, was also be a DayTime like that.
[00:02:16] No default on that. And I think there is like a, Yeah, there's an @updatedAt, so it does that for this because @updatedAt like that. So that'll auto set that fill for you every time you update an instance of a user, which is really cool. And then now we can get to the actual user stuff.
[00:02:39] So in this example, we'll just have an email, and that'll be a type String. And then we'll say this needs to be unique. So that means not two users is gonna have the same email. This will put an index on it. This allows to query it. Super easy to do.
[00:02:56] And the next thing is we'll have a password. Which is also a String like that. And we'll pretty much, that's pretty much all we'll have for the user for now until we start adding relationships to the different data that we have. I really like Prisma, not even for the schema stuff, but when we get into the querying and the writing like they have nested rights and like filtering.
[00:03:17] And it just makes it so easy to do really complicated stuff in my opinion, especially the types of GraphQL, is actually really quite powerful, so I like it.