sql

All things SQL and JDBC...
henrik42 2021-04-30T06:39:04.133400Z

Nice post. Just to clarify: does plan just mean transducer/reduceable or something special you're referring to?

seancorfield 2021-04-30T06:42:23.133600Z

next.jdbc/plan produces an IReduceInit so it is reducible and mostly transducible.

seancorfield 2021-04-30T06:43:11.133800Z

It allows for streaming very large result sets (eagerly).

henrik42 2021-04-30T06:57:09.134Z

Got it. Thx

richiardiandrea 2021-04-30T16:52:30.136Z

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?)

richiardiandrea 2021-04-30T16:58:39.136100Z

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

richiardiandrea 2021-04-30T17:00:20.136400Z

yeah it seems like I would have to "unroll the loop" if I wanted to send individual statements

seancorfield 2021-04-30T17:08:15.136600Z

with-db-transaction is going to create/manage a connection for you. It would be used for everything inside the body.

seancorfield 2021-04-30T17:08:31.136800Z

(depending on what you pass to with-db-transaction)

seancorfield 2021-04-30T17:09:57.137Z

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 🙂

seancorfield 2021-04-30T17:10:33.137200Z

You say “statements” — what type of SQL are you executing? DDL often doesn’t respect transactions anyway.

richiardiandrea 2021-04-30T17:21:14.137400Z

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)))

richiardiandrea 2021-04-30T17:22:02.137700Z

I see now it is not a connection issue though and thank you for answering

seancorfield 2021-04-30T17:22:58.137900Z

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.

👍 1