Complete Intro to SQLite

Alternatives to sqlite3

Complete Intro to SQLite

Check out a free preview of the full Complete Intro to SQLite course

The "Alternatives to sqlite3" Lesson is part of the full, Complete Intro to SQLite course featured in this preview video. Here's what you'd learn in this lesson:

Brian shares libraries that can be used as an alternative to sqlite3. Some libraries extend the APIs for sqlite3. Others are ORMs which provide an abstracted set of APIs.

Preview
Close

Transcript from the "Alternatives to sqlite3" Lesson

[00:00:00]
>> Brian Holt: So now that I made you walk through sqlite3, the base default original sqlite3 client, I went ahead and linked to other ones that you can use. Eventually, hopefully by the time I do v2 of this course there's going to be a built-in sqlite client to node JS.

[00:00:24]
It's just gonna ship with it starting in 22, and we're in 20 right now, right? Yes, I think we're in 20 right now. Yeah, you can see this is active developments. You can try it right now I thought about making you try it, but getting people to start no 22 with experimental flags seemed a little dicey to me.

[00:00:47]
But eventually you're gonna be able to do things like this, and it's just gonna look a lot better. Yeah, you're gonna do a database.prepare. You're gonna insert all your values into it and then you can just run the query, and it makes this like reusable object that you can run multiple times.

[00:01:04]
It's a it's a nice way of doing it. Bun already does this, if you're familiar with bun, which is another JavaScript runtime. I think Denno has their own as well, so I think that kinda puts some pressure back onto the Node core team to like, hey, maybe we should adopt an internal sqlite client.

[00:01:27]
They've always kind of had this thought process on the Node team, that like, let's the community do it, let's not prescribe anything. But this one seems useful to me. So that eventually will be what I would suggest all of you use. If this is available by the time that you watch this video, use the official Node 1.

[00:01:54]
>> Brian Holt: The second most popular as far as I can tell is Better Sqlite3. I'm not gonna say that it's necessarily better. I do use it probably the most. They purport to be significantly faster. Sure, it's already fast enough for me. They had this ability to do the prepare thing which we were talking about.

[00:02:21]
You can do pragmas, as we talked about earlier. They have a promise library built into it, so you can do promises, I think, pretty sure. And the one thing that SQLite 3, just the normal one that we were just using, it doesn't have the ability to do queries sync, which basically means like run this and pause the entire runtime until this is done and then continue.

[00:02:52]
Usually that's not what you wanna do, especially if you're doing like web services. But if you're just running a script, it actually is nice like, hey, do this wait, do this wait, do this wait, do this wait, and then now you're done. Better sqlite3 can do that, no problem.

[00:03:06]
Sqlite 3, just a normal one cannot or doesn't have a easy way to do that, I should say Yeah, Promise sqlite3, I've used this one a couple of times It really is just the exact same thing, but they have promises. It's really just a very thin wrapper that allows you to do a sync await and stuff like that.

[00:03:31]
>> Brian Holt: That's probably a good time as any for me to talk about ORMs and my love-hate relationship with them. My experience is primarily with old Django ORMs or specifically, the Django built in ORM back in 2013 I think when I was working at Reddit. It does some things really well for you.

[00:03:56]
It does data migrations and some other things. But it also makes a lot of things really hard. And so an ORM, if you're not familiar, is basically a library that lets it so you don't write sequel, it does, right? And so you say, database.createobject with this information, and then it generates sequel and it runs those commands for you.

[00:04:19]
Ten years ago, I would have told you never use an ORM, it's not worth it just learn sequel. Get good, essentially, is what I would tell people, skill issue. I don't think that's true anymore. I think Prisma and Drizzle and even sequelae have come a long ways of making ORMs a much more desirable thing to use, particularly Prisma and Drizzle.

[00:04:43]
I haven't used sequalaes in a while, but I'm told that it's gotten much better over the years, pleasant experiences and come recommended from people that I trust. I'm not gonna talk about them today, cuz I really couldn't tell you too much about them, cuz, again, I've been writing sequels for so long that I'm just kind of stuck in my ways at this point.

[00:05:02]
But you should have a look. Yeah, and then, in that case, you wouldn't include any of these. You would just interact with the ORMs then query your database for you. All of these have sqlite clients, I think I even,
>> Brian Holt: Yeah, so this one starts with SQLite you can see.

[00:05:29]
>> Brian Holt: Yeah, so you can see this one works as well with Turso and Bun, React Native, Cloudflare, they all work.
>> Brian Holt: Things to just keep an eye on with ORMs, like you'll do something that you find very straightforward and you think, this should be a nice fast query.

[00:05:50]
And then you find out that your ORM is doing something bananas, right? And that was my experience is like, they'd run these big weird queries. And so I'd find myself fighting the ORM, which defeats the purpose, right?
>> Brian Holt: But they do handle things like data migrations, which are very hard to handle yourself.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now