Fork me on GitHub

Hi, does Datalevin support a query limit to get e.g. just 10 results? I’ve been trying the map-args version of q as suggested , but can’t get it to work. I see that that map-args variant of q is in fact mentioned in the linked in Datalevins doc string for q, but is it actually supported? Simple experiment with map-args:

(def my-query '[:find [?email ...]
                  [_ :user/email ?email]])

  ;; OK
  (d/q my-query @db/conn)

  ;;NOK: Execution error... Cannot parse :find ...
  (d/q {:query my-query
        :args  [@db/conn]})


Query in the map form should be fine, as the vector query is turned into a map anyway. However, I don’t think limit is currently supported. You can file an issue. We work through the issues whenever we can.


OK, thanks. Should the {:query … :args […]} syntax itself work? Based on the Datomic example I was hoping for something like this where find is still in vector form, but wrapped in a map:

(d/q {:query   '[:find [?email ...]
                 [_ :user/email ?email]]
      :args    [@db/conn]
      :limit   10
      :offset  20
      :timeout 60000})
Disregarding missing support for :limit (and possibly :offset and :timeout) at the moment.


the supported map is for the query itself


This format you are showing is probably not the version of Datomic on-prem that Datascript was modeled against. However, I think these are superficial differences that reflect how Datomic is specifically implemented. I would probably put these features in the query itself to have a more consistent and simpler query API. We refer people to Datomic’s documentation for we have not had the time to write our own, so people shouldn’t expect the same API. Good documentation will be available when we reach 1.0.


in any case, file an issue and we will get to them eventually. Right now, my priority is to finish the query engine rewrite, so I can feel comfortable promoting this project.


Thanks for the clarification. I’ll file an issue in the next few days. For now I just limited the result with take and I think that will work just fine.


I suspect “take” is how datomic is implementing the limit, hence these things are at a layer outside the query.


Ideally, these should be part of the query, so query engines can optimize them better.


In my opinion, Datalevin’s query engine has more potential to optimize things, since it follows a traditional database architecture.


Not heeding the lessons of an half century of database research has its pitfalls.

👍 1

@U0A74MRCJ on the basis of this thread and the datalevin API, it seems query timeout is not supported at the moment, right? If yes, and in case you would want a PR for this, do you have any pointers as to how one would go about adding it?


I don’t have nay pointers. You can propose some approaches.