Fork me on GitHub
#datascript
<
2024-03-03
>
teodorlu13:03:31

Hi! I have a datascript query that returns a sequence of vectors of maps. All the vectors are of length 1. Is there a way to write the datascript query to return a sequence of maps instead?

(->>
 (d/q '[:find (pull ?e [:slug :title])
        :where
        [?e :page/slug ?slug]
        [?e :title ?title]
        [?e :form :remote-reference]]
      db)
 shuffle
 (take 3))
;; =>
;; ([{:slug "roam-research", :title "Roam Research"}]
;;  [{:slug "j-programming-language", :title "J (programming language)"}]
;;  [{:slug "eliyahu-goldratt", :title "Eliyahu Goldratt"}])

1
Niki20:03:21

I think it should be

(d/q '[:find [(pull ?e [:slug :title]) ...]
       :where ...])

👍 1
teodorlu20:03:32

That did the trick. Thank you! I tried reading the Datomic docs, but I didn’t find the right section.

(->>
 (d/q '[:find [(pull ?e [:slug :title]) ...]
        :where
        [?e :form :remote-reference]]
      db)
 shuffle
 (take 3))
;; => ({:slug "emacs-lisp", :title "Emacs Lisp"}
;;     {:slug "antifragile", :title "Antifragile"}
;;     {:slug "dtype-next", :title "dtype-next"})

Niki20:03:41

Yeah it’s pretty obscure, and syntax doesn’t help either

👍 1