Last active
November 16, 2021 12:48
-
-
Save refset/a61a89cfb6bd505ed306a18a9132c62f to your computer and use it in GitHub Desktop.
lazy-authz-subquery-with-limit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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