Request a list of all partitions in Datomic

What is a query to list all sections of a Datomic database?

This should return

[[:db.part/db] [:db.part/tx] [:db.part/user] .... ] 

where .... - all user sections.

+6
source share
2 answers

You should be able to get a list of all partitions in the database by searching for all objects associated with the object :db.part/db , using the attribute :db.install/partition :

 (ns myns (:require [datomic.api :as d])) (defn get-partitions [db] (d/q '[:find ?ident :where [:db.part/db :db.install/partition ?p] [?p :db/ident ?ident]] db)) 

Note

The current version of Datomic (build 0.8.3524) has a drawback, so :db.part/tx and :db.part/user (two of the three built-in partitions) are specially processed and are not actually associated with :db.part/db via :db.install/partition , so the result of the above request function will not contain these two.

This issue will be addressed in a future Datomic compilation. In the meantime, you should take care to include :db.part/tx and :db.part/user in the result set.

+7
source

1st method - using the request

 => (q '[:find ?i :where [:db.part/db :db.install/partition ?p] [?p :db/ident ?i]] (db conn)) 

The second method is from the db object

 (filter #(instance? datomic.db.Partition %) (:elements (db conn))) 

The second method returns a sequence of datomic.db.Partition objects, which can be useful if we want to get additional information about the section.

Both methods know an error / inconsistency: they do not return: db.part / tx and: db.part / user built-in sections.

+1
source

Source: https://habr.com/ru/post/925532/


All Articles