Re: understanding 'binding' use in clojure.java.jdbc
Hi, I found database connection pools to be the right thing to use with c.j.jdbc and multiple databases. https://clojars.org/org.bituf/clj-dbcp (let [conn1 (make-pool-1) conn2 (make-pool-2)] (sql/with-connection conn1 (sql/with-query-results r [select ...] (sql/with-connection conn2 (sql/do-commands insert into ...) matt On 10 October 2012 15:03, Stuart Sierra the.stuart.sie...@gmail.com wrote: On Tuesday, October 9, 2012 10:25:05 PM UTC-4, Sean Corfield wrote: This is why c.j.jdbc is getting an API overall that will expose functions that accept the connection or the db-spec directly (and the old API will be rewritten in terms of the new one for compatibility). Excellent. -S -- 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 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
Re: understanding 'binding' use in clojure.java.jdbc
FWIW, the c.j.jdbc docs have an example of connection pooling: http://clojure.github.com/java.jdbc/doc/clojure/java/jdbc/ConnectionPooling.html On Mon, Dec 3, 2012 at 6:03 AM, Matthias Cords schlafbo...@gmail.comwrote: Hi, I found database connection pools to be the right thing to use with c.j.jdbc and multiple databases. https://clojars.org/org.bituf/clj-dbcp (let [conn1 (make-pool-1) conn2 (make-pool-2)] (sql/with-connection conn1 (sql/with-query-results r [select ...] (sql/with-connection conn2 (sql/do-commands insert into ...) matt On 10 October 2012 15:03, Stuart Sierra the.stuart.sie...@gmail.comwrote: On Tuesday, October 9, 2012 10:25:05 PM UTC-4, Sean Corfield wrote: This is why c.j.jdbc is getting an API overall that will expose functions that accept the connection or the db-spec directly (and the old API will be rewritten in terms of the new one for compatibility). Excellent. -S -- 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 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 -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) -- 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
Re: understanding 'binding' use in clojure.java.jdbc
Yeah, you probably shouldn't rely on this but I think it will still work. I have done something similar before when reading from 3 databases simultaneously (3 nested with-connection and with-query-result calls) and I believe (connection) is only called once when creating the prepared statement. On Tue, Oct 9, 2012 at 9:24 PM, Sean Corfield seancorfi...@gmail.com wrote: No, the inner with-connection binds *db* to db1 so db2 is no longer accessible. This is why c.j.jdbc is getting an API overall that will expose functions that accept the connection or the db-spec directly (and the old API will be rewritten in terms of the new one for compatibility). Sean On Tue, Oct 9, 2012 at 2:44 PM, gaz jones gareth.e.jo...@gmail.com wrote: Can you not simply: (jdbc/with-connection db2 (jdbc/with-query-results results query {:result-type :forward-only :fetch-size 1000} (jdbc/with-connection db1 ;; read and write? ))) ? -- 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 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
Re: understanding 'binding' use in clojure.java.jdbc
On Tuesday, October 9, 2012 10:25:05 PM UTC-4, Sean Corfield wrote: This is why c.j.jdbc is getting an API overall that will expose functions that accept the connection or the db-spec directly (and the old API will be rewritten in terms of the new one for compatibility). Excellent. -S -- 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
understanding 'binding' use in clojure.java.jdbc
I'm trying to understand how 'binding' works, looking at the jdbc lib. with-connection* binds *db* and then invokes a function. That function will invoke other jdbc methods which do not take a connection parameter, so I presume they are pulling the connection from *db*. As I understand it, the value of *db* is scoped to the call stack somehow: anything called from with-connection* will have the new value of *db*, but once with-connection* returns the old value of *db* is restored? How would I do an operation involving two databases? I'd need to call with-connection* from with-connection*? How would I then read from one write to the other? -- 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
Re: understanding 'binding' use in clojure.java.jdbc
Brian Craft craft.br...@gmail.com writes: How would I do an operation involving two databases? I'd need to call with-connection* from with-connection*? How would I then read from one write to the other? I've never used the jdbc lib, but essentially it should be something along the lines of (let [db1 (connect-to-db1) db2 (connect-to-db2)] (with-connection* db2 (write-stuff (with-connection* db1 (read-stuff) Bye, Tassilo -- 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
Re: understanding 'binding' use in clojure.java.jdbc
On Tuesday, October 9, 2012 11:32:18 AM UTC-7, Tassilo Horn wrote: Brian Craft craft...@gmail.com javascript: writes: How would I do an operation involving two databases? I'd need to call with-connection* from with-connection*? How would I then read from one write to the other? I've never used the jdbc lib, but essentially it should be something along the lines of (let [db1 (connect-to-db1) db2 (connect-to-db2)] (with-connection* db2 (write-stuff (with-connection* db1 (read-stuff) If (read-stuff) is not lazy, then this looks pretty simple: all the data is loaded in memory returned to (write-stuff). If the data is large you wouldn't want it all in memory. What then? Could you make read-stuff return a lazy sequence? My impression after a brief experiment is that this doesn't work: when the inner with-connection* returns, the db connection is closed. A lazy sequence from (read-stuff) then can't be evaluated w/o throwing an error. -- 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
Re: understanding 'binding' use in clojure.java.jdbc
Brian Craft craft.br...@gmail.com writes: Hi Brian, If (read-stuff) is not lazy, then this looks pretty simple: all the data is loaded in memory returned to (write-stuff). If the data is large you wouldn't want it all in memory. What then? Could you make read-stuff return a lazy sequence? My impression after a brief experiment is that this doesn't work: when the inner with-connection* returns, the db connection is closed. A lazy sequence from (read-stuff) then can't be evaluated w/o throwing an error. Yes, that's true. Maybe Korma [1] is better suited for this kind of operation. Bye, Tassilo [1] http://sqlkorma.com -- 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
Re: understanding 'binding' use in clojure.java.jdbc
On Tuesday, October 9, 2012 12:11:28 PM UTC-7, Tassilo Horn wrote: Brian Craft craft...@gmail.com javascript: writes: Hi Brian, If (read-stuff) is not lazy, then this looks pretty simple: all the data is loaded in memory returned to (write-stuff). If the data is large you wouldn't want it all in memory. What then? Could you make read-stuff return a lazy sequence? My impression after a brief experiment is that this doesn't work: when the inner with-connection* returns, the db connection is closed. A lazy sequence from (read-stuff) then can't be evaluated w/o throwing an error. Yes, that's true. Maybe Korma [1] is better suited for this kind of operation. Damn. I was hoping there was some lispy fp thing I was missing here, but *db* really is just a global variable that fails in the same way that globals fail in all languages. Thanks for the link to korma. -- 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
Re: understanding 'binding' use in clojure.java.jdbc
Can you not simply: (jdbc/with-connection db2 (jdbc/with-query-results results query {:result-type :forward-only :fetch-size 1000} (jdbc/with-connection db1 ;; read and write? ))) ? On Tue, Oct 9, 2012 at 2:53 PM, Brian Craft craft.br...@gmail.com wrote: On Tuesday, October 9, 2012 12:11:28 PM UTC-7, Tassilo Horn wrote: Brian Craft craft...@gmail.com writes: Hi Brian, If (read-stuff) is not lazy, then this looks pretty simple: all the data is loaded in memory returned to (write-stuff). If the data is large you wouldn't want it all in memory. What then? Could you make read-stuff return a lazy sequence? My impression after a brief experiment is that this doesn't work: when the inner with-connection* returns, the db connection is closed. A lazy sequence from (read-stuff) then can't be evaluated w/o throwing an error. Yes, that's true. Maybe Korma [1] is better suited for this kind of operation. Damn. I was hoping there was some lispy fp thing I was missing here, but *db* really is just a global variable that fails in the same way that globals fail in all languages. Thanks for the link to korma. -- 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 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
Re: understanding 'binding' use in clojure.java.jdbc
No, the inner with-connection binds *db* to db1 so db2 is no longer accessible. This is why c.j.jdbc is getting an API overall that will expose functions that accept the connection or the db-spec directly (and the old API will be rewritten in terms of the new one for compatibility). Sean On Tue, Oct 9, 2012 at 2:44 PM, gaz jones gareth.e.jo...@gmail.com wrote: Can you not simply: (jdbc/with-connection db2 (jdbc/with-query-results results query {:result-type :forward-only :fetch-size 1000} (jdbc/with-connection db1 ;; read and write? ))) ? -- 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
Re: understanding 'binding' use in clojure.java.jdbc
On Tue, Oct 9, 2012 at 12:53 PM, Brian Craft craft.br...@gmail.com wrote: On Tuesday, October 9, 2012 12:11:28 PM UTC-7, Tassilo Horn wrote: Yes, that's true. Maybe Korma [1] is better suited for this kind of operation. Thanks for the link to korma. Korma is built on c.j.jdbc and may suffer from the same issues...? -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) -- 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