datomic

Ask questions on the official Q&A site at https://ask.datomic.com!
zendevil 2021-03-28T01:54:40.140900Z

I have this query: https://gist.github.com/zendevil/4d0f1a844208ceb01375c686eec1f930 And basically I want to sort the ?content based on the attribute :content/event-timestamp-lng which is a long. What’s the best way to do that? Does it have to be using a custom aggregate or can it be achieved inside the query? If it has to be a custom aggregate, how do you combine the pull expression with it?

2021-03-28T11:43:07.142900Z

Usually you sort in clojureland, using sort-by or the likes

2021-03-28T11:43:24.143700Z

Datomic always returns a returnset, which has no order guarantees

souenzzo 2021-03-29T00:09:20.144100Z

(-> '[:find (pull ?content [*])
      :in $ ?user-id-string
      :where
      [?user-id :user/id-string ?user-id-string]
      [?content :content/user ?user-id]
      (not [?content :content/deleted true])]
    (d/q db user-id-string)
    (->> (map first)
         (sort-by :content/event-timestamp-lng)))