This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-12-29
Channels
- # adventofcode (13)
- # announcements (2)
- # asami (59)
- # babashka (6)
- # beginners (273)
- # calva (18)
- # cider (3)
- # cljs-dev (3)
- # clojure (84)
- # clojure-estonia (1)
- # clojure-europe (2)
- # clojure-france (11)
- # clojure-nl (3)
- # clojure-taiwan (2)
- # clojure-uk (23)
- # clojurescript (7)
- # code-reviews (321)
- # conjure (4)
- # data-science (1)
- # depstar (6)
- # fulcro (37)
- # helix (20)
- # juxt (3)
- # keechma (3)
- # leiningen (3)
- # malli (7)
- # nrepl (1)
- # off-topic (20)
- # pathom (25)
- # re-frame (30)
- # reveal (5)
- # shadow-cljs (25)
- # sql (15)
- # tools-deps (4)
- # uncomplicate (2)
- # xtdb (3)
Hi, I'm using next-jdbc
with hugsql
. I would like to pass an argument to my query to limit batch size of how many rows I am selecting, but I also want to have an adapter that allows me not to have namespace
(hugsql/def-db-fns
"path-to-query.sql"
{:adapter (next-adapter/hugsql-adapter-next-jdbc {:builder-fn rs/as-unqualified-maps})})
now my results look a bit like this
{events/id "1a252d29-e19f-4e84-9e96-14ce82254988", :events/sequence_number 1}
but I would like them to look like this
{id "1a252d29-e19f-4e84-9e96-14ce82254988", :sequence_number 1}
@brzoskwinka18 can you try rs/as-unqualified-lower-maps
instead? https://github.com/nomnom-insights/nomnom.utility-belt.sql/blob/eacec699ba25019f8ebf55cea1e6d2af68a81eff/src/utility_belt/sql/model.clj#L15.
it seems like all I needed was to add the builder-fn as a parameter to the execute function, like this!
(jdbc/execute! db [query batch-size] {:builder-fn rs/as-unqualified-maps})
well I tried it both ways, and it worked with execute!
thanks for your advice anyway 🙂
@brzoskwinka18 :builder-fn
is an option for next.jdbc
which is why you need it in direct calls to that library's functions. There's an example of how to pass next.jdbc
options to the HugSQL adapter in the next.jdbc
docs: https://cljdoc.org/d/seancorfield/next.jdbc/1.1.613/doc/getting-started/friendly-sql-functions#hugsql-quick-start -- scroll down a bit to see:
;; add require next.jdbc.result-set :as rs to your ns
(hugsql/def-db-fns "db/example.sql"
{:adapter (adapter/hugsql-adapter-next-jdbc
{:builder-fn rs/as-maps})})
Always happy to hear ways folks think the docs can be improved...
(I don't know what HugSQL has in terms of docs on how to use next.jdbc
?)
BTW, in case folks aren't aware, there's a dedicated #hugsql channel (and I lurk there as well).
HugSQL docs have a dedicated "Adapters" section: https://www.hugsql.org/#adapter
Yes, that's their historical default since it's been around much longer. The recommendation these days is to use next.jdbc
(since clojure.java.jdbc
is no longer being maintained) but I can understand why they wouldn't necessarily want to change their default.