This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-29
Channels
- # aws (6)
- # beginners (33)
- # bitcoin (2)
- # boot (22)
- # carry (2)
- # cider (5)
- # clara (21)
- # cljs-dev (115)
- # cljsrn (40)
- # clojure (161)
- # clojure-dev (73)
- # clojure-italy (38)
- # clojure-russia (88)
- # clojure-spec (123)
- # clojure-uk (58)
- # clojurescript (88)
- # core-async (26)
- # cursive (5)
- # datascript (18)
- # datomic (26)
- # hoplon (50)
- # java (2)
- # jobs (1)
- # leiningen (10)
- # lumo (1)
- # off-topic (18)
- # om (9)
- # onyx (26)
- # parinfer (13)
- # pedestal (41)
- # quil (1)
- # re-frame (27)
- # reagent (21)
- # ring-swagger (11)
- # slack-help (3)
- # spacemacs (8)
- # specter (5)
- # sql (42)
- # timbre (1)
- # uncomplicate (7)
- # untangled (3)
- # videos (1)
- # yada (26)
tiny style thing, you can replace #(vector %1 %2)
with vector
, or even list
Something else to look at, from a debugging p.o.v.: https://github.com/ttddyy/datasource-proxy
if you happen to use honeysql, I use a utility to EXPLAIN ANALYZE
(require '[clojure.java.jdbc :as j])
(defn explain-analyze
[postgres q]
(->> (update-in (honeysql.core/format q) [0] (fn [x] (str "EXPLAIN ANALYZE " x)))
(j/query postgres)
(mapv #(get % (keyword "query plan")))
(str/join "\n")
println))
(comment
(explain-analyze (:postgres sys)
(bulk-action-counts-all-time actions contents)))
@bja did you know that you could specify :explain? "EXPLAIN ANALYZE"
as an option on java.jdbc/query
?
By default :explain? true
uses just plain old "EXPLAIN"
but you can also specify a string and it will use that instead. You can also specify :explain-fn
which will do whatever you want with the output of the EXPLAIN SELECT...
— by default it’s println
.
If you want all your SQL queries explained, you can just add :explain?
to your db-spec
map (you can set any default options there and they apply to all calls).
(and, er, yeah, I know this isn’t documented anywhere yet, except in the change log for java.jdbc
… ahem working on that… honest!)
@seancorfield that's awesome
I hacked that into my company's curiosity.components.jdbc
such that I can add (with-query-logged log-level ...)
or (with-honey-map-logged log-level ...)
to anything and get a spy of sql generated or the honeysql map, but at least the sql generation part is probably generic enough to belong in java.jdbc
No, but it’s easy with that datasource-proxy library I linked to above.
I’d be interested to see how you added query logging on a per-query basis tho’…
Right, but what I meant was, how exactly do you log each query?
Thanks… reading…
So you just log the vector of SQL + params that is going into the JDBC driver?
technically speaking you don't have to force the query, but we do because we know our queries are small
but it's super handy to be able to (with-query-logged ...) something when you get confused/curious
I tried out that datasource-proxy
above — it was a simple change to the one line where we construct our (pooled) datasource — and it logs everything:
17-06-29 00:51:36 sean-corfields-imac.local INFO [net.ttddyy.dsproxy.listener.logging.SLF4JQueryLoggingListener:20] - Name:, Time:1, Success:True, Type:Prepared, Batch:False, QuerySize:1, BatchSize:0, Query:["SELECT code FROM countryFeatured WHERE siteId = ?"], Params:[(45)]
17-06-29 00:51:37 sean-corfields-imac.local INFO [net.ttddyy.dsproxy.listener.logging.SLF4JQueryLoggingListener:20] - Name:, Time:2, Success:True, Type:Prepared, Batch:False, QuerySize:1, BatchSize:0, Query:["SELECT ISO, Country FROM countryInfo ORDER BY Country ASC"], Params:[()]
(deliberately picking some not very interesting queries from our app 🙂 )
I’m thinking that a :logging?
option could be added to java.jdbc
and :logging-fn
option (defaulting to println
) could allow for any logging function to be passed in as desired.
Then it could be built-in to the library…
when I gave a short talk on honeysql, the feedback I got was that my utility functions were the most useful part
Logging result sets is a lot more problematic (because of their size)…
OK, dinner time here. Thanks for sharing that!
I’m looking for feedback on Clojure version support for the next release of clojure.java.jdbc
— if you use the library, could you please complete this very brief survey? https://www.surveymonkey.com/r/MR2HRFD Thank you!