Skip to content

Instantly share code, notes, and snippets.

@terjesb
Forked from MichaelDrogalis/gist:10294159
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terjesb/009a0aea47224cfcdabe to your computer and use it in GitHub Desktop.
Save terjesb/009a0aea47224cfcdabe to your computer and use it in GitHub Desktop.
(def conn (start-datomic! (str "datomic:mem://" (java.util.UUID/randomUUID)) (schema)))
(def data
[{:db/id (d/tempid :com.mdrogalis/people)
:user/name "Mike"}
{:db/id (d/tempid :com.mdrogalis/people)
:user/name "Dorrene"}
{:db/id (d/tempid :com.mdrogalis/people)
:user/name "Benti"}
{:db/id (d/tempid :com.mdrogalis/people)
:user/name "Derek"}
{:db/id (d/tempid :com.mdrogalis/people)
:user/name "Kristen"}])
@(d/transact conn data)
(def db (d/db conn))
(defn datoms-between
"Returns a reducible collection of datoms created
between the start and end dates in a single partition."
[db partition start end]
(let [start-e (d/entid-at db partition start)
end-e (d/entid-at db partition end)]
(->> (d/seek-datoms db :eavt start-e)
(r/take-while #(< (:e %) end-e)))))
(def tip (d/next-t db))
(def partition-size 2)
(def partitions (take-while #(< % tip) (range 0 tip partition-size)))
(->> partitions
(map #(into [] (datoms-between db :com.mdrogalis/people % (+ % partition-size))))
(filter seq))
[[#datom[277076930200554 64 "Mike" 13194139534313 true] #datom[277076930200555 64 "Dorrene" 13194139534313 true]]
[#datom[277076930200556 64 "Benti" 13194139534313 true] #datom[277076930200557 64 "Derek" 13194139534313 true]]
[#datom[277076930200558 64 "Kristen" 13194139534313 true]]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment