datalevin db/id vs db/ident

239 Views Asked by At

I want to use Datalevin as a database for my app. The README mentions :db/id as the identifier of entities, and I see these do get an autoincremented integer value on insertion.

However, there are also multiple mentions of :db/ident in the source code, for example for implicit constants.

What are the purposes of the two keywords and what are the differences?

1

There are 1 best solutions below

0
cfrick On BEST ANSWER

:db/ident are called Entity Identifiers in Datomic.

They are used to allow for easier "pointing" to other, well known things; like an enum. So you can have the enum values as datums, but still be able to reference them via a keyword (no need to look them up every time before using them).

E.g.

(def conn (d/create-conn "./tst" {})) 
  
(d/transact! conn  
             [{:db/id 1, :customer-type/name "Fictional", :db/ident :fictional}
              {:db/id 2, :customer/name "ACME", :customer/type :fictional}])   
  
(d/pull @conn                                                                                         
        [:db/id :customer/name {:customer/type [:db/id :customer-type/name]}]
        2)  
; ⇒ {:db/id 2, :customer/name "ACME", 
;    :customer/type {:db/id :fictional, 
;                    :customer-type/name "Fictional"}}