mozilla / mentat

UNMAINTAINED A persistent, relational store inspired by Datomic and DataScript.
https://mozilla.github.io/mentat/
Apache License 2.0
1.65k stars 115 forks source link

[query] Allow to bind `[(min ?t) ?t0]` #750

Open ncalexan opened 6 years ago

ncalexan commented 6 years ago

Mentat allows to order results; Datomic does not. When expressing "least or greatest in a group" style queries, the fact that we can't manipulate the max or min outside of the find spec is limiting. That is, it's not easy to ask for "the 10 most recently used items" or whatever.

I think we might be able to bind scalars to achieve this. That is, we might find that

:find
 [?e ...]
:where
 [?e :value ?v]
 [(min ?v) ?v0]
:order
 (desc ?v0)
:limit
 10

is generally useful.

thomcc commented 6 years ago

Some more context in #815. I think either this or #647 are needed to do even a fairly naive top-sites list (which just finds the top N most visited urls) would need to order by count, either as a :order (desc ?numVisits) where there's a [(count ?visit) ?numVisits], or as a more direct :order (count ?visit).