java.jdbc

The age of reduce is upon us

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

jdbc code is pretty heavily in to resource management, you have connections, result sets, prepared statements all of which require lifetime management.

clojure.java.jdbc is built around result-set-seqs, sequences of results. but lazy-sequences provide no good way to manage the lifetime of resources behind the sequences.

clojure provides a mechanism to define a collection in terms of reduce and a growing collection of ways to manipulate and transform reducible collections.

a collection that knows how to reduce itself has a means of managing the lifetime of associated resources, the lifetime of the reduce operation.

so it seems clear that result-set-seqs should be replaced with result-set-reducibles.

Activity

Hide
Ghadi Shayban added a comment -

Something like this would be amenable to reduce/transduce. Used in conjunction with db-query-with-resultset
https://gist.github.com/ghadishayban/d2f31961deba98ee4595

Half of the knobs on jdbc/query are to control seq realization, but instead should defer to reduce/reduced

i.e.
(into [] (take 5000) (queryr "select * from foo"))

The reducible collection returned should be one-shot, cleaning up resources, and it would be an error to run more than once

Show
Ghadi Shayban added a comment - Something like this would be amenable to reduce/transduce. Used in conjunction with db-query-with-resultset https://gist.github.com/ghadishayban/d2f31961deba98ee4595 Half of the knobs on jdbc/query are to control seq realization, but instead should defer to reduce/reduced i.e. (into [] (take 5000) (queryr "select * from foo")) The reducible collection returned should be one-shot, cleaning up resources, and it would be an error to run more than once
Hide
Sean Corfield added a comment -

This can be tested in org.clojure/java.jdbc "0.7.0-beta1":

(->> (reducible-query db-spec "select * from foo")
     (transduce (map :field) +))
Show
Sean Corfield added a comment - This can be tested in org.clojure/java.jdbc "0.7.0-beta1":
(->> (reducible-query db-spec "select * from foo")
     (transduce (map :field) +))
Hide
Sean Corfield added a comment -

So far, from the survey, 33 responses: all on Clojure 1.8 or 1.9, all happy to see java.jdbc drop support for Clojure 1.6 and earlier...

Show
Sean Corfield added a comment - So far, from the survey, 33 responses: all on Clojure 1.8 or 1.9, all happy to see java.jdbc drop support for Clojure 1.6 and earlier...
Hide
Sean Corfield added a comment -

Available in java.jdbc 0.7.0-beta2 (which requires Clojure 1.7 or later).

Show
Sean Corfield added a comment - Available in java.jdbc 0.7.0-beta2 (which requires Clojure 1.7 or later).

People

Vote (3)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: