This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-07-24
Channels
- # admin-announcements (21)
- # announcements (1)
- # beginners (36)
- # boot (48)
- # cider (21)
- # clojure (61)
- # clojure-italy (4)
- # clojure-japan (5)
- # clojure-norway (2)
- # clojure-russia (2)
- # clojure-sg (2)
- # clojure-uk (3)
- # clojurescript (33)
- # core-async (5)
- # core-typed (1)
- # cursive (13)
- # datomic (34)
- # devops (38)
- # editors (24)
- # events (10)
- # ldnclj (14)
- # off-topic (31)
- # onyx (4)
- # re-frame (84)
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.
@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.
@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 ;-/
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)))
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>
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
I think you need t still
t/overlap
@chelsey: I see where you’re getting it from on the main page though - that should probably be fixed in the readme
(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))
(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]))
(t/overlap (t/interval (t/date-time 1986) (t/date-time 1990))
(t/interval (t/date-time 1987) (t/date-time 1991)))
@surreal.analysis: thanks for the pointer
@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
Ah, you mean prepare-statement
? I was thinking of the old API I think…?
Yes, prepare-statement
is very low-level. It’s only intended to be used if you’re doing something fairly specialized.
If you have suggestions for how to make that clearer in the docstrings or the http://clojure-doc.org docs, I can update stuff...
Sorry it caused you problems 😞