Skip to content

Instantly share code, notes, and snippets.

@pesterhazy
Created January 3, 2017 11:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pesterhazy/1e0ce9f18035b1693ee9e55241b23be6 to your computer and use it in GitHub Desktop.
Save pesterhazy/1e0ce9f18035b1693ee9e55241b23be6 to your computer and use it in GitHub Desktop.
Datomic set intersection query
(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)))
@dimovich
Copy link

Thank you. That was helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment