How to sort the result in a Datalog query

I am using datomic with a playback platform. The game is amazing, datomic - fast. So a good combination overall. Since I am new to datomic (and datalog ie), I cannot sort my result (for example, we do, order in sql). For instance.

if my request:

q= [:find ?title :where [?e :movie/title ?title] [?e :movie/director "Dave Swag"] [?e :movie/year ?year] [(sort ?year)] //here I am trying to sort by year ] 

He must return the names of the films directed by Dave Swag, and the result is sorted by the year in which the image was released. Thankyou :)

+6
source share
1 answer

If you want to sort the result set, you will need to do this outside the query in the returned result set. Here is an example of this in the Datomic blog post about the query in Listing 20:

 (def hist (d/history db)) (->> (d/q '[:find ?tx ?v ?op :in $ ?e ?attr :where [?e ?attr ?v ?tx ?op]] hist editor-id :user/firstName) (sort-by first)) => ([13194139534319 "Ed" true] [13194139534335 "Ed" false] [13194139534335 "Edward" true]) 
+5
source

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


All Articles