> In my case config/db is really read from a config.edn file and may point
> to a mysql, postgresql or sqlite database.

Then you can add a :streaming-options key to your EDN file and do this in your 
code:

        (into [] (take 2) (jdbc/reducible-query config/db (:streaming-options 
config/db)))

As Luke said, it’s not java.jdbc’s job to support a concept like “streaming” 
when that requires different options on every database – java.jdbc’s job is to 
let users provide all the options they need and make sure they’re delivered to 
the appropriate parts of the JDBC driver, connection, statement, transaction, 
etc.

A comment on your use of EDN to produce a db-spec: for production code I’d 
strongly recommend using a connection pool instead of just a bare hash map 
db-spec in every call, otherwise you’re going to pay the cost of setting up and 
tearing down a full DB connection for every operation!

The :auto-commit? option is supported in 0.7.0-beta5 which should hit Maven 
Central by tomorrow (or maybe late tonight). Please let me know if it solves 
the streaming problem.

Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

From: Ralf Schmitt
Sent: Wednesday, July 5, 2017 2:57 PM
To: Sean Corfield; Clojure Mailing List
Subject: Re: JDBC Connection auto-commit?: [ANN] clojure.java.jdbc 0.7.0 Beta1

Sean Corfield <s...@corfield.org> writes:

> Rather than doing something that requires a dependency on specific JDBC 
> driver classes, it seems that if an :auto-commit option in the db-spec were 
> honored by get-connection you would get what you needed:
>
>       (into [] (take 2) (jdbc/reducible-query (assoc config/db :auto-commit 
> false) query {:fetch-size 500}))
>
> You can already pass additional options into the DriverManager/getConnection 
> call as properties (from the db-spec) but autocommit does not appear to be 
> supported in that format.
>
> Actually, it would be cleaner if get-connection had a 2-arity accepting 
> db-spec and opts, and then everything could pass opts into get-connection and 
> you could do:
>
>       (into [] (take 2) (jdbc/reducible-query config/db query {:fetch-size 
> 500 :auto-commit false }))

That would work, but I have to look at which database driver is being
used here when creating the reducible-query. I would have to pass the
right options depending on the database driver being used instead of
passing a {:use-streaming? true} as options.

In my case config/db is really read from a config.edn file and may point
to a mysql, postgresql or sqlite database.

The extend-protocol form would be provided by the user's code, not by
java.jdbc, so there's no dependency on a specific JDBC driver class.

Anyway I could live with both solutions. And I'm aware of the fact that
an additional protocol to turn on streaming also introduces additional
complexity.

Being able to pass the :auto-commit option would already be a nice
improvement since I could get rid of the outer jdbc/with-db-connection.

I hope I've made my point clear. I'm going to trust your best judgement
on this issue from now on.

Thanks again for your work on java.jdbc.

-- 
Cheers
Ralf

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to