I have a SQLite DB with a tinyint column (named owner) that takes the values 0 and 1 to act like a boolean. Currently I am retrieving and transforming this column's values to true and false by extending next-jdbc's ReadableColumn:
(extend-protocol rs/ReadableColumn
Integer
(read-column-by-index [x mrs i]
(if (= (.getColumnName mrs i) "owner")
(if (= 1 x) true false)
x)))
Is this the best solution knowing that this is the only column for which I cast from Integer to Boolean?As long as owner
is unique across your whole DB, thatโs reasonable. In MySQL, I use the BIT
column type and that automatically generates true
/`false` at the JDBC level.
(you could just have (= 1 x)
instead of the if
BTW)
Great, thanks.
Oh thanks for the tip, much more cleaner like that!
(when (= (.getColumnName mrs i) "owner")
(= 1 x))
that when looks like trouble. you are doing this for all Integer columns.
I'd probably use (not= 0 x)
since that sorta tracks in my brain
where anything non-zero maps to true
Only integer columns called owner
.
that code snippet uses that determination in the when test. this would null out all other integer columns right?
(if (= (.getColumnName mrs i) "owner")
(not (zero? x))
x)
Make sense, Thank you both!