Fork me on GitHub
#beginners
<
2015-07-24
>
tap01:07:14

@petrus: yeah, zipmap makes it slightly shorter (map #(zipmap [:id :label] %) my-map)

ska11:07:06

Hi. Feeling like a total idiot here... I can not find any clojure.jdbc examples for how to lazily read from a database and for each item run an update. I do not want to slurp everything into memory. Processing time is not an issue.

Petrus Theron12:07:43

@ska: for a traditional relational db, you'll have to poll periodically. In the poll handler, you can connect, update, disconnect. Repeat update for any unprocessed rows, or immediately queue another update.

ska12:07:37

@petrus: I think, my use case is much simpler: Iterate once over the ResultSet and for each row fire an update to the database. And yes, it is traditional relational DB: DB2 for just a tiny bit more fun ;-/

surreal.analysis13:07:37

Their example

(jdbc/atomic conn
  (with-open [cursor (jdbc/fetch-lazy conn "SELECT id, name FROM people;")]
    (doseq [row (jdbc/cursor->lazyseq cursor)]
      (println row)))

chelsey13:07:10

I’m trying to use the overlap function mentioned in the clj-time readme

chelsey13:07:24

The overlap function can be used to get an Interval representing the overlap between two intervals:

(overlap (t/interval (t/date-time 1986) (t/date-time 1990))
         (t/interval (t/date-time 1987) (t/date-time 1991)))
=> #<Interval 1987-01-01T00:00:00.000Z/1990-01-01T00:00:00.000Z>

chelsey13:07:34

has anyone used this before? I cannot seem to get it to work " Unable to resolve symbol: overlap in this context” even though I’ve required clj-time.core

surreal.analysis13:07:33

I think you need t still

surreal.analysis13:07:34

@chelsey: I see where you’re getting it from on the main page though - that should probably be fixed in the readme

chelsey13:07:25

yes I thought that, but I tried that as well

chelsey13:07:35

still getting "No such var: t/overlap”

sveri13:07:27

maybe its in a different namespace than interval?

sveri13:07:16

ok, it is not

chelsey13:07:11

yeah strange

sveri13:07:14

can you post the namespace and the complete function please?

chelsey13:07:43

ns clj-time.core

chelsey13:07:47

(defn overlap
  "Returns an Interval representing the overlap of the specified Intervals.
   Returns nil if the Intervals do not overlap.
   The first argument must not be nil.
   If the second argument is nil then the overlap of the first argument
   and a zero duration interval with both start and end times equal to the
   current time is returned."
  [^Interval i-a ^Interval i-b]
     ;; joda-time AbstractInterval.overlaps:
     ;;    null argument means a zero length interval 'now'.
     (cond (nil? i-b) (let [n (now)] (overlap i-a (interval n n)))
           (.overlaps i-a i-b) (interval (latest (start i-a) (start i-b))
                                         (earliest (end i-a) (end i-b)))
           :else nil))

sveri13:07:15

sorry, I meant your code

chelsey13:07:26

oh haha sorry

chelsey13:07:33

(ns fy.impl.sys.ops
  (:refer-clojure :exclude [format])
  (:require [ :as io]
            [datomic.api :as d]
            [fy.util.db :as db]
            [clj-time.local :as l]
            [clj-time.core :as t]
            [clj-time.coerce :as c]
            [fy.impl.sys.report :as r]
            [fy.util.env :as env]))

chelsey13:07:37

(t/overlap (t/interval (t/date-time 1986) (t/date-time 1990))
         (t/interval (t/date-time 1987) (t/date-time 1991)))

sveri14:07:57

hm, works for me, I left out the datomic namespace and the fy.* namespaces

sveri14:07:05

maybe reset the repl`?

chelsey14:07:29

I’ll try that, thanks simple_smile

ska14:07:48

@surreal.analysis: thanks for the pointer

ska15:07:24

@seancorfield: First time user of your java.jdbc library... I wonder why I need to extract the :connection from the db-spec/connection object for prepared-statement while e.g. query takes the db-spec/connection map. Took my some time to hunt my error down

seancorfield16:07:25

Ah, you mean prepare-statement? I was thinking of the old API I think…?

seancorfield16:07:25

Yes, prepare-statement is very low-level. It’s only intended to be used if you’re doing something fairly specialized.

seancorfield16:07:06

If you have suggestions for how to make that clearer in the docstrings or the http://clojure-doc.org docs, I can update stuff...

seancorfield16:07:52

Sorry it caused you problems 😞