Clojure/Datomic Reader Macro Gotcha
Datomic schema transactions are quite verbose, so I created a little helper for myself...
(defn attr [ident type]
{:db/id #db/id [:db.part/db]
:db/ident ident
:db/valueType type
:db/cardinality :db.cardinality/one
:db.install/_attribute :db.part/db})
Spot the mistake? No, well it took me some debugging to find too. Reader macros are expanded (as the name suggests) at compile time like normal macros. So the #db/id reader macro for creating a new temporary ID is only ever executed once, giving all my attributes the same ID.
Doh! So I need to change it to (only change shown)...
:db/id (d/tempid :db.part/db)
So, just something to remind yourself of when using them.
Written by Rhodri Pugh
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Clojure
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#