Forked from pesterhazy/datomic-set-intersection.clj
Last active
January 11, 2019 17:46
-
-
Save dimovich/872c0c55bdec621fadae357fef92ce62 to your computer and use it in GitHub Desktop.
DataScript 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
;; 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