This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-01-03
Channels
- # aleph (2)
- # announcements (6)
- # babashka (6)
- # beginners (106)
- # biff (8)
- # clara (24)
- # clj-kondo (10)
- # clj-otel (4)
- # cljdoc (2)
- # clojure (54)
- # clojure-conj (3)
- # clojure-europe (85)
- # clojure-norway (54)
- # clojure-uk (3)
- # clojurescript (27)
- # community-development (2)
- # data-science (1)
- # datahike (2)
- # datomic (11)
- # deps-new (67)
- # emacs (4)
- # graalvm (15)
- # hyperfiddle (11)
- # introduce-yourself (1)
- # lsp (6)
- # malli (30)
- # midje (4)
- # nrepl (13)
- # off-topic (86)
- # polylith (7)
- # releases (2)
- # sql (10)
Hi folks, I am new to next jdbc 1. I am trying to use join using next.jdbc ! Currently, since i am doing the left join on the same table, the output has the keys with the table name associated with it for eg, :emptable/id, now is there a way where i can just get id for it ? 2. I am currently using plain query with execute! using preparedStatement of next.jdbc is there any better way we can do it ? is the execute! along with preparedStatement safe from sql injection ?
1. in your query, specify the aliases explicitly, for example:
select
t1.id as id,
t2.id as parent_id
etc
2). The execute! call creates a one-time PreparedStatement under the hood. use PreparedStatement only if you're going to call that query in a loopfor example:
(let [stmt (jdbc/prepare ....)
(doseq ...
(jdbc/execute stmt params)))
To prevent sql injections, just pass all the parameters through params, not as a part of a query. Long story short, never use format or str for building a query, and you're good
@U1WAUKQ3E I am currently passing the alias explicitly
SELECT parent.employee_id AS id,
parent.name AS name,
but since maybe i am using Left JOIN
on same table it is working little weird and I am also getting the table name as
:employee/id
To omit the table names, pass the :as option with a value from the result-set module. Smth like this {:as rs/as-unqualified-maps} Writing by memory
It's :builder-fn
but I'd recommend just using unique aliases and keeping the qualified keys.
Otherwise use execute!
You don't need to work with prepared statements directly in general. You do want to use connection pooling in production code. That's all explained in the docs.
@U1WAUKQ3E @U04V70XH6 thanks for the inputs
I had already implemented :builder-fn
in custom config for all the conn during its creation but it was overriding because instead of passing the ds
i was passing a new connection !
Eg: instead of
(execute! ds [params])
I was doing
(execute! (:connectable ds) [params])
This did create a new conn
Silly !! 😅