This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-05-04
Channels
- # announcements (1)
- # asami (61)
- # babashka (71)
- # beginners (170)
- # biff (1)
- # calva (14)
- # clj-kondo (23)
- # cljsrn (28)
- # clojars (1)
- # clojure (152)
- # clojure-australia (2)
- # clojure-europe (65)
- # clojure-nl (2)
- # clojure-spec (8)
- # clojure-sweden (3)
- # clojure-uk (45)
- # clojurescript (1)
- # css (12)
- # cursive (16)
- # datomic (9)
- # devcards (2)
- # emacs (1)
- # events (1)
- # graalvm (31)
- # honeysql (10)
- # jackdaw (2)
- # jobs (5)
- # lambdaisland (9)
- # lsp (4)
- # malli (11)
- # meander (43)
- # off-topic (6)
- # pathom (7)
- # polylith (1)
- # portal (14)
- # re-frame (7)
- # releases (1)
- # remote-jobs (1)
- # rewrite-clj (6)
- # shadow-cljs (101)
- # specter (1)
- # tools-deps (26)
- # vim (9)
- # xtdb (2)
Hi! I am using honeysql together with Babashka and I would like to produce a raw sql queries compatible with psql. Is this possible right now?
If you're using V2, there is an inline option that tries to put the values inline in the string instead of using ? And putting the parameters in a vector
Hi, version 1 has build fn, i use it for removing keys with missing values to build a valid sql map. Is there something simiÄşlar in v2?
@zikajk No, V2 does not have that function. Can you explain what you mean by “removing keys with missing values”?
@U04V70XH6
In HoneySQL v1 I had got a function like this:
(defn build-select [table-name where limit]
(hsql/format
(hsql/build :select :*
:from table-name
:where where
:limit limit)))
All this was valid thanks to the build fn:
(build-select :public.table)
(build-select :public.table [:= :table.field "string"])
(build-select :public.table [:= :table.field "string"] 10)
Now I changed the logic in HoneySQL v2 to this - so I can supply map with/out :where or :limit as before.
(defn build-select [table-opts]
(hsql/format (merge {:select [:*] :from [(:table-name table-opts)]}
(select-keys table-opts [:where :limit]))))
The input got a little different of course:
(build-select {:table-name :public.table})
(I am building custom sql queries from EDN files. I used to read list of [table-name where limit] now it is (:table-name string :where vector :limit int}
Well, it’s “just data” so you can use cond->
and assoc
to conditionally add things, or use the helper functions to make sure you get the right structure.
@zikajk BTW, if you’re reading a vector of [table-name where limit]
you can always turn that into a map programmatically with (zipmap [table-name where limit] [:table-name :where :limit])
or your build-select
could take [[table-name where limit]]
as before and do (hsql/format (cond-> {:select [:*] :from [table-name]} where (assoc :where where) limit (assoc :limit limit)))
(in case you wanted to preserve the calling format)
@U04V70XH6 Thank you. I already changed my code to use maps, no problem here. It is just that build fn is one of the first thing mentioned in HoneySQL v1 tutorial so I have been looking for it (as I migrated to version2 because of {:inline true} which is a great option btw.)