Skip to content

Instantly share code, notes, and snippets.

@Jaretbinford
Created November 8, 2019 16:03
Show Gist options
  • Save Jaretbinford/c41d0d9a14d3ea6134790900e471b2aa to your computer and use it in GitHub Desktop.
Save Jaretbinford/c41d0d9a14d3ea6134790900e471b2aa to your computer and use it in GitHub Desktop.
;First transaction
(d/transact conn {:tx-data [{:db/ident :account/id
:db/valueType :db.type/uuid
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity
:db/doc "foo"}]})
=>
{:db-before {:database-id "datomic:dev://localhost:4334/mbrainz-1968-1973",
:db-name "mbrainz",
:t 246349,
:next-t 249160,
:type :datomic.client/db},
:db-after {:database-id "datomic:dev://localhost:4334/mbrainz-1968-1973",
:db-name "mbrainz",
:t 249160,
:next-t 249161,
:type :datomic.client/db},
:tx-data [#datom[13194139782472 50 #inst"2019-11-08T15:06:20.703-00:00" 13194139782472 true]
#datom[139 10 :account/id 13194139782472 true]
#datom[139 40 56 13194139782472 true]
#datom[139 41 35 13194139782472 true]
#datom[139 42 38 13194139782472 true]
#datom[139 62 "foo" 13194139782472 true]
#datom[0 13 139 13194139782472 true]],
:tempids {-9223301668109598143 139}}
;TX-ID1: 13194139782472
;Second Transaction
(-> (d/tx-range conn {:start #inst"2019-11-08T15:35:09.993-00:00"})
first :data)
=>
[#datom[13194139782473 50 #inst"2019-11-08T15:35:09.993-00:00" 13194139782473 true]
#datom[139 62 "foobar" 13194139782473 true]
#datom[139 62 "foo" 13194139782473 false]]
;TX-ID2: 13194139782473
(d/pull db '[:db/txInstant] 13194139782472)
=> #:db{:txInstant #inst"2019-11-08T15:06:20.703-00:00"}
(d/pull db '[:db/txInstant] 13194139782473)
=> #:db{:txInstant #inst"2019-11-08T15:35:09.993-00:00"}
;;Getting the two T's:
(-> (d/tx-range conn {:start #inst"2019-11-08T15:06:20.703-00:00"})
first :t)
=> 249160
(-> (d/tx-range conn {:start #inst"2019-11-08T15:35:09.993-00:00"})
first :t)
=> 249161
;T1
(def as-of-y-t (d/as-of db 249160))
=> #'releasetest.core/as-of-y-t
(d/q '[:find ?doc
:where
[?e :db/ident :account/id]
[?e :db/doc ?doc]] as-of-y-t)
=> [["foo"]]
;T2
(def as-of-y-t (d/as-of db 249161))
=> #'releasetest.core/as-of-y-t
(d/q '[:find ?doc
:where
[?e :db/ident :account/id]
[?e :db/doc ?doc]] as-of-y-t)
=> [["foobar"]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment