Skip to content

Instantly share code, notes, and snippets.

@robert-stuttaford
Created July 29, 2015 09:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robert-stuttaford/4ad9c539976d23e9a1cf to your computer and use it in GitHub Desktop.
Save robert-stuttaford/4ad9c539976d23e9a1cf to your computer and use it in GitHub Desktop.
(let [dt #(-> (clj-time.core/date-time 2015 % %2)
clj-time.coerce/to-date)
now (d/db (d/connect (db/database-uri :main)))]
[(db/conn (db/database-uri :main))
(vec
(for [db [now ;; 29th July 2015
(-> now
(d/since (dt 2 1))) ;; 1st Feb 2015
(-> now
(d/as-of (dt 2 1))) ;; 1st Feb 2015
(-> now
(d/since (dt 2 1)) ;; 1st Feb 2015
(d/as-of (dt 4 1)))]] ;; 1st April 2015
[db
(->> db d/basis-t)
(->> db d/next-t)
(->> db d/basis-t d/t->tx)
(->> db d/basis-t d/t->tx (d/entity db) d/touch)]))])
[#<Connection
{:db-id "db-50d3055e-99fc-4639-835c-16c5e88890f7"
:index-rev 625
:basis-t 25630814
:next-t 25630816
:unsent-updates-queue 0
:pending-txes 0}>
;; I thought i would see different :basis-tx, :next-t, :t->tx, and
;; entities for each of these cases.
[{:db datomic.db.Db@8f42a8dd
:basis-t 25630814
:next-t 25630816
:t->tx 13194165164126
:touched-entity
{:db/txInstant #inst "2015-07-29T08:45:22.093-00:00"
:db/id 13194165164126}}
{:db datomic.db.Db@8e6794f5
:basis-t 25630814
:next-t 25630816
:t->tx 13194165164126
:touched-entity
{:db/txInstant #inst "2015-07-29T08:45:22.093-00:00"
:db/id 13194165164126}}
{:db datomic.db.Db@8e1d54f5
:basis-t 25630814
:next-t 25630816
:t->tx 13194165164126
:touched-entity {:db/id 13194165164126}}
{:db datomic.db.Db@8d2bde09
:basis-t 25630814
:next-t 25630816
:t->tx 13194165164126
:touched-entity {:db/id 13194165164126}}]]
@tonsky
Copy link

tonsky commented Jul 29, 2015

(let [now (db/db)
      f   (fn [t]
            (when t
              [t (d/t->tx t) (d/touch (d/entity now (d/t->tx t)))]))]
  (for [db [now ;; 29th July 2015
            (-> now
                (d/since #inst "2015-02-01")) ;; 1st Feb 2015
            (-> now
                (d/as-of #inst "2015-02-01")) ;; 1st Feb 2015
            (-> now
                (d/since #inst "2015-02-01")      ;; 1st Feb 2015
                (d/as-of #inst "2015-04-01"))]]   ;; 1st April 2015
    { :basis  (f (d/basis-t db))
      :next   (f (d/next-t db))
      :as-of  (f (d/as-of-t db)) 
      :since  (f (d/since-t db))
      }))

{:basis [25642501 13194165175813 {:db/id 13194165175813
                                  :db/txInstant #inst "2015-07-28T20:24:07.403-00:00"}]
 :next [25642504 13194165175816 {:db/id 13194165175816}]
 :as-of nil
 :since nil} 

{:basis [25642501 13194165175813 {:db/id 13194165175813
                                  :db/txInstant #inst "2015-07-28T20:24:07.403-00:00"}]
 :next [25642504 13194165175816 {:db/id 13194165175816}]
 :as-of nil
 :since [19229736 13194158763048 {:db/id 13194158763048
                                  :db/txInstant #inst "2015-01-31T22:30:08.353-00:00"}]} 

{:basis [25642501 13194165175813 {:db/id 13194165175813
                                  :db/txInstant #inst "2015-07-28T20:24:07.403-00:00"}]
 :next [25642504 13194165175816 {:db/id 13194165175816}]
 :as-of [19229736 13194158763048 {:db/id 13194158763048
                                  :db/txInstant #inst "2015-01-31T22:30:08.353-00:00"}]
 :since nil} 

{:basis [25642501 13194165175813 {:db/id 13194165175813
                                  :db/txInstant #inst "2015-07-28T20:24:07.403-00:00"}]
 :next [25642504 13194165175816 {:db/id 13194165175816}]
 :as-of [21809460 13194161342772 {:db/id 13194161342772
                                  :db/txInstant #inst "2015-03-31T23:55:05.636-00:00"}]
 :since [19229736 13194158763048 {:db/id 13194158763048
                                  :db/txInstant #inst "2015-01-31T22:30:08.353-00:00"}]}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment