Unexpected type mismatch for sqlite integer boolean mode
Hi, you guys added boolean support for sqlite recently (thanks for that!!). It correctly expects
0
and 1
as the values in the db but I've noticed when using a default(0)
it throws a ts error (see below). Setting it as a boolean default(false)
does not.
I'd expect to set a value in line with the expectation but perhaps my understanding is wrong? Is it a bug?
5 Replies
I think this is likely the intended behavior. If you have a boolean column, you’re trying to store a true/false. This is the mapping between two language-specific expressions of true/false.
Yeah, it makes sense logically for sure. I think the confusion lies wherein the type is an integer with a boolean "mode". Drizzle also state it's set as a 0 or 1.
This allows you to operate boolean values in your code and Drizzle stores them as 0 and 1 integer values in the database.Is there a transformation under the hood going on or am I reading too much into this? My understanding was that we should be doing this But are we saying we should be doing: Only one way to find out... but just keen to discuss it so I ensure I'm not misinterpreting 🙂
Yeah, so we made true mapped as 1
and false mapped as 0
just ot make a boolean mode in code and still have 0 and 1 in database
Thanks @Andrew Sherman
Just running into this myself and I'm not sure I understand the design philosophy. An integer taking "true" or "false" as a value seems like an anti-pattern to me.