YouTubevideo· Aug 4, 2025· 9:43
So, I'm not a database expert and that title that you clicked on, it might have been a gross oversimplification, but really when it comes down to it, it makes a lot of sense. And so, I wanted you to join me to see, okay, when do I actually need booleans in my database?
Is it as complicated as I'm making it out to be, or can you use something else? Thanks so much to Bento for sponsoring this video. This whole idea stems from this tweet I saw a little while back. You probably shouldn't be using booleans in your DB schema. Use datetime. And uh it got a little bit of attention and a lot of people upset.
And I'm not someone who gets all upset because, oh yeah, I really wanted to use booleans and not date time, but I honestly wanted to take a look and see, okay, can I do most of the things that I usually do within a database using booleans, but can I actually use datetime instead? And so, while this whole Twitter thread is chalk full of uh people on both sides of the aisle saying, "Hey, this is right or this is wrong," or maybe in the middle of, "Hey, this is right."
For the majority of the time, I want to do a um mental exercise with you, taking a look at most applications that you might build or that I might build and see, okay, do I actually need to use booleans? Should I stop defaulting to booleans? Which I think that's the key word right there.
And then when should I use datetime? And when does datetime fail? All right, the basics of basics, the to-do app. Let's say for the most part you usually have a hey I finished this and then I didn't finish this. Those are the booleans of like it's done and if it's not done if that is not true or maybe completed
then I don't know then it's null and so what would this look like with date time instead which provides uh agreeably a little bit more information especially for something like this application because then you have uh completed at you have a completed at date time or you could Okay. Okay. Now, without having to use another column in my database, I can say this to-do was completed at this time.
Okay, that works great. But like most people in the comments were saying, well, what happens when you have a to-do that is uh done and then maybe it's not done and then it's done and then it's not done. and just keeps going back and forth. The the toggle of this completion is a boolean because it is a toggle. But let's ask this question.
How do you know when it's been turned on and off in a standard application? I think this is when you need to think, okay, what applications do I need this extra context? And then that's when you would move to something like event sourcing. And there's a great Laravel package called Verbs that I've taken a look at uh in very minuscule depth, but it is really interesting. But I think event sourcing is when you actually do need that extra bit of information.
You have this toggle that is going on and off, but I need to know how many times did this person complete X, Y, or Z because maybe it's not a to-do app. Maybe it's a uh a status application. So you have a forum or a uh you know a a polling application where you need to check how many people are active.
Okay. Well, you also need to check when were they active because you can you don't just need to know the number of people. You also need to know when they were active. So this person was active last week but they were also but they were not active this week. And can you do that with a a date time?
Eh, maybe if you could say um you know active at date and then you could say okay the last time they were active was you know last week and you can make that calculation based off of the date in that datetime column.
uh you can make them null when it's not active or you could just leave it as active at and continue to update it when they become active again. But maybe that doesn't necessarily fit for your application.
Here's where the mental gymnastics that I want you to kind of think through now of okay, am I getting more information if I use a date time than the flexibility that a boolean provides? And to be honest, ever since I saw this tweet, uh, I've stopped using booleans for all of my applications because I just realized I don't necessarily need them.
Every single time I think I need something like a false or a true, usually the date time provides the info that I might need because then I know when something has happened when it become when it changes from the null status into a uh an active status we'll
call it because then I know hey whatever I'm trying to find information on for my user they didn't do something whether that is uh you know they they mark something complete and one-time activifications automatically just like I said usually for the most part they fit better within this datetime structure but even if they mark something complete and it's a toggle kind of status uh if it's active
I know when it was active and I automatically get this extra bit of context that I otherwise wouldn't have with just booleans. So, should you stop using booleans? Um, yes. No.
What do you think? Before I give the answer of when you should absolutely use booleans, I want to hear more from our sponsor. All right. and send. Perfect. All right, user number six just signed up. Hey Siri, you set a timer for 10 minutes. We need to get this drip campaign out the door for new signup.
Hey, what are you doing? Who else is going to send these emails? Every single minute, I need to watch to make sure my users are signed up so that I can get them emails as promptly as possible. That's why I got timers. I just use Bento. They have workflows and triggers specifically meant for those kind of automations.
Yeah, that sounds better. Seriously, Bento is fantastic even if you only use a small part of it like I do. My favorite feature, being able to automate my email flows, saying once something happens in my code, and of course there's SDKs for literally everything. I can say I want to wait a certain number of time and then I want to send or this email or start this campaign.
It just makes the things I want to do within my application easier and it makes it better for my users because I don't have to bother them as much as I would otherwise because all the automation's built in and flexible for my use cases. So seriously try Bento, let them know Josh Siri sent you and get started with it today. So here's the answer that really brings it home. It depends.
Really, you shouldn't stop using booleans. at least you shouldn't stop unless you know the reason why you're stopping. For me, the reason why I haven't written a single boolean again is because I just like the simplicity that it brings of having my this mental model of okay, when I do need that extra context, especially for things when I maybe want to keep track of something for the user, I don't have to have multiple columns that I'm kind of bouncing back and forth of when a column was updated or having to dive into event
sourcing for just one little part of an application. And so when this user says, "Hey, this is an overgeneralization of something that might have been a good idea in somebody's side project," really that user is correct. And so yes, using datetime and stopping using booleans might be great for you in your particular use case.
And maybe it's something that you shouldn't even think about because if you do need that extra little bit of context, maybe you need to dive even further into the event sourcing into keeping track of when something has turned from false to true.
And then you get to start knowing as you're building, as you're making things of being evaluated, evaluating when you actually might need something within an application. Because that's what it
really comes down to, knowing the ability in your mind to say, hey, this is why I'm making something and this is why I am not using something or using a particular project, using a particular uh library, using a particular framework. know why you're using it, but even more importantly, know why you're not using it. So, stop using booleans, maybe uh but start using the things that make sense for you and your project as you build. So keep creating.