Skip to main content
View on YouTube to comment and like!

Syntax Video

The Latest Drizzle Updates are AWESOME | The road to v1

Chapter 1 0:00

intro

what's up CJ here drizzle omm has released some new versions over the past couple weeks and in this video we're going to talk about them now if you haven't heard of drizzle they are a typescript focused orm and they are really great I have used them in all of my most recent projects and they're a joy to work with so some of the biggest updates you'll see are defining tables has gotten a whole lot easier and then also they have a new way of defining the drizzle connection that reduces a lot of boiler plate and so about 2 weeks ago they released version 0.34 and this got them about 40% of the way to version one so the team is working hard um they're doing as much as they can to get closer and closer to V1 now another major upgrade that happened was an upgrade to the documentation and personally this is one of the biggest gripes I had and a lot of people had with Drizzle is the docs were a little bit confusing to get into but they changed the information hierarchy they removed a lot of duplication they made it easier to hide and show stuff easier to find stuff and so now it's really great so I highly recommend if you haven't tried drizzle and maybe you tried it in the past and you couldn't figure fig out cuz of the

Chapter 2 0:25

40% towards v1

Chapter 3 0:37

new docs

docs go to the docs right now om. drizzle. team and just check it out uh one of the biggest upgrades is they have this new getting started section so from a high level you can choose okay do I have a new database do I have an existing database what kind of database do I connect to am I using some kind of hosted provider and then for each of those they have a walkthrough on getting started from scratch inside of your project to talk to one of those databases so these guides are awesome and then beyond that the information hierarchy here is more flat and a lot easier to navigate so it used to be that all of these providers were kind of like nested underneath postgress or MySQL or sqlite and so was a little bit tricky to find and you had a lot of duplication of examples inside of there now it's nice and Consolidated so if you head into postgress this has a section on note postgress and then also postgress JS and then same thing for MySQL and then also sqlite but if you want to connect to a database that has a specific type of hosted provider then you can head into those docs as well so the docs are great now is the time to start using drizzle if you haven't yet and again now is the time to look at drizzle again if you kind of skipped it in the past because you didn't like the docs now about a week ago they released another version

Chapter 4 1:55

70% towards v1

so version 0.35 and this got them 70% of the way to version one so they've been working really hard um and they're getting closer and closer to V1 and in the next release they plan to support Ro level security and have a bunch more bug fixes as well now one of the updates that got introduced in version 0.34 was this idea of a mono driver and the idea that you could very easily connect to any database just by passing in the type of database you wanted to connect to and so that's this example here where you literally just import drizzle and then now instead of having to import your specific connection client and everything else you can just pass in the type of data Bas you want to connect to and drizzle handles the rest well it turns out there was actually an issue with having an API that looks like that and so there's a discussion on the drizzle repo that talks about why that wouldn't exactly work and ultimately that would have been a really nice API right so everyone no matter what database you're using you would have just imported drizzle from jizel dmconnect and then it handles the rest but this introduced some bundling issues and there was an issue with like Dynamic Imports and so they kind of scrapped that idea but there is still a better way to connect dat to databases you just

Chapter 5 2:10

monodriver canceled

Chapter 6 2:31

monodriver alternative

have to specify the type of database and so the old way of connecting was you bring in drizzle for your specific driver and then you bring in your specific connection client instantiate the connection client and then pass it into drizzle and it was the same way for every type of database no matter what kind of database you were uh connecting to but now in version 0.35 that same drizzle that you imported before can just directly accept your connection info so this removes a little bit more boilerplate right you don't have to Define that connection client you can just pass in your connection info directly and drizzle handles the rest if you want to specify more settings or more options there's now a connection property on that object where you can then pass in the rest of the connection information as well and then beyond that you specify all of your drizzle settings just like you did before now personally I think this is the best thing that drizzle could have done because it removes a lot of confusion and a lot of boilerplate right because if you go from one codebase that's using postgress and then another one that's using MySQL the code is going to look almost exactly the same right both of them could just be passing in the connection URL the only difference is going to be the import and so as developers become more familiar with Drizzle it's going to be a lot

Chapter 7 2:59

unified driver

