This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-22
Channels
- # arachne (8)
- # bangalore-clj (1)
- # beginners (72)
- # boot (95)
- # braveandtrue (5)
- # business (1)
- # capetown (1)
- # cider (180)
- # cljs-dev (8)
- # cljsrn (20)
- # clojure (104)
- # clojure-art (1)
- # clojure-brasil (8)
- # clojure-czech (1)
- # clojure-greece (15)
- # clojure-korea (13)
- # clojure-poland (2)
- # clojure-russia (53)
- # clojure-sg (5)
- # clojure-spec (60)
- # clojure-uk (35)
- # clojurescript (186)
- # community-development (3)
- # core-async (24)
- # cursive (18)
- # datascript (11)
- # datomic (39)
- # devcards (4)
- # emacs (2)
- # events (1)
- # funcool (23)
- # hoplon (148)
- # juxt (1)
- # ldnclj (2)
- # luminus (1)
- # off-topic (22)
- # om (27)
- # onyx (35)
- # overtone (2)
- # pedestal (7)
- # perun (8)
- # protorepl (2)
- # rdf (6)
- # re-frame (15)
- # reagent (2)
- # ring-swagger (10)
- # untangled (54)
(def conn (d/create-conn {}))
(d/transact! conn
[{:msg "hi", :done? false}
{:msg "hi", :done? true}
{:msg "low", :done? false}])
(defmacro select [conn m]
`(->> (d/q (quote [:find ~'?e :where
~@(mapv (fn [[k# v#]] ['?e k# v#]) m)])
~conn)
(mapv first)
(d/pull-many ~conn '[~'*])))
(select @conn {:done? false})
;; => [{:db/id 3, :done? false, :msg "low"} {:db/id 1, :done? false, :msg "hi"}]
(select @conn {:done? true})
;; => [{:db/id 2, :done? true, :msg "hi"}]
(select @conn {:done? true :msg "hi"})
;; => [{:db/id 2, :done? true, :msg "hi"}]
I want a select function/macro that works like above... I'm a datascript noob and curious if something like that already exists.
@escherize Tonsky and other use es-by-av
or e-by-av
which works for just one attr-value pair, by going straight into the index.
Sorry, wanted to post a link but got distracted: https://gist.github.com/rauhs/260a8f255f33e72308cd592bf5e2cd6d
(https://gist.github.com/rauhs/260a8f255f33e72308cd592bf5e2cd6d#file-ds-helpers-cljs-L53)
@escherize Oh darn, I thought I removed those macro calls. But yeah, that's it 🙂