about 3 years ago Syntax Podcast
WTF is an ORM
- 00:33 Scott went to the dentist early in the morning
- 01:57 Wes and Scott dread going to the dentist
- 02:43 Scott started tracking his flossing to improve his dental hygiene
- 03:04 Wes asks Scott what an ORM (Object Relational Mapper) is
- 03:20 Scott explains ORM is a translation layer between a database and application code
- 04:35 Scott explains he removed Mongoose but ended up rebuilding a mini ORM
- 05:01 Wes says he often removes packages but ends up rebuilding them
- 05:28 Scott has a tendency to want to build things himself instead of using existing packages
- 06:08 Wes says ORMs allow writing the same database code across different database types
- 06:45 Wes guesses the first ORM was developed in 1971 by IBM
- 07:01 Scott says one of the earliest ORMs was in the 1960s by SDC
- 08:15 Wes used to write SQL Server queries but now prefers ORMs
- 09:07 Scott isn't confident writing raw SQL queries without an ORM
- 09:15 Scott says ORMs provide abstraction and ease of use for databases
- 10:16 Scott had difficulty getting Mongoose schemas to integrate with GraphQL types
- 11:09 Wes asks if ORM schemas are written in the ORM's language
- 11:11 Scott explains models define the data and generate schemas
- 12:26 Scott finds blurred lines between models, schemas, and other ORM concepts
- 12:37 Scott says you model your data to fit the database with an ORM
- 13:26 Wes explains some ORMs have validation beyond basic types
- 14:40 Scott likes Prisma's ability to lint schemas for database compatibility
- 15:34 Wes says sharing schema types with GraphQL avoids duplication
- 16:19 Scott warns about creating deeply nested GraphQL schemas without DB understanding
- 17:23 Scott ran into issues modeling roles as an iterable primitive in MySQL
- 18:12 Wes says WordPress doesn't use raw SQL queries
- 18:35 Scott says Laravel has the Eloquent ORM
- 18:40 Scott says mature systems tend to have good ORMs
- 19:24 Wes likes that Prisma generates types from the schema
- 20:14 Scott had difficulty sharing types between Mongoose, GraphQL, and UI
- 20:45 Scott now shares Prisma types between server and client
- 22:33 Scott wonders if typing subcomponents differently is ever beneficial
- 24:41 Scott explains Prisma strengths like schema linting and nice docs
- 25:24 Wes explains Drizzle's PlanetScale implementation
- 26:19 Wes says many solutions will suffice for smaller use cases
- 27:15 Scott clarifies Prisma has type validation, not custom validation
- 28:47 Wes says most databases today are MySQL, Postgres or MongoDB
- 29:17 Wes uses SQLite and Sequelize for quick demos without installations
- 30:36 Wes sometimes uses SQLite instead of JSON for more control
- 31:29 Scott hasn't used Sequelize but it's popular and often updated
- 32:30 Scott and Wes joke about unclear pronunciation in tech
- 33:40 Wes says non-native English speakers speak better than them
- 34:01 Scott doesn't like tools that require pronunciation guides
- 35:51 Wes is intrigued by Drizzle's serverless and inferencing capabilities
- 37:11 Wes discusses building standards-based instead of Node specific
- 37:49 Scott says Figma had massive scale on a single Postgres instance
- 38:18 Wes suggests a show on supporting multiple JavaScript environments
- 39:27 Scott prefers Mongo aggregations to Mongoose populate
- 40:41 Wes finds Mongo aggregations very difficult compared to ORMs
- 41:50 Scott regrets not using migrations for database changes
- 43:26 Scott has run into issues debugging vague Prisma errors
- 44:43 Wes keeps researching Drizzle's capabilities
- 45:53 Scott introduces topic of database schemas
- 46:50 Wes looks up the difference between schema and model
- 47:29 Scott says models define data structure and schemas represent it
- 48:18 Scott explains migrations keep the database updated over time
- 49:02 Scott has never looked at how Prisma handles migrations
- 49:18 Wes says Prisma generates SQL migration files
- 50:36 Wes has used virtual fields to transition old properties
- 51:14 Wes says some ORMs support middleware for hooks and events
- 52:03 Scott asks listeners for their preferred ORMs and why
- 52:32 Wes mentions new show I Think You Should Leave
- 53:49 Scott loves I Think You Should Leave though his wife hates it
- 54:58 Wes says show humor is hit or miss if you don't get it
- 55:20 Scott praises brilliance and comedy of I Think You Should Leave
- 55:55 Wes suggests Wise cards for easy travel currency conversion
- 57:14 Scott jokes about the number of companies with owl logos
- 57:30 Wes jokes about racing to get a pull request in first
- 59:02 Scott says the show's humor is specific and not for everyone
Scott has run into issues debugging vague Prisma errors
Scott Tolinski
it says, hey. You have an issue with this column, and there'll be nothing there. Rid. Okay. Great. Thank you. Let me, let me just take a guess as to which column I have an issue with because you're not telling me. So, debugging, you know, anytime you're putting yourself between a layer or anything else, that debugging experience could could, security issues or anything without an ORM.
Scott Tolinski
can sometimes be interesting. Let me tell you, Prisma throw some errors that sometimes it's like missing the column names sometimes because we're using planet scale in PlanetScale is not giving the column name correctly to Prisma, and then therefore, Yeah. And, you know, I'm not I'm not really confident on many of those things that I could prevent
Scott Tolinski
3, you have to learn the ORM. You know, I I talk about this as being a downside to anything, whether that's like a front end framework or anything. You have to learn the thing to do the thing. So, rid. You have to learn the ORM specific language. You have to learn their own things. And, yeah, sure, TypeScript can help with that, but you have to learn the syntax and learn the right way to do it. Rid. Also database compatibility issues depending on which database you're trying to use, even database versions, thing things like that. You have to Actually have an ORM that works with the database you wanna use and maybe you end up picking a database just to work with an ORM specifically. Right? Also, debugging, it just like some JavaScript code that can be run? I'm gonna tell you right now, I don't even know. Okay. I've never looked at the database migrations.
Scott Tolinski
or
Scott Tolinski
get into the software yourself and fix it. Man, I'm just CloudFlare workers.
Wes says ORMs allow writing the same database code across different database types
Wes Bos
The actual code that you write to
Wes Bos
all the different languages. That can be really handy because
Wes Bos
select rid. Fun, Deno,
Wes Bos
And you can just write the same code across all of them, right? You just hook up different type of database and all the queries work. What would you say when would you say,
Wes Bos
10 things massive schemas and whatnot,
Wes Bos
rid. Where the name has the word West inside of it is going to be the same across
Wes jokes about racing to get a pull request in first
Scott Tolinski
chaos or whatever. And it's usually at the behest of everybody else feeling uncomfortable in some sort of way. And I find this show to be truly brilliant. There's like moments in it where, it transcends
Scott Tolinski
rid. 50 sodas.
Wes Bos
rid. You wanna get that pull request in? Stop. Stop. Stop.
Scott Tolinski
because he he
Wes Bos
Rid It's so true. You don't wanna be the 2nd person to have to rebase it. You have to pull up 500 cheeseburgers, 500 coffees, But if not, just Much
Scott Tolinski
the moment that that thought goes in your brain, it's completely out the door,
Scott Tolinski
I'll I'll sick pick that. I'll sick pick season 3 of I Think You Should Leave. I've sick picked the 1st 2 seasons. They're both great. Season 3 really comes in. It's funny because you think after however many sketches of the same kind of style Rid.
Wes Bos
putting a pull request in for the same file you're working on,
Wes says many solutions will suffice for smaller use cases
Wes Bos
working inside of that, especially someone's name. All of them have this, by the way. No, not all of them do. And It's really nice. Mongoose has this. Let's say somebody updates their name.
Wes Bos
then you just jump into the,
Wes Bos
and whatnot, that's what I do is rid Like, I have a whole admin thing. If something is not possible in the admin UI, to like a virtual field.
Wes Bos
and whatnot.
Wes Bos
It's really nice to be able to do that. And then, of course, if you do that 2 or 3 times and you realize, oh, I should probably And a big part of my job was writing,
Wes Bos
rid. Meaning that, like, you could possibly make a change that would not be approved in your application,
Wes Bos
and then that could goof up rid. Well, Prisma Studio does block you from doing that kind of stuff, which is nice. So does Prisma Prisma has validation built in then? Yes. Oh. Well, I don't know. Like type both of those, Obviously, TCP, but also being able to to send it requests via HTTP. So I guess the Drizzle's implementation You should be able to, like, Mark something in your schema
Wes Bos
rid be building a thing. This is also kind of scary
Scott says the show's humor is specific and not for everyone
Scott Tolinski
Io.
Scott Tolinski
Only throw them in production and stuff right now. So check it out, century.
Scott Tolinski
Rid. West sent me a Slack message the other day that says, hey.
Wes Bos
Peace. Peace.
Wes Bos
Shameless plug. Westboss.com/courses.
Scott Tolinski
it had Century up in my SvelteKit project.
Scott Tolinski
plug century at century. Io. That's s e n t r y dot I o. You can use the coupon code tasty treat, all lowercase, all one word to get 2 months for free. Sentry is the perfect place to track all of your errors and exceptions. And Guess what? We're building the new syntax site right now. We've been talking about it for a while. It's one of those things that, you know, it's gonna be a long time project, but we're building it. And I just set it up with Century using their new SvelteKit So Yep. Yeah. Definitely a character flaw of mine wanting to do it myself and then, You know, realizing I should've actually used the thing that was popular, which is why we're using And anybody who's used MongoDB knows that that is, like, kind of different than how you work in Mongo. Typically, it can be like the wild wild west. You can just throw data in there and Mongo doesn't care. But it does actually have a built in data validation using JSON schema if you want to use a model based,
Scott Tolinski
on on Twitter and stuff. So check it out. I think you should leave season 3 very funny. Rid. Yeah. That's it for me. Shameless plugs. I'm going to shamelessly the type safety. Right? So if you're able to define your data as a model is typically what they're called. So they're not necessarily typically referred to as a schema, but more or less as a model, even though I wish somebody smarter than me would tell me, like, what's the difference there because you do see them used of interchangeably. Remember when we had the MVC patterns and like, oh, in this framework, the v is actually
Scott Tolinski
And don't forget to subscribe in your podcast player Or drop a review if you like this show.
Scott Tolinski
Either way, primitive rid. You've probably seen the memes at this point around,
Scott Tolinski
you know, CLI's that modify your code or do anything and and
Scott Tolinski
If you if you watch
Scott Tolinski
You need to adjust the alerts. I'm getting so many alerts, and you're you're just working on the site. And those were the alerts are coming from. So I was able to say, hey. Only throw alerts in this specific environment.
Scott Tolinski
Within Sveltekit
Scott Tolinski
and essentially one little CLI command.
Scott Tolinski
rid be hit or miss, but I ran this this code. I I ran it in 2 seconds.
Scott Tolinski
rid. It's been a little while since I set up a a full new site on Sentry. But either way, Sentry, perfect place to see all of your errors and exceptions happening. You can get Profiling, you can get,
Scott Tolinski
And let me tell you,
Scott Tolinski
replays. You can see what happened when somebody clicked on a thing and it broke your thing. You can see it right there. You have, you can monitor your cron jobs now. You can choose how you wanna send alerts. If you have a big or small company, you could choose who's getting those notifications.
Scott Tolinski
And next thing you know, this this month and it's been going for 8 years. So definitely feels like one of those mature options has TypeScript support, inside of Mongoose using populate and have it work
Wes Bos
That's it. Thanks, Eric, for tuning in. We'll catch you later.
Wes Bos
Check it on out if you wanna learn a thing or two about JavaScript
Wes mentions new show I Think You Should Leave
Wes Bos
like hooks or events or metalware, like writing SQL. So If you're writing MySQL or something like that, or you're writing Postgres,
Wes Bos
anytime anyone touches the name property on a user. You want to regenerate a slug.
Wes Bos
I think everyone's loving.
Wes Bos
where if you delete something, you don't actually delete it because the middleware will be like, it steps in and says, don't actually delete it. Put it in, like, I much prefer when, like like, for example, I have customers meaning that like when you connect to a database, you generally make a connection via TCP and you just send rid data through that connection.
Wes Bos
And when you do that, what's that one that everybody's loving?
Wes Bos
You could just listen for that value to change, or you could do, like, soft deletes. I know Prisma has
Wes Bos
Yep. Yep. I've been I just started watching it with my wife, and she was not into it at all. And I was Dying. Wes Isaac picked the show twice now,
Scott explains he removed Mongoose but ended up rebuilding a mini ORM
Scott Tolinski
I'm doing my,
Scott Tolinski
it it provides like, translation. I'm doing all this stuff, and I have, like, a little mini ORM. And I did not Set out on making an ORM. I was just like, oh, Mongoose feels too heavy for this. Let me do something else. So I I directly hit that exact Quote in my own work, not intentionally doing it just because
Scott Tolinski
ease of use in abstracting the kinds of things that you do with a database or in a data layer day to corporation in the 19 sixties.
Scott started tracking his flossing to improve his dental hygiene
Wes Bos
ORMs.
Scott prefers Mongo aggregations to Mongoose populate
Scott Tolinski
what is that? migrations is another thing that ORMs can do for you most of the time via like a CLI.
Scott Tolinski
It it's a pain to write. In fact, like most of the time when I wanted to write a Mongo aggregation, I would almost always run to Yeah, you're right. Outside of your like code validation, like you're saying,
Scott Tolinski
Populate where you can do relational mapping. Rid. Yeah. Do relational queries
Scott Tolinski
pipeline, but for me worked fine.
Wes Bos
it's named a bit funny because I named them before I had the users in the database, and I've never wanted to switch it. But essentially, you can have you log in, And then you can have like a list of purchases, right? And if you if you want to query the user, but you don't care about their purchases,
Wes Bos
is really, really tricky. So
Scott Tolinski
keep a more organized way of doing things like dire. So I'm like Yeah.
Wes Bos
So Mongoose is an option. Yeah. That's always a weird thing about like MongoDB is that like as soon as you want to do something a little bit different, you have to like, real Rather than just a quick demo or me trying to figure something out, it would be nice not to have to rewrite all this stuff. So if you use SQL, oh, well,
Scott Tolinski
just this is maybe me just being Like this kind of like salty old man, but like their whole, like, MySQL.
Wes Bos
then you don't populate that value. But If you do, you just dot populate on the end of it. So you you because you were saying, like, with the Mongo pipe aggregation pipeline, It's my favorite show.
Scott Tolinski
Yep. I personally would rather just go straight up Mongo aggregation
Scott and Wes joke about unclear pronunciation in tech
Scott Tolinski
Like silent letters? What the hell? Just anything. Yeah. Just anything. What the hell? My my son literally yesterday was like, He's brilliant. I think he should leave his, like, they call it, like, kind of cringe comedy or something. It's, the whole premise of the show is
Scott Tolinski
So you're right. Yeah. Oh. I'm totally wrong. I mean, it makes both of the ways. It seems like if here's here's my hot here's my hot tip. If you have to put a pronunciation guide next to your product name, that's a bad product name. I don't. Can we I don't like it. We also talk about these, like, when people tell you how to pronounce something, rid. They put it with all these, like, squiggly letters that also make no sense to me. Like, I don't know how to read those. Who knows those? Does anybody know those? Yeah. I don't think anybody does. No. Probably people.
Scott Tolinski
I don't get why cities starts with a c. Why wouldn't they write the word cities with an s? And I was like, I don't know what to tell you, man. It's a That's, that's one of those questions.
Wes Bos
that pronounces it. Yeah. And it's man, I miss I miss, SQLite, that kind of stuff is But, Alberto,
Wes Bos
literally, the first line
Scott says one of the earliest ORMs was in the 1960s by SDC
Wes Bos
what's the Microsoft SQL
Wes Bos
select queries,
Scott Tolinski
was integrated data store developed by SDC System Development
Scott Tolinski
Rid It seems like they've just been around for as long as we've been working with data storage in any any type of capacity, language that my database is expecting. So I'm just going to do it that way. But, I've often heard, like, the saying that, And eventually, every time I would query that data. I'd be like, oh, give me the playlist ID thinking it was the idea of the data see some issues. And and sure enough, you know, you gotta you're ready. Holding for somebody else to fix those connective tissues And,
Wes Bos
Server?
Wes Bos
rid. Orm over straight up rid. Links to a YouTube video
Scott Tolinski
which is wild to think about, especially Head on over to syntax.fm
Wes Bos
Rid SQL Server. That's what it is.
Scott Tolinski
of some sort of data store tape. Yeah. I mean, you're very close because it says,
Wes Bos
whatever the language is, because probably the biggest one to me is
Wes and Scott dread going to the dentist
Scott Tolinski
I go in there and I told them, like, the the instead of just importing the object with all of the properties on it, even though that's the data that's Like getting passed into it because the the component only needs those 2 properties.
Scott Tolinski
of the Oh, yeah. Like, once your gums start to recede, they, like, don't stop. And because it was started by that tongue piercing, if I don't, like, really intensely,
Wes Bos
rid. I'm not flossing as much as I should be. Just like, please, can we skip the And
Wes Bos
the whole where you care more than I do? You know? is not
Scott Tolinski
it's it's very funny. I I had to start caring a lot because and I just like wanted Yeah. One of the earliest ORM like tools was integrated wizard that allowed you to quickly and easily get Century going for the whole application
Wes Bos
stop abusing me. You know? Like, I understand
Scott Tolinski
Yeah. I've had to just start you know what? They actually, like, love me now because that seems like overkill. It's like almost never overkill. So if you're a young developer out there and you're hearing some things About its own model for the roles entirely. So you have to have Really? A roles model. Yeah. So, like, there's It's not possible to say
Scott Tolinski
take good care and and floss like crazy and do the water pick and do the electric. If I if I'm not doing everything perfectly,
Wes Bos
like, stop
Wes uses SQLite and Sequelize for quick demos without installations
Wes Bos
SQLite doesn't require anything to be installed. It's just a file on your file system.
Wes Bos
without having to do any database connection strings or any of this type of stuff, probably in
Wes Bos
throw it into a Throw it into a JSON file on the file system because it's just local, right? And then and then when I pull it out, I just read the file, parse it out And you're good to go. But sometimes you want a little bit more control over that and SQLite supports Alibaba.
Wes Bos
Like, this is something I run into all the time where I build a quick little demo logic everything
Wes Bos
and I go, I need to save this data somewhere.
Wes Bos
And when I run into that, I do one of 2 things. I say I'm just going to JSON stringify it,
Wes Bos
And then you can even do it straight away in memory so that doesn't even have to be a file in your file system. It just goes straight into memory and then it gives you
Wes Bos
so fast
Scott says ORMs provide abstraction and ease of use for databases
Scott Tolinski
and make many of the things, but effortless, you know, update many, create many, whatever,
Scott Tolinski
that and now granted The new syntax site isn't in Mongo, and I'm actually pretty excited to to be trying something a little bit more,
Scott Tolinski
get into, like, really crazy situations or or scary situations with With the database, it all feels very, like, almost ORM like anyways. You're just running methods and whatever. But for the most part, you know, having an ORM to do basic CRUD operations Yeah. Yeah. I know it's, delete many, whatever that language ends up being. You're just running those basic CRUD operations in what is a standard kind of method based, grabs the correct one based on whatever you have or, you know, the most complex one I have include
Scott Tolinski
Not because I I don't trust myself in doing the research to figure it out, But, you know, I just haven't written enough. And and I've been working in MongoDB for so long at this point I'm still seeing commits
Wes looks up the difference between schema and model
Wes Bos
more of like an ORM level, higher level based language where I simply just have my model and I have a couple of different methods for querying and and I have users or, like,
Scott Tolinski
I think you can just bypass that. I think we just pretend that doesn't exist.
Wes Bos
How do how do you say you say it? Like, I'm going skiing, ma. Schema. Schema.
Wes Bos
description of it. So
Wes Bos
Schema.
Scott Tolinski
Schema.
Wes Bos
in most cases, we will be writing models,
Wes Bos
a schema
Scott explains models define the data and generate schemas
Scott Tolinski
A schema
Scott Tolinski
I, you know, I wanna take the type this out specifically
Scott Tolinski
where, Rid. You know, you can write some some unoptimized code, but also the fact that there is a layer in between you and the database means that inherently, there's going to be, accomplish.
Scott Tolinski
The data fetching and not the HTML. And in this framework, the v is the HTML and not the data fetching. Like, that's the controller.
Scott Tolinski
with or anything like that, or you have unique IDs.
Scott Tolinski
you know, I found 1 episode of it and you do not laugh and you hate it, you probably won't like the rest of it.
Scott loves I Think You Should Leave though his wife hates it
Wes Bos
Rid. He's just always yeah. It's just incredible. There's there's some, like, really amazing moments on it. The The part where he does the zipline, where he's like, oh, he's on the zipline, and then they bring in the, like, guy that rents the zipline. He's like, there's too much wear and tear on the
Scott Tolinski
He can't do it. I know. I I've been, like, dying of the, the shirt. There's a one of the shirt brothers.
Scott Tolinski
And, a mature and good ORM. Laravel has Eloquent ORM. That's their ORM.
Scott Tolinski
rid. The 3rd season of I Think You Should Leave. So Yeah.
Scott Tolinski
And And I used robust, so to say, in many different ways. But It it it does feel like many times with Mongo or something like that, it's really easy to not
Scott Tolinski
hate it to the point where she will leave the room if anything is on and she really hates it.
Scott Tolinski
But it is my favorite show on TV
Scott Tolinski
after both the 1st and the 2nd season.
Scott Tolinski
Courtney So basically, yeah, it helps you write write safer And sometimes they do a lot for you. Sometimes they're minimal and they try not to get in the way too much. But oftentimes,
Wes Bos
I was we only watched, like, 2 episodes so far, but I've been, like, quoting it. Like, give me a sec. I'm doing something.
Scott Tolinski
he's he's too he's too rough on the zipline. He's too rough on the line.
Scott doesn't like tools that require pronunciation guides
Scott Tolinski
Drizzle is kind of the the new hotness one because people are talking about it on Twitter. But you know what? I
Scott Tolinski
you know, I think that's just to boost up their
Scott Tolinski
their whole word cloud where it's like developers, Valket is smart enough to know to pass those same following fields along to the front end. Now the only time that I didn't have to reference the Prisma ones is when I'm My name is Scott.
Scott Tolinski
rid. I don't wanna say anything controversial because I haven't used it.
Scott Tolinski
I personally don't see enough to, stuff that comes into play here
Scott Tolinski
Either way, connects is a batteries included SQL query builder. So, basically, it's a query builder. So this thing uses an existing query builder that's already popular anyways. So if you're if you have experience with that, then maybe, objection is a good way to go.
Wes sometimes uses SQLite instead of JSON for more control
Wes Bos
rid Just flip this thing over, and you don't have to write Let's let's get on into I've done and then it figures out, Sometimes you might already have a specific database in place, or sometimes a lot of people are very opinionated about what type of database they'd like to pick.
Wes Bos
but SQL SQLizes that would be pretty handy. Well, if we need to rip out our our our database ORM, now is the thing to do. No, man. Like Or we've gotten too crazy. Very happy working in Prisma. It's, like, so simple. The fact that the types follow you all all the way around, I think it's more than what we need for our website. Yeah. I do like it when Types follow me around.
Wes Bos
But then I thought, like, if this thing if I actually turn this project into something that is a little bit more, table of the possible strings.
Scott Tolinski
I haven't picked it yet. I haven't tried it, but definitely one to look into.
Scott Tolinski
very fast to get up and running. Yeah. And it seems like it's one of those things that a lot of People use the like a a very common project. There's a version 7 that's in alpha right now. So, you know, it's it's definitely, like, still being,
Wes Bos
npm npx init or anything like that. Like Bigger projects, I probably would just use Prisma,
Transcript
Wes Bos
relational databases rid Most are probably MySQL, Postgres, or or Mongo these days, right, you'd say? Yeah. A lot. It's Yeah. We had a couple years there of a lot of people camera thing. Because we Not the cameras and not there's another one that's wise as well.
Announcer
You're listening to Syntax, the podcast with the tastiest web development treats out there. Strap yourself in and get ready. Here is Scott Talinski and Wes Boss.
Wes Bos
Welcome to Syntax.
Wes Bos
Waterline ORM. We're going to dive a little Deep on into it.
Scott had difficulty getting Mongoose schemas to integrate with GraphQL types
Scott Tolinski
you get lovely things like type safety, which in TypeScript and JavaScript having type safety
Wes Bos
in the ORM specific ready matter if you pick MySQL or Postgres or MongoDB.
Scott Tolinski
Isn't correct?
Scott Tolinski
I I desperately want that. I don't want to hit that error,
Scott Tolinski
It's fantastic if I'm going to,
Scott Tolinski
make sure my database is completely set up the way I'm expecting it to. And then I run a Create operation. And my create operation gets a red underline because a data type I'm trying to pass into one of the values in in my model I don't know. Some of these concepts that I I were taught Okay. Let's keep moving here. There's also Type ORM, which is the ORM from SQL Server. So it is very much like a,
Scott has never looked at how Prisma handles migrations
Wes Bos
a SQL file,
Scott Tolinski
I can I can pop open something to see? Let's see. Yeah. I don't I don't even know here, to be honest. I'm looking at the I don't know where it generates that. I think it puts it in the node modules folder or something somewhere hard to find. It doesn't put it into your life. Oh, looks like it gives you database I am importing and using those types on the client side.
Scott says you model your data to fit the database with an ORM
Scott Tolinski
validation as well.
Wes Bos
but some ORMs will also include, like, a validation layer where you can say, okay. When this thing is saved, rid. Check that it meets X, Y, and Z because it's kind of similar
Wes Bos
in to TypeScript, where TypeScript you can say this thing is a string
Scott Tolinski
Done. You have a follow-up?
Wes Bos
Or this thing is a union of possible options.
Wes asks Scott what an ORM (Object Relational Mapper) is
Wes Bos
rid What language you're building your back end in, you you might want to use an ORM. What is an ORM, Scott? It's the sound I make when I met the dentist.
Scott Tolinski
Rid. An ORM, object
Scott finds blurred lines between models, schemas, and other ORM concepts
Scott Tolinski
So I I think sometimes they They take a look at these things in different ways. Like, what is the scheme of first? What's the model? But at the end of the day, you are modeling your data to fit into a database.
Wes used to write SQL Server queries but now prefers ORMs
Wes Bos
Filtering and pagination, all that good stuff on top of it. So Let me go first. I'm doing something.
Wes Bos
that's where I would generally reach for an ORM, rid. Instead of straight up using
Wes Bos
the different types Part of every ORM, Such a nice experience being able to just
Wes Bos
and
Wes Bos
I just want to use an A big a big part of that job was was just writing straight up SQL Server queries,
Wes Bos
I worked at a bank and I was in charge of putting together reports and whatnot. So I wrote a lot of CRUISER. At the time, I was pretty good at or customer dot find one. And all I've done finder. Yeah. Has many.
Wes Bos
MySQL,
Wes Bos
object We were just joking about this before the episode is that often we'll have people on the podcast to English is, like, their third language, And there's so much more well spoken than Scott and I.
Wes says show humor is hit or miss if you don't get it
Wes Bos
if you were to, like, show it to somebody, you rid. You know, like, sometimes when you show something someone like a TikTok or something, you're like, this is the funniest thing in the world. And then there's like, do you
Scott Tolinski
I could watch it. Watch it any time. I could watch it over and over again. I don't care that it's quoted and popular and whatever.
Wes Bos
what?
Wes explains Drizzle's PlanetScale implementation
Scott Tolinski
third party database application database management applications, but it does make Basic tasks easier if you're not doing big, big tasks with, database stuff. Yeah. It's it's also like a cheap and easy admin. You know, like, before you write cheap and easy admin. Yeah. Before you write all the UI to CRUD I don't know. Something that something happened when I hit my thirties, and I really dread going to the dentist. Maybe not,
Wes Bos
It's just its own DSL. Right? Which is great because
Scott Tolinski
And they're they're technical. Yeah. Like he said,
Scott Tolinski
where Oh, that's the best. A database UI that you can pop open. And then you know what? You don't have to buy. You don't have to But, I I mean, you you could buy one of these And this Prisma schema allows you to have like a source of truth for the entire every model of your database and schema and all that stuff. One of the cool things about the fact that it's so very specific
Scott clarifies Prisma has type validation, not custom validation
Wes Bos
there's a possibility you could just write ABC 123.
Wes Bos
Like, something I do sometimes is someone say, oh, I bought this course,
Wes Bos
I don't know if it actually if it validates it or not. It's been a while since I built that tool, but
Wes Bos
It won't know. Hey. That's not a valid In database land, you have you can say this is a string.
Scott Tolinski
SQLite,
Scott Tolinski
object ID that exists in this database. Yeah. So either way, Prisma full featured, nice tools, nice everything, nice system. So, You know, I'm I'm a big fan. You know, I think it might be a little bit heavier handed than some of these other ones, but it does does the job and it does it well. Another really popular one is SQLize, which SQLize does not support Because the way we're working in ORMs today is is probably very, very different, but very fascinating nonetheless.
Scott Tolinski
system. Right? Supports Mhmm. Postgres, MySQL, Maria,
Wes Bos
That's not a proper user ID. Whereas, like, in my MongoDB, TikTok I saw the other day, which is talking about the I'm doing something.
Wes Bos
and I actually bought it for somebody on my team, And I need to transfer to them, right? And if that's the case, then you update the related And then it just converts it to euro
Scott Tolinski
rid. A very specific use case if you have a SQL database and not like a more general works with everything kind of world. But, I mean, most databases out there, I'd say, are either,
Wes has used virtual fields to transition old properties
Wes Bos
while you're doing it.
Wes Bos
and then you kind of run it but it seems like people are sort of coming back and saying, yeah, you know what? Rid. Postgres was the way like, there was something from Figma where
Wes Bos
you can remove the old one. But that, like, sort of in between value, especially if you can't take down the entire website
Wes Bos
And then your virtual field will be able to, like, look it up. All right. Well, does it have this? I'm signing up a couple 100 people a day and making several 1,000 queries
Wes Bos
Does it have the old value or does it have the new value? And then over
Wes Bos
rid. You add an additional field Sequelize is fantastic, especially
Wes Bos
when you need to pull that value. Rid. Or what sorry. What I've done is you add a new field and then switch the old one
Wes Bos
Sometimes you have to run both at once and have a little bit of logic to decipher which one is needed.
Wes Bos
Once you've finally done your migration, then you can, in JavaScript is pretty cool, and they have a
Scott had difficulty sharing types between Mongoose, GraphQL, and UI
Scott Tolinski
this world before with my Mongoose set up before.
Scott Tolinski
to talk to each other in a way that TypeScript actually liked was infuriating.
Scott Tolinski
server, which also had types. Those were 3 separate models. Yeah. And getting those 3
Wes says Prisma generates SQL migration files
Wes Bos
which you can
Wes Bos
and I'm probably never going to change it because it's not worth the pain of changing it over. That's like one of these things that these systems, especially with migrations.
Wes Bos
But Mongo doesn't Have the concept of migrations, which is Yeah. That's why, like, I have something misnamed in my code base,
Scott Tolinski
but I was really scared to touch my database because without proper migrations, everything was, like, very You just don't feel like you can make modifications to your database beyond adding fields. So it's just like, oh, just add another field or something. In the past, where instead of writing types once for something
Wes Bos
MongoDB. I guess that makes sense because they would have to
Wes Bos
for every single implementation.
Scott Tolinski
playlist model. No. It's the playlist on YouTube for some reason. Like, I would have loved to have changed that at some point,
Wes says some ORMs support middleware for hooks and events
Scott Tolinski
Yeah. Cool. Well, that is, ORMs as a is a big old topic.
Scott Tolinski
Early on and my dumb brain was like,
Scott Tolinski
either migrations or this or that. And you're thinking, oh, that seems like, why do I have to do that? Well, there's usually very good reasons, and it's usually just you being ignorant, Which it's for me, that's always the case. So
Scott Tolinski
And, I hope you found it to be interesting. You know, I these are one of the systems that I've only used a few of these. I've now used
Scott Tolinski
it it is funny. It's like,
Scott Tolinski
Mongoose and I've used Prisma specifically.
Scott hasn't used Sequelize but it's popular and often updated
Scott Tolinski
Have you I've seen Connex a bunch beef is it next? I I don't think the c is you said the c. Okay. Yeah? Okay. Rid. I don't I couldn't tell you, to be honest. I I you could go either way for me. They they shouldn't spell things like that is what is my opinion. That's that's a good point. English is such a bizarre language.
Scott Tolinski
It uses 1 or many of these things.
Scott Tolinski
Postgres, There's also I hadn't heard of before we started this,
Scott Tolinski
It works with SQLite,
Scott Tolinski
Connex JS?
Scott Tolinski
JSON schema validation.
Scott Tolinski
show notes, I had never heard of Objection rich. J s, have you heard of that one? I have not. Yeah. Well, this was listed as one of the more popular ones and it has 7,000 stars. So it's not like a massive project, but it does seem to be one of those projects that, they mean it. My my, like, gums are are permanently effed, So I'm gonna have to get, like, an actual surgery to fix it at some point here. And it's just it's Yeah. A lot of these things, it's it's funny. There's there's so many blurred lines. And I think one of the questions that people have, like, what exactly? Where does the, It doesn't use Code generation. So that's like a thing. You know, Prisma uses, I believe, code generation for their types.
Scott Tolinski
people do use and has been going. The initial commit was 8 years ago, so it's it's
Wes suggests a show on supporting multiple JavaScript environments
Wes Bos
different JavaScript runtimes. We should maybe do a show on that because that's what my talk was at Reactathon, which is
Wes Bos
Node, Cloudflare Workers, Fastify,
Wes Bos
standards based JavaScript instead of Node APIs.
Wes Bos
There's like there's so many different environments.
Scott Tolinski
Allows you to work with Mongo in an easier way. One thing that Mongo by default doesn't do is hear anything above the shape of your data. So Mongoose Cares about the shape of your data and allows you to do validation stuff.
Wes Bos
I didn't realize that that's awesome that they support all of the It's a much different scale, and I don't know if
Wes explains some ORMs have validation beyond basic types
Scott Tolinski
so validation. Type validation.
Wes Bos
But you're not able to do, like, custom validation where you say, all right, the string must start with Postgres, whatever.
Wes Bos
When I am creating this, it must pass this validation. That's not something every ORM includes. Actually, I would say probably most of them don't.
Scott Tolinski
Prisma, the ORM that we're using has its
Wes Bos
Ord, and it must be 8 characters long. And if that's the case, then generally you write a little bit more code into your model that says,
Scott Tolinski
You know, how how much does this thing do for you right before it becomes more than an ORM or less than ORM? And to me, that that is also a little unclear because it does feel like some rid. Some of them want to do a lot and some of them want to do a little. But at the end of the day, you just have to think about it as this this layer that sits in between and translates. And sometimes they they help you parsing and validating. Sometimes they don't. Sometimes they help you with migration. Sometimes they don't. One thing that I really like about, the actual
Wes Bos
There's different types of strings, big ones, long ones, etcetera.
Scott ran into issues modeling roles as an iterable primitive in MySQL
Scott Tolinski
Oh, it's nice that they caught that type of thing. Yeah. Because I wouldn't have known otherwise, you know, that my history with MySQL
Scott Tolinski
And, So the fact that you were, like, 1971, like, early 19 seventies, that Yeah. That's pretty, yeah, that's pretty amazing.
Scott Tolinski
I didn't want it to be just like you only have one of these things. It it had to be an array of Okay.
Wes Bos
is WordPress. And in WordPress land, I'm not writing, rid raw my SQL queries ever. I wasn't personally. So yeah. Yeah. You almost never write raw SQL queries in WordPress because they have their ORM, right? It's called the query in WordPress. And there is the ability to go straight into the database.
Scott Tolinski
is is specifically what the error was was mad at me about. Makes sense.
Scott praises brilliance and comedy of I Think You Should Leave
Wes Bos
credit cards
Wes Bos
instead of just using our, like, personal credit cards, Canadian cards, because they rid kill you on the exchange rate.
Wes Bos
something I picked before, but I was saying I'm going to pick some travel stuff, and that is using Wise or previously we called it Transferwise
Wes Bos
I just loaded up the I'm just going back to my initial get up and running quickly kind of thing, but But then you still need a Postgres database, right? Like it would be cool. Oh, no. Does it work with SQLite? It does. I think it says Web SQLite, I think. Yeah, it does work with SQLite.
Wes Bos
on your phone. So Figma was running on, like, a single instance of Postgres. Postgres. Yeah. The first, like, $1,000,000,000 in my case, I have to open up the, rid. MongoDB Compass, which is a fantastic tool for editing it. But Prisma
Wes Bos
Rid. I'm going to sick pick,
Scott Tolinski
Yeah, I just I really enjoy it. It's very funny to me.
Wes Bos
and
Scott now shares Prisma types between server and client
Scott Tolinski
the data that I'm sending
Scott Tolinski
that
Scott Tolinski
is there a situation to the modeling of your database as a model. Some of them refer to it as a schema. Some of them refer to the collective models as your schema. At the end of the day, you are writing a model for your data. It's modeling the data. And that often determines exactly
Wes Bos
as server side only.
Scott Tolinski
Rid. In a related conversation with, I you know, I've often wondered, like, rid. In a in a component based flow for the UI and talk about UI.
Scott Tolinski
what we're doing with Prisma is
Wes Bos
And then you forget to omit that. You know, I guess it's not a big deal for types, but it definitely would be for queries.
Scott Tolinski
But then you could always just use, like, pick or any of those, like, utilities
Scott Tolinski
this Rid. And that's why. That's specifically why. It was the fact that it was an iterate iterable the database model or the database schema, Prisma, you have models that make up your schema. Where with SQLize, you have models that can be associated with the schema. Yeah. I'll I'll talk about all that in a little bit here. So it it they typically do have that concept where basically
Scott Tolinski
when
Scott Tolinski
I pass in, at a database level. I don't wanna hit that error anywhere else. I wanna hit that error while I'm authoring the code in the TypeScript with a little red squiggly, like I just made a tiny little mistake that I can I can figure out myself? Rid. So with ORMs, this is a question I have for you. You are always writing your schema JavaScript or at least it was trying to be A very long time. Sales has been around for a long time at this point, but I haven't used it personally. So,
Wes Bos
to see. You could just Omit. Yep. Or even I think some of the ORMs will allow you
Wes Bos
and strip out the tips. It's probably better to use pick. Yeah. Because which one is better? Yeah. Because, like, pick. You're explicitly opting in, whereas omit you're opting out. So, like, what happens if you add a new property
Scott Tolinski
this from the database and I only want to project of the following fields. It knows that the types it's going to give me on that data are those following fields. Then
Scott Tolinski
And typically it's because
Scott Tolinski
If you have, like, a leaf component
Wes Bos
run through them real quick. Use omit a put a flag on it, you know, and To using an ORM Alright. After this, I'm gonna the ability to write a middleware which is I did look up the difference between So apparently
Scott Tolinski
is going to be that data. And Prisma is smart enough to know. Well, I should say Prisma and Seltkit are smart enough to know
Wes discusses building standards-based instead of Node specific
Wes Bos
per day.
Wes Bos
rid. I would hit the issues that a lot of people do. One neat thing about,
Wes Bos
300,000
Wes Bos
will be more than enough for a lot of people listening in what we build. Right. We're not
Wes Bos
on the century level where we're getting infer model.
Wes Bos
like almost all of these solutions
Wes Bos
that
Scott asks listeners for their preferred ORMs and why
Scott Tolinski
Things that were just validating data that kind of did some of the roles in ORM. But If you've used any of these specifically and you find them to be just fantastic, you think Drizzle is the bee's knees, let us know. I wanna hear all about which ORMs you're using, Why you're using in them and what you like specifically about them is up on Twitter or any of that stuff. So yeah. Wes, sick pick, shameless plugs. Do you have a sick It's a little trickier to do that right now, so that's nice that they've Done that from the start. Yeah. Yeah. Totally. It definitely like this one does feel like a project that's like, well, what if we started writing an ORM today? Not, You know, without having a legacy. That's how this stuff always works. Right? Mhmm. You start writing it today, and then next thing you know, everything's kinda shifted underneath you. So okay. So that's neat. We also have Mongoose. People wonder I see this question all the time. You're working with Mongo. Like, why do people use Mongoose? Mongoose is an ORM. It basically I do so much, like, self talk to myself about,
Wes Bos
I do. I do. Actually, hold on. I have one more thing to add, and that is the concept of, using different types of databases with different packages. Which one should you use? Prisma, SQLize, Objection, Drizzle Mongoose, Type ORM, In order to support all those environments, you have to write it in user ID, right? And if you put in an incorrect user ID, it'll yell at you for saying, hey.
Scott Tolinski
ish ORMs before as well.
Scott Tolinski
ready for us today.
Scott wonders if typing subcomponents differently is ever beneficial
Wes Bos
it could be undefined, but it's not gonna be undefined. You know? It's not in this case, it's not. And,
Scott Tolinski
To typing that component with the object and 2 properties specifically
Scott Tolinski
Is that like I I, like, ran back and forth in my brain logically is, like, rid. I I don't see people doing it this way. Is this a dumb idea? I don't know. Is it too much work? Is that Just pass in the whole thing or, like, rid. I run into the same thing with, like, undefined types. You're like,
Scott Tolinski
is there a downside you know, writing raw database queries isn't necessarily something that a lot of developers are doing. And maybe some developers think that, Like, I'm really super good at writing in Mongoose, which is a 2nd model. And then I had a GraphQL which has been somewhat recently, the 1st site I did with it was the the coupon code site for the Syntax t shirts And then most recently, the syntax site
Wes Bos
of course, inner joins and left join and primary keys
Scott Tolinski
we're working on right now.
Scott Tolinski
Prisma. And I can't say that doesn't count for something because when I look at Prisma's website in their docs and everything, it goes it makes me wanna use Just based on on those things alone. But in my experience with Prisma,
Scott Tolinski
like, No. This couldn't be. And it's TypeScript's always right about it. And I'm like, no. This will never be undefined. But it's like, oh, I guess it could be. Again, I guess. Yeah. So true. So the different node ORMs that I've I've really pod through and and these are the, like, the most popular ones that I've really found being talked about. So if there's other ORMs out there, I'm sure there are maybe almost even a popular one, given that, you know, I've only used a couple of these myself. But Prisma really seems to be The top dog these days. And, honestly, systems Therefore, you can't get into any invalid data situations or stuff like that. Rid And many things like Ruby on Rails, you know, migrations is one of the first things you learn. So my first experience with database migrations was via Ruby on Rails. So, rid. I'm sure many people who have picked up Rails have done the same thing.
Scott Tolinski
I'm I'm a easily influenced kind of guy in some ways. And if you go to all of these websites, Prisma has the nicest website, the nicest documentation,
Scott Tolinski
like the overall most polished product award goes to
Scott Tolinski
the best marketing presentation, Hassle free
Wes Bos
yeah, it could be. You have to write an extra 11 lines of code to handle that case.
Scott Tolinski
Like,
Scott explains ORM is a translation layer between a database and application code
Scott Tolinski
relational mapping. Basically, it's the way that you can work In, database systems
Scott Tolinski
rid. You either use an ORM or you end up building your own because at the end of the day, you just end up needing some of the abstraction so to say. So it definitely is one that's gaining a lot of hype right now and and people are starting to pick it up. Ready. I think it could be a cool option, but again, it's fresh.
Scott Tolinski
layer between the database
Scott Tolinski
these raw queries whether it's raw SQL or whatever. I'm really good writing, or like that would like that person to leave. So there there's always, like, kind of 1 person that's the focal point of, like, causing everything about comedy and TV for me. So, yeah, it's very funny.
Scott Tolinski
And the language that you're working in.
Scott Tolinski
with the normal language. So it's like it's like a translation
Scott went to the dentist early in the morning
Scott Tolinski
ruined from the tongue piercing, and now it's like I I just, like, Think about it for months. So I'm already thinking about my next appointment in 6 months from now. So I'm going to have to have to do something about that. Oh, yeah. I always feel like rid. I let our dentist down. You know? Like Oh, yeah. Ours is just like, ours ours cares so much
Scott Tolinski
Bright and early. We had to wake up at, like, 5:45 it's just gonna continue to get worse, and it's already I had to use, like, an app to track When I was flossing my teeth, now they, like, tell all their other clients, oh, we had this 1 guy who was using an app to track his flossing, and I'm I'm used as, like, the model dentist citizen now. Oh, man. That's rid. Yeah. They're big fans of me.
Scott Tolinski
I'm wide awake because I went to the dentist this morning, like, first thing. The kids' dentist appointments were, like, You need to adjust.
Scott Tolinski
to get there, I gotta say my experience with it has been is very, very positive overall. Like I said, I'm loving that linting going. It works with Postgres, MySQL, SQLite, SQL Server, Mongo, and Cockroach. I've only used it with MySQL so far, But,
Scott Tolinski
it it has ruined my life for too long now where I'm like, I just rid. I I just dread going to the dentist. I don't I don't care about the cleaning. There's just, like, 1 specific spot that was, That can warn you about specific issues across very specific domains, pull me in to Drizzle right now in terms of I mean, it's it's lightweight. It's 0 dependencies.
Scott Tolinski
rid. When people tell you that a tongue piercing will will ruin your gums, you're structuring out your database or your data in a way. Right? Rid. And that helps with all those things like, what that data looks like in the database, what type of fields in the database relate to the different fields. Therefore, you're not passing a string into a number field
Scott Tolinski
maybe not in the 30th. What I what what I did is I had a tongue piercing for about, like, 8 years or so. And, If you're wanting to have, like, a passcode that's 5 digits or something. You're right. It won't fall within. Yeah. But it would do. It would if, like, you're, like, changing, and a model can use those words in in kind of different ways. So like Drizzle has a schema their numbers of What things they support? But they support Postgres and MySQL, SQLite,
Wes Bos
rid. Like, I come and I almost want to be, like write the migration
Scott Tolinski
just to get everybody out the door and they had school and stuff. So to make sure everybody is ready. Yeah. Yeah. We had to get up nice and early. And, at first, you'd think I'm a little sleepy. But, man, I
Wes Bos
My name is Wes Bos. I'm a developer from Canada. With me as always is mister Talinsky. How are you doing today, Scott? Ready. Hey. I'm doing good, man. I just, I didn't bring the card a credit card out of my pocket the entire time,
Wes guesses the first ORM was developed in 1971 by IBM
Wes Bos
something
Wes Bos
I was going to say
Wes Bos
where they needed to rid. Right. A layer on top What what do I say? Schema. Schema.
Wes Bos
with IBM then run. It does not work for
Scott Tolinski
the 1st ORM like system was developed?
Wes Bos
1971, that is unless you're, like, very good at that. I actually used to work at a job when I was in University. I had a co op at a bank,
Scott Tolinski
Rid. What year?
Scott warns about creating deeply nested GraphQL schemas without DB understanding
Wes Bos
which is a string, right, 6 or 7 different lines of code. So I've been sort of going that way. I used to use these, like, disk DB packages that would just give you kind of a lightweight database.
Scott Tolinski
but not possible in in my sequel. If If you wanna do it this way, you need to create And whether or not you're kind of authoring it yourself or whatever. And I actually fell into this trap myself when I removed Mongoose from our stack, which we'll talk a little bit about what that is and stuff. But I removed Mongoose from our stack to use the native MongoDB driver. And then I ended up using Xod to do my schemas. And the next thing you know, I'm doing my validations.
Wes Bos
one of these following strings. You had to create an entire separate Today, we are going to talk about what rid is an ORM. It's all about databases,
Wes Bos
like in my SQL, you said, like, okay, this is just a what is it? Varchar,
Wes Bos
like, it has to be Yeah. I was just going to ask about or talk about the validation is like, this is not something that is
Scott Tolinski
rid. This particular field, which I would like to query off of, can can only be one of these following values. And The Prisma scheme was that, hey, that's not possible. The way you're trying to do this is not possible with my sequel. It's possible in Postgres, Yeah. But
Wes Bos
of a certain size,
Wes Bos
and you're not able to say,
Scott Tolinski
the role system in in the new syntax site. I just wanted the roles to be like a string value And I want it to be like an Enum. So it could only be one of the following values. So when I'm mapping out the database, I saying, all right, this, Drizzle that you might appreciate, Wes, is that they support So level up tutorials, when we were on Mongoose, I had to define my types themselves. That's like kind of 1 model. Mhmm. Then I had to define my Schemas
Scott likes Prisma's ability to lint schemas for database compatibility
Scott Tolinski
rid. Helps me write my sequel in a more complete way, but it's also saving me headaches down the line
Scott Tolinski
is that there's a Prisma specific linter
Scott Tolinski
database domains. For instance, if you're doing something with Prisma in a way That isn't compatible with MySQL verse Postgres.
Scott Tolinski
You you can't do a relation this way using my sequel because it understands so much about the underlying database technologies and what you're trying to do. So for me, having that linter there not only, NoSQL database system, so it's it's very much a SQL in that time is because, Not only that, it also allows you to, Yeah, because you got the Sch.
Scott Tolinski
It's going to tell you, hey.
Scott Tolinski
rid. In actually mapping out the relations in my database.
Wes says sharing schema types with GraphQL avoids duplication
Wes Bos
you have to understand that there's there's a poor old database somewhere running 900 queries every time you call that thing And joining all the data together is a possibility that you write something that's Let's talk about, like, why would you want to use
Wes Bos
If you just give somebody a GraphQL API and you say, go nuts, you can nest these things 400 levels deep rid. When in reality, like, you're like, all right, well, I built my database schema. Now I want to generate types off of that.
Wes Bos
is that you might not understand requests per second. Armin was saying, you know,
Wes Bos
not very performant.
Scott Tolinski
Yeah. And then save me. I mean, I was doing, like, the roles,
Wes Bos
That's that's awesome. I didn't realize they had that because that's one of the downsides
Wes is intrigued by Drizzle's serverless and inferencing capabilities
Wes Bos
Serverless databases, to just the same as you can Mark a property as read only.
Wes Bos
You simply just send an HTTP request to the database Wise. So we have a business account on Wise and a personal account on Wise.
Wes Bos
Drizzle lists PlanetScale separately is because
Scott Tolinski
I'm on the the wrong the wrong page here. But it thing about databases that most of us are building
Wes Bos
PlanetScale The fact that you can configure the whole thing in
Wes Bos
Ready. It's HTTP focused, which means it works in serverless.
Wes Bos
But with serverless,
Wes Bos
uses Man. Yeah. I don't know. That's a great question.
Wes Bos
supports like duck out to aggregations. And like writing aggregations
Scott Tolinski
HTTP version under the hood, which is cool. Okay. Okay. I take it back. K? I've learned my lesson there. No. I I think Drizzle is a cool option. And like I said, I I haven't used it yet. I I definitely can can be easily swayed. This this definitely could be me being, like,
Wes Bos
So we've done go back to the episode on where we talked about
Wes Bos
their sorry. Their PlanetScale implementation That show seems to be one of those shows where
Wes Bos
you don't I find it even more now that I'm teaching my kids to spell. Oh, God. So many times we're teaching them, like, there's Schema. People always say I say a funny schema. You do say it. Yeah.
Wes Bos
stuff
Wes says he often removes packages but ends up rebuilding them
Scott Tolinski
falling into that trap repeatedly.
Wes Bos
I just made my own.
Scott Tolinski
That that to me is like the, hey, don't do that. Ouch. Oh. Oh, hey, don't ouch. Like me just doing that repeatedly.
Wes Bos
rid. Wake up 3 days later. You're like, shoot.
Scott Tolinski
I know. And you know what? Rid. I I I don't know. There's something about my personality, but I find myself Somebody is put into a situation where other people are are getting uncomfortable and would like him to leave, Every major server full and serverless runtime. So they support Bun. They support,
Wes says most databases today are MySQL, Postgres or MongoDB
Wes Bos
random databases, the server side database stuff is not necessarily what should be
Wes Bos
rid. Kind of going with all these rid PlanetScale's own database JS driver, which is So instead of just raw SQL query. Yeah. It's HTTP.
Wes Bos
they made or something silly like that.
Wes Bos
But it's connects. It's, like, like, connecting.
Wes suggests Wise cards for easy travel currency conversion
Wes Bos
experience. So check it out.
Scott Tolinski
Wise. Not the, Guests select guest equals true. And, like, that's it. That's the entire relation query. And and maybe it's just that I'm not used to writing queries in a relational database. No, it's actually impressive.
Wes Bos
like, which account to take it from. I only had I had Canadian and US, Okay. I guess that's funny. That's what that show is, is if people don't get it, they don't get it. They don't get it. Yeah, I know. And it's not their humor.
Wes Bos
there's tap everywhere in Europe and there's no limit on it. So and whatnot. But that's not something that I am good at or necessarily want to do anymore.
Wes Bos
You just tap is like the lower level, like the database level type of thing, whereas a model is day. Oops, I did it again. Don't you hate that where you're like, I don't need this package? And then you
Wes Bos
you. They give you these, like, virtual cards. They give you physical cards. I didn't take them along because both because Europe is amazing for that.
Wes Bos
And I said, do you want to upload the receipt? I was like, you're I do want to upload the receipt wise. Thank you for that. And then you take a picture, throw the receipt in the garbage. You're all done.
Wes Bos
Rid. And just being able to, like, convert it and, like, it immediate for my business ones, it would immediately send you a push notification, But it almost never makes sense. Because if you're going straight into the database,
Wes Bos
this is such a good
Wes Bos
And at whatever the rate is. And like the wise the wise rates are so good. And I was like, this has been
Wes Bos
Rid. Just such a great experience. And every time I use it, me and my wife are just like, Is that what the guy Tim Robinson? So on on connextjs.org, have an ongoing connection.
Wes likes that Prisma generates types from the schema
Wes Bos
you don't have to rid. Duplicate your types for
Wes Bos
type. A password field shouldn't be on the client side. So do you also use those types on the client? I I do personally. And in fact, I I kind of ran into
Wes Bos
put to the client as well. I think the most simple example is a password
Wes Bos
also put those into your GraphQL types, which is really nice. So now you have your types sort of rippling through. And then The 4th place, I guess, is like your client side types. So
Wes Bos
And you can often
Wes Bos
Make additional because sometimes gives you a whole UI for searching and filtering What are you talking about? What's that new show that's like Portlandia?
Wes Bos
do you also share your client side types or
Scott explains migrations keep the database updated over time
Scott Tolinski
But at the end of the day, a lot of these tools make a migration really simple because what you're doing rid. Is you're changing rid. You know, it's a product that's seeing updates all the time and stuff like that. So, hey, I I find it to be fascinating. I
Wes Bos
the migration?
Scott Tolinski
And, in fact, any time that,
Wes says WordPress doesn't use raw SQL queries
Wes Bos
rid. Stop and say, how do I do this in the the WordPress way with custom post types and fields and all that good stuff? Yeah. It seems like every mature system like that Has like, let's say you have You can get up and running
Wes Bos
doing WordPress things. You're probably doing something that is outside and you should
Wes Bos
it means you're probably not Is nicer, like user dot create
Scott has a tendency to want to build things himself instead of using existing packages
Scott Tolinski
rid. Data models to a language that you're using, an ORM has been there. And one kind of benefit of an ORM is often the different ORMs tend to discuss these days is just really great. So having it completely up and down your stack to the database I am a little weirded that they rid. Have, like, PlanetScale separate from MySQL here considering I hate rid Zolin. It's not production ready yet as, like, a joke. That really turns me off because it makes me feel like this product's not serious. And, like, I get it. I think it I think in some degree, it's funny, and I think a lot of developers will look at that and think it's funny. But, like, for some reason, I For some reason, I look at that and I put my, like, serious old man hat on and be like, I don't like it. And I I don't know why. I couldn't tell you why I don't like it. It just for some reason, whatever. Rid. It's fine. I think Drizzle looks like a cool new option to use. The reason It was really tough. Now And that's just kind of par for the course with Sentry. And, you know, I've been using their their tools for a long time, but I was really quite impressed by the user flow of up and running a new project
Scott Tolinski
But ORMs, they they've been along around for a very long time. Basically, anytime you need to map, and then the ORM will be generating schemas. But I don't I don't know if that really matters all that much. Well, it's funny that Some of some of the ORMs do refer to the model as a schema. A schema. It doesn't help. Yeah. It doesn't help. I know language. Right? It was like Yeah. When I was trying to look up Things for, like, model modals and popovers and and all that stuff. It was like, man, there's just either a lot of nuance here or things being named the same way or whatever. So, JavaScript plain English that many of us are really familiar with when just Writing straight up JavaScript overall.
Scott Tolinski
Prisma for our ORM on the new new syntax site. So we'll we'll talk a little bit about different rid. ORM options and JavaScript and stuff like that in in just a bit.
Scott introduces topic of database schemas
Wes Bos
schema and model.
Scott Tolinski
and that's the type of word you're going to be looking for when you're looking into these systems.
Scott Tolinski
structure of your data, webhooks. It gives you a lot more than a typical ORM would. So it it it it's a much bigger service than what it nor am would typically, and then you're running a CLI command, and then it's generating your migrations for you, and you just, like, don't need anything. And rid. What does Prisma output for
Scott Tolinski
Those types of properties or even default values are often defined within the model. So that that if you hear the word modeling or schema or whatever. Basically, you're just thinking about
Scott Tolinski
Okay. So we kind of talked a little bit about this before. And just to elaborate upon that, Some of these things refer Supabase even, but they don't support Mongo Or or anything like that. Did you support Web SQL Lite? You know, and I've used
Scott says Figma had massive scale on a single Postgres instance
Scott Tolinski
All of that stuff. So Deno Deploy. So, yeah, if you're looking for like a really forward thinking ORM, this one seems to be it. I know that it's Still a little bit new,
Wes finds Mongo aggregations very difficult compared to ORMs
Wes Bos
when you're like, oh, I need to do this in a different way. Let me just scrap the query I've been building and move entirely to it In aggregation. Right? That's it's a bit odd that you have to you're essentially writing 2 DSLs or or 2 ORMs at that point, and that's that's really annoying to have to do that. Totally.
Wes Bos
You shouldn't have to, like, stop and give up
Scott Tolinski
Something like a relational database using Prisma or any of these other ORMs.
Scott Tolinski
the compass and use their UI
Scott Tolinski
on. Yeah. Even just to do a simple lookup
Scott Tolinski
where with SQL migration. So it has the stuff. It works with seemingly everything. Although, for a full archive of all of our shows.
Scott Tolinski
The way in which you do a relational query or anything like that is as simple as, like, Include this field, that it would lose some of its, Luster in a way and especially like I think even like episode 1 of season 2 people are like, oh, wait. This kind of feels already like a retread. Be Like has it like can even do more and then like you're
Scott Tolinski
To write my aggregation because it was way easier to tell what was going Using like a subcomponent, and I'm passing that data into a subcomponent.
Scott Tolinski
and then it
Scott regrets not using migrations for database changes
Scott Tolinski
enough is whatever. 2, it could give you less control if you especially if you're used to writing, rid. SQL queries or queries in general, you can feel like you're giving up a lot of control going to an ORM, but most of the time you're just having to do it their way instead. And many of the times they give you In escape hatch 2. Right? Raw sequel. We've already had to do that, once.
Scott Tolinski
I know that that can be a thing.
Scott Tolinski
Sometimes there's a performance overhead.
Scott Tolinski
it handles the hosting of the database. It gives you sure, Sure. It gives you those crud operations and allows you connect to your database and stuff like that, but it gives you auth. It gives you I don't know if you've gotten to that one. He's like, hey, there are shirt brother because they're wearing the same shirt. No. No. Either way, there's a lovely song that you're gonna like at the end of that episode by a pop punk band that you'll you'll enjoy. Ready. Oh, I'll check that.
Scott Tolinski
people might ask about Supabase. Is Supabase rid. It's an ORM. It's not really it does weigh more than an ORM does because
Scott Tolinski
Nest JS. Anybody who's used Nest JS will have Use Type ORM. It's a TypeScript one. Works with MySQL, Maria Postgres, my Microsoft SQL, Oracle Cloud Spanner, and then rid. Which is the ORM from sales, which is the rails kind of equivalent of I cannot get enough of that show. I actually watched the entire 3rd season again last night for Father's Day because I was like, as my father's day, I'm gonna put on,
Scott Tolinski
some some bit of latency there, whether that is Specifically, technical reasons why. And, hey. That's fine. It's not a deal breaker. So for me, Prisma is is been a really nice option. And and definitely, like, Nobody's gonna get fired for picking Prisma these days. It it works really well. And the the things like the migration tools, which we'll talk a little bit about migrations later on, migration tools are excellent. The, CLI is excellent. The they have a nice little visual studio own DSL. It's like a Prisma schema, right, where you're writing these Prisma schemas.
Scott Tolinski
That seems like a thing that they're really emphasizing with Drizzle is that it's very performant.
Scott Tolinski
What are the potential downsides to using an ORM? somewhat easy.
Scott jokes about the number of companies with owl logos
Wes Bos
Rid. It was like, when you see another developer I recently went to Europe
Wes Bos
about that. I'll tell everybody about the hilarious,
Scott Tolinski
a. All right. Well, I am going to sick Can't do that. There's been like an open issue on GitHub for like. Oh, really? 7 years about that. Rid. Not that long, but forever. It's like the the longest standing open issue on Prisma. It's like, hey. Can we, split these up into different files? Probably because it's it's, like, statically analyzed. Right? Like, you can't. It's not JavaScript.
Scott says models define data structure and schemas represent it
Scott Tolinski
A migration basically, if you don't know, is when your data changes over time, which it often does. You need to add a field, change a field, remove a field, anything like that.
Scott Tolinski
A migration makes sure that your database stays up to date in terms of, like, What where things or how these changes have been applied to your database and what those changes are.
Wes says non-native English speakers speak better than them
Scott Tolinski
It's wild. You know what? I wonder yeah. It's like linguist know the pronunciations guide, But, like, those people are gonna probably guess correctly how to say the word in the 1st place.
Scott Tolinski
Oh, yeah.
Scott explains Prisma strengths like schema linting and nice docs
Scott Tolinski
it gives me those linting errors. One thing I do like about it is that you do just define your schemas all right there. Now I don't like that you can't break up that a file into smaller files.
Scott says mature systems tend to have good ORMs
Wes Bos
generates the types. So just the best because
Scott Tolinski
The the queries that you're writing, the the code that you're writing can just be written in straight up JavaScript. You can throw it into a function and have it be nice and easily reusable, put in your variables, Whatever. It feels just like writing JavaScript or TypeScript because it is. Right?
Scott Tolinski
So it it always seems like anytime that There's a mature system with a database. There's a mature and good ORM to go along with it. Another nice thing is that it makes things a little bit more reusable.
Scott Tolinski
code to connect to your database. It helps you occasionally write more performant code. It helps you write better code overall and it helps those connections take place. What about can I can I just ask you about the types as well? So something like Prisma Yeah. Database schemas.
Wes keeps researching Drizzle's capabilities
Scott Tolinski
a specific You can use zod with it. Should I rip out rid Charisma and go with, Drizzle. No. I don't I don't think so. I'm just I'm just trying to think of, like And it includes an object with only 2 properties in it.
Scott Tolinski
I'm just looking at how to actually You're getting swayed. Yeah. Well, I'm I'm not getting swayed, but Like, I I was telling you before the show started, Migrations were a topic that I was like, this seems like so much extra work for me that I don't understand why I have to do this. But then after having a database that existed for 10 years rid And something that started off as playlist ID, which was initially referring to the YouTube playlist ID.
Wes Bos
Oh, Oh, that makes sense. They just have a bunch of, like, kind of, handy things to infer your types from uses the rid.
Wes Bos
I'm gonna do a quick little example because that would be You may have heard this term thrown around a lot. So no matter and PlanetScale if you are outside of your validation library, the fact that this ORM sits on 2 totally different types of databases, And you could do the exact same thing in both of them, but what trouble are you going to run into at one point where you rid People say the same same thing with GraphQL.
Wes Bos
rid. Sorry to come back to the drizzle stuff, but I am,
Wes asks if ORM schemas are written in the ORM's language
Scott Tolinski
Language or is that just sometimes? Yeah. So we'll we'll talk about this a little bit later. I have a section called DB Schemas. And the only reason, Yeah. How How many of these have an owl as a logo? That's The the reason why is because it was iterable primitive.