easier to switch between code bases and a lot easier to switch database drivers if you really want to um so yeah I think this is a very welcome change I'm okay with the caveat that you still have to import from the place that has your specific database driver because when you're upgrading your code AS I'll show all you have to do is just remove the connection client code and then just pass that directly in now of course the old way will still work for now so you could actually upgrade to the latest version of drizzle not change the way you define the connection it'll still work but they are going to deprecate this way of defining it so that way in V1 you have to Define it in this more unified way now since then there's been a flurry of updates so in 0.352 they introduced approximately 240 tests uh that check for esm and CJs builds and compatibility and this is huge I think one of the things about building a library like this is if you're moving towards V1 and you want to show people that you are production ready and that your latest versions aren't going to break builds or break projects this is the kind of thing you want to see in a repo so this is awesome to see they've got lots of tests they're basically setting themselves up so that when they release V1 they're going to be production ready and they're not going

Chapter 8 4:25

move towards production ready

to be breaking apps that are out there in production and then one more update that got pushed pretty recently was a new lib SQL driver module and so before you would just import directly from lib SQL now you can specify the specific type of lib SQL client that you're connecting to like node web or HTTP now along with this idea of making the codebase more production ready moving towards V1 Andrew made a post that talks about what they've been up to so they actually transitioned to working full-time on drizzle about 6 months ago and since then there are 12 people working on drizzle development and another thing that he pointed out that something that I haven't thought of but actually makes a whole lot of sense and actually should give you some assurances when you're deciding to choose a library is they have a plan for successors so I didn't even realize this but GitHub has this way to define this inside of a GitHub repo where if for whatever reason a maintainer steps down or maybe they're not able to maintain a project anymore or maybe they don't want to maintain a project anymore um they can specify successors who can then take over the project and so if anything happens to the maintainers or they decide to stop working on it or whatever else there

Chapter 9 4:57

new libsql driver modules

Chapter 10 5:09

drizzle team is committed

will be a plan in place to make sure that drizzle keeps being maintained and stays active now all of this combined is is just a really good signal that drizzle is doing everything they can to make sure that they are production ready this isn't just some random Library they are real competitors in the space and definitely a legit choice for choosing your typescript orm now I want to show you where in the code things will actually change if you upgrade to this latest version and I actually have two different projects I have one project that's using lib SQL in a single table but it'll show you some of the breaking changes in lib SQL client and how you can update your settings to work with that and then I also have a larger codebase built with Drizzle this has 13 database tables all with relations and everything else and so this is a really good case study of what your codebase will look like if you upgrade to version 0.35 so first of all the changes in lib SQL client here it used to be in your Jizzle config that you specified a dialect of sqlite and then a driver of turo now if you're using turo you specify the dialect as turo so now there are four options for dialect there are sqlite postgress MySQL and turo instead and so this is a super simple change you

Chapter 11 6:10

example codebase upgrades

Chapter 12 6:35

libsql client changes

basically just swap out your dialect and remove the driver property if you specified it but that essentially allows drizzle to do the right type of inference and type checking whenever specifying DB credentials cuz DB credentials for turo can be slightly different than just plain old SQL light they also made some upgrades to how they do migrations and so for my codebase that's using lib SQL client it was super easy just change that dialect from sqlite to terso and then remove the driver property now the next major upgrade which is another quality of life Improvement is automatic snake casing so it used to be that when you define your tables you also had to pass in a string with the database table name and so you could think of it like the left hand side is how you access it inside of typescript and then the string that you pass in is what the column name would be inside of the database but you can see there's some duplication here right ID is the same name is the same description is the same the only one that's different is from cam casing to snake casing and so now in the latest version of drizzle if the column name inside of your database is the same as the column name you specify here you don't have to pass in that string so that actually removes a bunch of code and then if you do want to manually map the column to something else you can still do that but

Chapter 13 7:15

auto casing table names

they introduced automatic casing across your entire schema so you can see in my code change here I'm now passing in casing as snake case to my drizzle config and that means it's automatically going to take any camel case columns that I defined in my schema and then translate them into snake case whenever making database queries or generating the migrations and so you need to pass that property into the drizzle config because that's used when generating your migrations and and running drizzle Studio but you also pass that casing property into your drizzle instance and so that way all of the queries that are generated when your codes are running do the correct kinds of conversions from camel case to snake case and then they also support cam casing in your database as well so so you could have your codebase where you're using snake case everywhere but then it's caml case inside of the base you can you can you can mix and match if if you really want to and so to see those changes in this simple lib SQL client code base here you can see I'm passing and casing a snake case to my drizzle config and then also I'm passing in casing a snake case to my database connection and then looking at the schema basically I just got to remove code so everywhere I had specified the column name manually I just got to remove that and now drizzle takes care of the rest the other change here that I kind of hinted at earlier is

