Created
January 3, 2017 11:35
-
-
Save pesterhazy/1e0ce9f18035b1693ee9e55241b23be6 to your computer and use it in GitHub Desktop.
Datomic set intersection query
This file contains hidden or 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 make-intersection-q | |
"Generate an intersection q for arbitrary sets of features" | |
[n] | |
(assert (pos? n)) | |
{:find '[[?product-slug ...]] | |
:in ['$ (->> (range 1 (inc n)) (mapv #(symbol (str "?v" %))))] | |
:where | |
(into ['[?product :cat.product/slug ?product-slug]] | |
(map (fn [n] | |
['?product :cat.product/features (symbol (str "?v" n))]) | |
(range 1 (inc n))))}) | |
(defn feature-intersection [db feature-slugs] | |
(d/q (make-intersection-q (count feature-slugs)) | |
db | |
(map (fn [feature-slug] [:cat.feature/slug feature-slug]) | |
feature-slugs))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you. That was helpful.