Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dimovich/872c0c55bdec621fadae357fef92ce62 to your computer and use it in GitHub Desktop.
Save dimovich/872c0c55bdec621fadae357fef92ce62 to your computer and use it in GitHub Desktop.
DataScript set intersection query
;; A variation for DataScript
(defn make-intersection-q
"Generate an intersection q for searchable tags."
[n]
(assert (pos? n))
(into
[:find '[(pull ?e [*]) ...]
:in '$ (->> (range 1 (inc n)) (mapv #(symbol (str "?v" %))))
:where]
(map
(fn [n]
['?e :tags (symbol (str "?v" n))])
(range 1 (inc n)))))
(defn search-intersection
[db tags]
(ds/q (make-intersection-q (count tags))
db
tags))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment