This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-05
Channels
- # announcements (1)
- # babashka (5)
- # beginners (151)
- # calva (43)
- # clj-kondo (23)
- # cljdoc (1)
- # cljs-dev (6)
- # cljsrn (10)
- # clojure (60)
- # clojure-australia (1)
- # clojure-europe (26)
- # clojure-gamedev (14)
- # clojure-nl (1)
- # clojure-spec (10)
- # clojure-uk (80)
- # clojurescript (66)
- # clojureverse-ops (4)
- # community-development (7)
- # conjure (8)
- # datomic (15)
- # deps-new (1)
- # docker (27)
- # emacs (2)
- # fulcro (13)
- # honeysql (13)
- # java (5)
- # jobs-discuss (43)
- # lsp (121)
- # luminus (13)
- # malli (1)
- # off-topic (73)
- # pathom (12)
- # polylith (29)
- # practicalli (4)
- # re-frame (35)
- # reagent (44)
- # remote-jobs (5)
- # rewrite-clj (2)
- # sci (7)
- # shadow-cljs (125)
- # sql (4)
- # tools-deps (9)
- # xtdb (5)
I feel like I’m missing something obvious; how would I format an =
clause inside of a function call? The approach I expected to work doesn’t do the right thing:
=> (sql/format (sql/call :nullif [:= :id "dsr-000"] false))
["nullif((=, id, ?), FALSE)" "dsr-000"]
@greg316 HoneySQL v1 or v2?
On v2:
dev=> (sql/format-expr (sql/call :nullif [:= :id "dsr-000"] false))
["NULLIF(id = ?, FALSE)" "dsr-000"]
(sorry, didn't paste the right thing)(I'm not sure if you can format
expressions in v1 -- you can't in v2, you must use format-expr
-- but if you format
a statement that includes your expression you should do better)
has the same effect in a full expression:
=> (sql/format (sql/build :update :foos :set {:is_default (sql/call :nullif [:= :id "dsr-000"] false)}))
["UPDATE foos SET is_default = nullif((=, id, ?), FALSE)" "dsr-000"]
v1 had some strange behavior in some places with embedded expressions...
v2: (there's no build
function because it really didn't do much)
dev=> (sql/format {:update :foos :set {:is_default (sql/call :nullif [:= :id "dsr-000"] false)}})
["UPDATE foos SET is_default = NULLIF(id = ?, FALSE)" "dsr-000"]
unfortunately I don’t think upgrading the whole app to v2 is tractable right now, but I’ll put it on our backlog - does look like a nicer API
You can run v1 and v2 side-by-side and migrate on a query-by-query basis.
Different library names and different namespaces.
We're running both at work and slowly migrating from v1 to v2.