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?
export const foo = sqliteTable("foo", {
isFooBar: integer("is_foo_bar", { mode: "boolean" })
.notNull()
.default(0)
// ^ Argument of type '0' is not assignable to parameter of type 'boolean | SQL<unknown>'.ts(2345)
});
export const foo = sqliteTable("foo", {
isFooBar: integer("is_foo_bar", { mode: "boolean" })
.notNull()
.default(0)
// ^ Argument of type '0' is not assignable to parameter of type 'boolean | SQL<unknown>'.ts(2345)
});
5 Replies
ijd
ijd2y ago
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.
Graeme
GraemeOP2y ago
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
mutation({
isFooBar: 0 // 0 is entered into the db
})
mutation({
isFooBar: 0 // 0 is entered into the db
})
But are we saying we should be doing:
mutation({
isFooBar: false // 0 is still entered into the db
})
mutation({
isFooBar: false // 0 is still entered into the db
})
Only one way to find out... but just keen to discuss it so I ensure I'm not misinterpreting 🙂
Andrii Sherman
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
Graeme
GraemeOP2y ago
Thanks @Andrew Sherman
SteveS
SteveS15mo ago
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.
Want results from more Discord servers?
Add your server