How can I get the current Datomic schema?

Since the Datomic schema itself is stored in Datomic, how can I query Datomic to get the installed schema? I want to get only the user level diagram, excluding the system level diagram, which has things like partitions.

+4
source share
2 answers

According to the Datomic docs , the user level scheme must be installed in the partition :db.part/db. The following function gets all the attributes of the schema in this section, given the Datomic connection.

(defn get-user-schema [conn]
  (d/q '[:find ?id
         :where [?e :db/ident ?id]
                [_ :db.install/attribute ?e]
                [?e :db.install/partition :db.part/db]]
       (d/db conn)))

Related: Is there a canonical way of capturing all ids from a specific separation element?

+3
source

Datomic Datalog, , , :

[:find ?attr ?type ?card
 :where
 [_ :db.install/attribute ?a]
 [?a :db/valueType ?t]
 [?a :db/cardinality ?c]
 [?a :db/ident ?attr]
 [?t :db/ident ?type]
 [?c :db/ident ?card]]

- :

schema query results

http://www.learndatalogtoday.org/chapter/4 ( 2 ).

+1

All Articles