sql

All things SQL and JDBC...
Ramon Rios 2020-02-18T10:45:36.213300Z

Hello everyone!

Ramon Rios 2020-02-18T10:46:57.214600Z

(-> (sql/query ds ["select * from customers"] {:builder-fn rs/as-unqualified-lower-maps}) lazy-seq)
Would it be a good idea to transform this return of data into a lazy-seq, considering the fact that i could get a huge amount of data and then avoid issues?

dharrigan 2020-02-18T10:57:22.214900Z

I believe that is what plan is for

dharrigan 2020-02-18T10:57:31.215200Z

<https://github.com/seancorfield/next-jdbc/blob/master/doc/getting-started.md#plan--reducing-result-sets>

dharrigan 2020-02-18T10:58:17.215500Z

Alternatively, you could use a cursor?

seancorfield 2020-02-18T17:41:22.217300Z

Yup, what @dharrigan said @ramon.rios -- query (which is the same as execute! really) gives you a complete, realized vector of hash maps -- converting that to a lazy-seq is pointless: the data is already all in memory. What you want is plan and then reduce over that.

seancorfield 2020-02-18T17:43:43.219700Z

plan also lets you take advantage of lazy/streaming result sets on the JDBC side (even tho' reducing is eager on the Clojure side), because you can set options to get the JDBC sdriver/database to read results N rows at a time and process them in a reduction, so you can deal with result sets much larger than will fit in memory. See the Tips & Tricks section of Friendly SQL Functions (in the GitHub repo -- it has doc changes that have not yet been published in a release to http://cljdoc.org).

dharrigan 2020-02-18T17:48:51.219900Z

👍

Ramon Rios 2020-02-18T18:02:34.222200Z

Ok. I got that plan is the one who i need to pick up. I'll try out on what i want to achieve, thanks 🙂