loading...

re: Opinionated React - Use Status Enums Instead of Booleans VIEW POST

FULL DISCUSSION
 

Yes, that's true.

It's true for databases too.

If you want to store a data in a SQL database which has three states (True, False, Unknown), then you might think a nullable boolean column (here "my_column") is the right choice. But I think it is not. Do you think the SQL statement "select * from my_table where my_column = %s" works? No, it won't work since "select * from my_table where my_column = NULL" will never ever return a single line. If you don't believe me, read: Effect of NULL in WHERE clauses (Wikipedia). If you like typing, you can work-around this in your application, but I prefer straight forward solutions with only few conditions.

If you want to store True, False, Unknown: Use text, integer or a new table and a foreign key.

From my Guidelines: github.com/guettli/programming-gui...

 

Great comparison! Thank you for sharing this!

code of conduct - report abuse