Skip to content

Commit

Permalink
Add get to built-ins for binding on map values
Browse files Browse the repository at this point in the history
  • Loading branch information
logseq-cldwalker authored and tonsky committed Jan 31, 2022
1 parent 9c09ba5 commit 8989723
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/datascript/built_ins.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@
false)))

(def query-fns {
'= =, '== ==, 'not= not=, '!= not=,
'< less, '> greater, '<= less-equal, '>= greater-equal,
'+ +, '- -, '* *, '/ /,
'= =, '== ==, 'not= not=, '!= not=,
'< less, '> greater, '<= less-equal, '>= greater-equal,
'+ +, '- -, '* *, '/ /,
'quot quot, 'rem rem, 'mod mod, 'inc inc, 'dec dec, 'max max, 'min min,
'zero? zero?, 'pos? pos?, 'neg? neg?, 'even? even?, 'odd? odd?, 'compare compare,
'rand rand, 'rand-int rand-int,
Expand All @@ -89,7 +89,8 @@
'identity identity, 'keyword keyword, 'meta meta, 'name name, 'namespace namespace, 'type type,
'vector vector, 'list list, 'set set, 'hash-map hash-map, 'array-map array-map,
'count count, 'range range, 'not-empty not-empty, 'empty? empty?, 'contains? contains?,
'str str, 'pr-str pr-str, 'print-str print-str, 'println-str println-str, 'prn-str prn-str, 'subs subs,
'str str, 'subs, subs, 'get get,
'pr-str pr-str, 'print-str print-str, 'println-str println-str, 'prn-str prn-str,
're-find re-find, 're-matches re-matches, 're-seq re-seq, 're-pattern re-pattern,
'-differ? -differ?, 'get-else -get-else, 'get-some -get-some, 'missing? -missing?, 'ground identity,
'clojure.string/blank? str/blank?, 'clojure.string/includes? str/includes?,
Expand Down Expand Up @@ -180,7 +181,7 @@
'distinct set
'min aggregate-min
'max aggregate-max
'rand aggregate-rand
'rand aggregate-rand
'sample aggregate-sample
'count count
'count-distinct aggregate-count-distinct})
8 changes: 8 additions & 0 deletions test/datascript/test/query.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@
"X")
#{["abcX"] ["aXb"]})))

(deftest test-built-in-get
(is (= (d/q '[:find ?m ?m-value
:in [[?k ?m] ...] ?m-key
:where [(get ?m ?m-key) ?m-value]]
{:a {:b 1}
:c {:d 2}}
:d)
#{[{:d 2} 2]})))

(deftest ^{:doc "issue-385"} test-join-unrelated
(is (= #{}
Expand Down

0 comments on commit 8989723

Please sign in to comment.