Nice post. Just to clarify: does plan
just mean transducer/reduceable or something special you're referring to?
next.jdbc/plan
produces an IReduceInit
so it is reducible and mostly transducible.
It allows for streaming very large result sets (eagerly).
Got it. Thx
Hi there, I have an interesting problem here, we have a doseq
within a with-db-transaction
and I was wondering how that behaves in terms of connections. Does it open one connection per item in the doseq or it sends all the SQL statements over one connection (therefore one transaction?)
As a note, the library we are using calls clojure.java.jdbc/execute!
https://github.com/layerware/hugsql/blob/master/hugsql-adapter-clojure-java-jdbc/src/hugsql/adapter/clojure_java_jdbc.clj#L12
yeah it seems like I would have to "unroll the loop" if I wanted to send individual statements
with-db-transaction
is going to create/manage a connection for you. It would be used for everything inside the body.
(depending on what you pass to with-db-transaction
)
Any SQL actions that are dynamically within that “scope” will reuse that connection, assuming you’re passing in the bound value from with-db-transaction
and not the thing you are making the tx from 🙂
You say “statements” — what type of SQL are you executing? DDL often doesn’t respect transactions anyway.
yep I now read that here: https://www.mchange.com/projects/c3p0/#configuring_statement_pooling basically it is something like this
(jdbc/with-db-transaction [api-tx api-db-spec]
(doseq [report open-reports]
(update-precision-on-all-measurements api-tx report)))
I see now it is not a connection issue though and thank you for answering
Right, so it makes a Connection
from the db spec and starts a TX on it, then the body is executed with that new TX-enabled Connection
(`api-tx`), then the TX is committed and the Connection
closed.