I came across an interesting issue. I've had a habit a long time ago to store my boolean values as 1 and 0 in the database, it has many advantages. However I came across a silly trouble, that took lot of my free time to work out. (I'm the kind of coder, who has a backlog but able to work on an issue for weeks if I find the logic to be dodgy, sometimes even change the code back to database level if I feel that'll help me in the long run.)
The trouble is - or correct me if I'm wrong, I looked it up and found no solution - that a html checkbox doesn't understand 0 and 1, it returns false for 1.
I've got lots of switches in my application, that can be turned on and off so the best is to handle this case for once and for all. I am considering testing storing simply boolean values and see what the api returns to the frontend.
How do you store your booleans?
Update: I've tested the mysql boolean, and it returns 0 or 1 LOL.
Update2:
Sending true/false to the database is totally cool, returns no error, stores as 1 and 0. So it doesn't need to be 'translated back' to int from true/false.
I think you're able to use the BIT type in MySQL, which also has the boolean type. Didn't take long to find on a Google search. Stack Overflow has several threads on it over the years.
dev.mysql.com/doc/refman/8.0/en/bi...
When reading your value back from the database, cast it into whatever your UI needs. Usually there's a layer of logic between the crunchy data stuff and fancy interactive UI stuff.
In something like Sqlite which has very limited types available, I go with the text option 'true' and 'false'.