This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-05-17
Channels
- # announcements (1)
- # beginners (44)
- # calva (20)
- # cljs-dev (22)
- # cljsrn (5)
- # clojars (24)
- # clojure (33)
- # clojure-europe (36)
- # clojure-filipino (1)
- # clojure-indonesia (1)
- # clojure-my (1)
- # clojure-nl (2)
- # clojure-sg (2)
- # clojure-uk (8)
- # clojurescript (73)
- # code-reviews (21)
- # conjure (13)
- # cursive (46)
- # datahike (16)
- # datomic (5)
- # depstar (1)
- # graalvm (7)
- # honeysql (22)
- # jobs (2)
- # jobs-discuss (2)
- # kaocha (3)
- # luminus (2)
- # malli (2)
- # nrepl (17)
- # off-topic (46)
- # pathom (14)
- # re-frame (7)
- # remote-jobs (1)
- # sci (8)
- # shadow-cljs (33)
- # sql (14)
- # vim (48)
- # xtdb (1)
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))
Only integer columns called owner
.
that code snippet uses that determination in the when test. this would null out all other integer columns right?
Oh, gotcha! Yeah, missed that. Yeah, needs to be if
not when
and return the original x
in the else
case @admin055
Make sense, Thank you both!
Oh, gotcha! Yeah, missed that. Yeah, needs to be if
not when
and return the original x
in the else
case @admin055