What do all fields mean for db.part / db?

I'm new to datomic and I'm still trying to figure out how the system was built. In particular, I do not understand what role db.part / db plays, since it seems necessary every time you install the circuit. Can anyone shed light on what all this means?

  (require '[datomic.api: as d])
 (def uri "datomic: mem: // sample")
 (d / create-database uri)
 (def conn (d / connect uri))

 (pprint (seq (d / entity dbval: db.part / db)))

 ;;  => 
 ;;  ([: db / doc "Name of the system partition. The system partition includes the core of datomic, as well as user schemas: type definitions, attribute definitions, partition definitions, and data function definitions."]
 ;;  [: db.install / function # {: db.fn / cas: db.fn / retractEntity}]
 ;;  [: db.install / attribute
 ;;  # {: db / noHistory: db.install / partition: db / cardinality
 ;;  : db.install / attribute: db / index: db / unique: db / fulltext
 ;;  : db / txInstant: db / lang: db / doc: db.install / valueType: db / code
 ;;  : db / isComponent: db / fn: db.install / function: db / valueType: db / ident
 ;;  : fressian / tag}]
 ;;  [: db.install / valueType
 ;;  # {: db.type / uuid: db.type / bigint: db.type / uri: db.type / ref
 ;;  : db.type / keyword: db.type / bytes: db.type / string: db.type / instant
 ;;  : db.type / fn: db.type / long: db.type / bigdec: db.type / boolean
 ;;  : db.type / double: db.type / float}]
 ;;  [: db.install / partition # {: db.part / db}]
 ;;  [: db / ident: db.part / db])
+6
source share
1 answer

:db.part/db - this is the section for schematic objects (see schema documents for sections ). These db.install attributes are used to trigger hooks when installing certain objects. The fact that they are approved in :db.part/db doesn't really matter (afaik), it's just the convention that the Datomic team has chosen to represent setting attributes, etc.

So, for example, when you submit a transaction, for example:

 [{:db/ident :person/name :db/cardinality :db.cardinality/one :db/valueType :db.type/string :db.install/_attribute :db.part/db :db/id #db/id[:db.part/db]}] 

which is equivalent (in Clojure now instead of edn):

 (let [id (datomic.api/tempid :db.part/db)] [[:db/add id :db/ident :person/name] [:db/add id :db/cardinality :db.cardinality/one] [:db/add id :db/valueType :db.type/string] [:db/add :db.part/db :db.install/attribute id]]) 

then Datomic notes that you added the value for :db.part/db :db.install/attribute , confirming that you provided the necessary attributes for the attribute, and setting the new attribute to the database so that you can use it after the transaction.

Similarly, you can use :db.install/_partition :db.part/db to install new partitions. See Documents in Setting an Attribute Definition and Creating New Partitions .

:db.install/valueType may someday be used to set your own custom value types, but this function is not ready yet. :db.install/function appears for internal use. I am not sure of his purpose. The documented way to set the database functions is different.

These attributes (except :db.install/function ) are also convenient for querying and checking db. For example, we can pull out a set of all the established value types if we forget:

 user> (:db.install/valueType (datomic.api/entity db :db.part/db)) #{:db.type/uuid :db.type/bigint :db.type/uri :db.type/ref :db.type/keyword :db.type/bytes :db.type/string :db.type/instant :db.type/fn :db.type/long :db.type/bigdec :db.type/boolean :db.type/double :db.type/float} 

Or we can write queries on existing attributes:

 user> (datomic.api/q '[:find ?ns (distinct ?attr) :where [:db.part/db :db.install/attribute ?a] [?a :db/ident ?attr] [(namespace ?attr) ?ns]] db) [["db" #{:db/noHistory :db/cardinality :db/index :db/unique :db/fulltext :db/txInstant :db/lang :db/doc :db/code :db/isComponent :db/fn :db/valueType :db/ident}] ["db.install" #{:db.install/partition :db.install/attribute :db.install/valueType :db.install/function}] ["fressian" #{:fressian/tag}]] 
+9
source

All Articles