how to store actually boolean in mysql instead 0 and 1

Please, is there any way to enforce Boolean to be stored as true and false, not 0 and 1 in mysql I am uisng prisma × mysql
3 Replies
Brendonovich
Brendonovich2y ago
no 🙂 mysql doesn't have bools, only ints
Glorrin
Glorrin2y ago
You could go to paint, create a realy big image write true on it, create another big image writing false on it, and store those as longblob in your database. Sarcasm aside what is wrong with 0 and 1, and what is the difference with true and false ? The role of your database is not to store your ui only data. for boolean it makes sense to use 0 and 1. If the boolean is nullable you even have this option: 0, 1 or null. If you don't like looking at 0 and 1 on your ui change the ui not the data. A terrible way to solve your issue would be to store it as string "true" and "false" but why would you do that ? Maybe i am misunderstanding the question and your issue is with prisma not mysql but you will have to share where your issue is within your code. An example would be nice.
Brendonovich
Brendonovich2y ago
I don’t think the ui side matters in this case - prisma automatically casts MySQL ints to js bools for you so the only place you actually see an int is in the SQL It can just be a bit unexpected if you don’t know that is expected behaviour
Want results from more Discord servers?
Add your server