datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
fmn 2018-05-26T03:06:58.000061Z

Anybody knows why this doesn't work?

(let [conn    (d/create-conn
               {:user/name {:db/unique :db.unique/identity}})
      tempid  (d/tempid :db.part/user)
      tx-data [[:db/add tempid :user/name "foobar"]
               [:db.fn/cas tempid :foo/bar nil true]]]
  (-> @conn
      (d/with tx-data)
      (:db-after)
      (d/pull ['*] [:user/name "foobar"])))
Pulled data doesn't have :foo/bar key: {:db/id 1, :user/name "foobar"} Inspecting the tx-report yields:
{:db-before {},
 :db-after {-1000064 :foo/bar, 1 :user/name},
 :tx-data
 [#datascript/Datom [1 :user/name "foobar" 536870913 true]
  #datascript/Datom [-1000064 :foo/bar true 536870913 true]],
 :tempids {-1000064 1, :db/current-tx 536870913}, 
 :tx-meta nil}
The datom has different eid. If I replace tempid with hard-coded positive integer e.g 1, it yields the correct result: {:db/id 1, :foo/bar true, :user/name "foobar"}

2018-05-26T07:22:15.000006Z

@funyako.funyao156 please create an issue. I’ll take a look when I have time