How are people pulling collections in cloud?

#1

Since the find-coll … expression and pull-many is not available, are people using recursive pulls? I’m using ions and was a bit surprised that find-coll was not available in the :ion server type.

Cheers,
Dean

#2

If I understand you correctly, you can use pull syntax in a recursive way. Consider the following schema:

{:pull-request/author   {:db/valueType :db.type/ref}
 :pull-request/comments {:db/valueType :db.type/ref
                         :db/cardinality :db.cardinality/many}
 :comment/author        {:db/valueType :db.type/ref}}

You could then

(require '[datascript.core as ds)
(def test-db ...)

(ds/q '[:find [(pull ?e [* {:pull-request/comments [* {:comment/author [*]}]}]) ...]
        :where
        [?e :pull-request/title]]
      @test-db)
;; => [{:db/id 1,
;;      :pull-request/author #:db{:id 2},
;;      :pull-request/comments
;;      [{:db/id 3,
;;        :comment/author
;;        {:db/id 5, :user/avatar "http://avatars.com/cjno", :user/name "Christian"},
;;        :comment/text "A question"}
;;       {:db/id 4,
;;        :comment/author
;;        {:db/id 2, :user/avatar "http://avatars.com/magnars", :user/name "Magnar"},
;;        :comment/text "A reply"}],
;;      :pull-request/title "A pull request"}]

Note: I’ve tested the above with Datascript and not Datomic, but I think the behavior is the same.

#4

Thanks @teodorlu. I’d made an assumption a while ago about find-coll which was incorrect. I was using

 [(pull ?e [* {:pull-request/comments [* {:comment/author [*]}]}]) ...]

when in fact

(pull ?e [* {:pull-request/comments [* {:comment/author [*]}]}]) 

does the job.

#5

Glad to hear it helped!