Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a canonical way to grab all idents from a particular datomic namespace?

say I had :user/name and :user/gender installed as datomic schema.

(pprint (d/q '[:find ?ident :where
               [?e :db/ident ?ident]
               [_ :db.install/attribute ?e]] (d/db conn)))

finds all the db.install/attributes

 #{[:db/code] [:user/gender] [:fressian/tag] [:db/unique] [:user/name] [:db/fn] 
 [:db/noHistory] [:db/fulltext] [:db/lang] [:db/valueType] [:db/doc]
 [:db/isComponent] [:db.install/function] [:db/cardinality] [:db/txInstant] [:db/index]}

however, I only want to list items in the :user namespace

[:user/gender] [:user/name]

what should I add to the query or is there a function that does it automatically?

like image 427
zcaudate Avatar asked Feb 06 '13 03:02

zcaudate


2 Answers

I figured it out

(d/q '[:find ?ident :where
           [?e :db/ident ?ident]
           [_ :db.install/attribute ?e]
           [(.toString ?ident) ?val]
           [(.startsWith ?val ":user")]] (d/db *conn*))

;; => #{[:user/gender] [:user/firstName]}
like image 53
zcaudate Avatar answered Oct 29 '22 18:10

zcaudate


You can use the Tupelo Datomic library to grab all EIDs for a given partition. Just use:

(ns xyz
  (:require [tupelo.datomic :as td] ...

  ; Create a partition named :people (we could namespace it like :db.part/people if we wished)
  (td/transact *conn* 
    (td/new-partition :people ))

; Find all EID's in the :people partition
(let [people-eids (td/partition-eids *conn* :people) ]
   ...)

More information can be found in the Datomic Mailing List. Enjoy!

like image 23
Alan Thompson Avatar answered Oct 29 '22 17:10

Alan Thompson