Chapter 14 8:49

simpler drizzle client creation

I got to completely remove the separate creation of the client now I just took all of those settings that I was passing in to create client from lib SQL and just pass those into the connection property that I'm passing into drizzle here and then I can remove the lib SQL import I can remove that client creation and so now there's less boiler plate right I can just literally pass in my connection info directly to that drizzle instance but now let's look at these changes in a codebase that has a bunch of database tables um so yeah one table that was fine 10 plus tables uh could get a little tricky and actually it wasn't for the most part it was a very straightforward upgrade now this schema is actually from a video that I did a few months back here on the syntax Channel called real world drizzle schema so in this video I show some patterns for working with a large code base like this when you're using drizzle because at a certain point having a single schema file with all of these tables doesn't exactly make sense and so I show how to structure that and also how to do more complex queries whenever you have lots of related tables like this but let's take a look from the top so this codebase was actually using postgress so there were no changes I had to make to the drizzle config everything just worked exactly the same after upgrading

Chapter 15 9:11

complex db schema upgrade

but the one change that I made was adding the casing snake case property so that allowed me to go through and remove all of the manual column names that I was passing in as strings because now those are going to be automatically inferred as snake case and then for the connection file very similar to with li SQL client I was able to remove this direct creation of a postgress instance and just pass those same settings right in as the connection object here on the drizzle instance and then of course we have to pass in casing as snake case on the drizzle instance as well now another change is I have a separate migration and a separate seed file which needed access to that connection to be able to close it after all of the seeds or migrations were run but you can see here we can actually get access to that underlying postgress client using dollar sign client and so if anywhere in your codebase you need access to that underlying client and it and not just for the case of postgress this will work for any database driver you can use dollar side client and then call any methods that you might need to so in this case I was able to call the end method on that underlying client and then from there all of my tables have been updated so you can see I've gone through and removed all of the manual specifying of these column names so this

actually cleaned up the code base quite a bit and I just went through and did this for every single table now one spot where this didn't work automatically is for my street add address columns and so you can see here that I decided to camel case this as streetcore address1 but the automatic camel casing that drizzle does is actually streetcore address one without the other underscore there and so because I wanted this to be purely a codebase change I didn't want to migrate my database I didn't want there to be any database changes at all I want my database to exist as it was but I just want my code to be simpler I left these manual specifiers here so that way I wouldn't have to migrate my database and so whenever you're upgrading your codebase you might come across a few Fields like that where maybe the automatic naming doesn't work for you or maybe you still just want to specify it manually and you can still do that one other spot where I had to specify this manually is here when I was defining a unique constraint so before I just called unique directly and it used the underscore names of the tables to create that compound key but after

upgrading that generated compound key actually used the camel case names whenever creating this big long name here so it was restaurant owner restaurant ID camel case uncore owner ID in ccore unique uh and again I didn't want any any schema changes so I went in and manually specified what it was before now I don't know if this was intentional by drizzle I'm going to open up a discussion to see that under the hood when generating these constraint names should they actually take into account the casing option I don't know maybe maybe not um but in this case they didn't and again I didn't want any schema changes so I specified it to be the old value and so that was pretty much it um now again like I've mentioned several times I did not want any actual schema changes I didn't want any migrations so after making changes I would generate a migration to see if drizzle actually detected any changes between my old schema and my new schema and I did this until there were no changes detected at all and so my codebase is up to date but I don't have any sort of migration or anything else so overall I'd give this on a difficulty

scale two out of 10 it was I didn't pull my hair out um it was pretty straightforward to even figure out what was happening with those autogenerated columns as well and so yeah difficulty scale two out of 10 but if you do want to upgrade I think it's worth it cuzz it reduces boiler plate and the code base gets a whole lot simpler so that's it for these updates on drizzle again if you haven't tried it out yet Now's the Time the docks are better than ever and I think drizzle is pretty awesome so definitely check it out if you would like to get your hands on a shirt like this check out cry. shop we actually have it for sale and $10 from every sale of this shirt actually goes to the drizzle team so if you want to support drizzle if you want to get some cool swag definitely check out the syntax shop all right that's all I have for you in this one I'll see you in the next one [Music] oh

Chapter 16 13:01

thanks

[Music]

Quote it with credit and a link. Quoting Syntax