Skip to content

Instantly share code, notes, and snippets.

@refset
Last active November 16, 2021 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save refset/a61a89cfb6bd505ed306a18a9132c62f to your computer and use it in GitHub Desktop.
Save refset/a61a89cfb6bd505ed306a18a9132c62f to your computer and use it in GitHub Desktop.
lazy-authz-subquery-with-limit
(defn authz-subquery [db q authz-q]
(let [limit (:limit q)
q (dissoc q :limit)]
(with-open [qi (xt/open-q db q)]
(->> (iterator-seq qi)
(map first)
(xt/q db authz-q)
(keep seq)
(map first)
(distinct)
(take limit)
doall))))
(def n (xt/start-node {}))
(->> [[::xt/put {:xt/id :foo :a "string"}]
[::xt/put {:xt/id :bar :a "string2"}]]
(xt/submit-tx n)
(xt/await-tx n))
(xt/q (xt/db n) '{:find [e]
:where [[(dev/authz-subquery $
{:find [e]
:limit 2
:where [[e :a s]]}
{:find [e]
:in [[e ...]]
:where [[e :a s]
[(clojure.string/starts-with? s "string")]]})
[e ...]]]})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment