-
-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
filter whole entities with d/filter #63
Comments
What is your source? Db? Datoms? Entities? (d/q '[:find [?e ...]
:in $ ?n
:where [?e :name n]]
db "Ivan")
;; => [1, 2, 3]
(filter (fn [datom]
(and (= (.-a datom) :name)
(= (.-v datom) "Ivan")))
datoms)
;; => [#datascript.core/Datom{:e 1, :a :name, :v "Ivan"}, ...]
(filter (fn [entity]
(= (:name entity) "Ivan"))
entities)
;; => [{:db/id 1, :name "Ivan"}, {:db/id 2, :name "Ivan"}, ...] |
Oh, you’re asking about (d/filter db
(fn [db datom]
(and (= (.-a datom) :name)
(= (.-v datom) "Ivan")))) This will only keep datoms which are about
without any other properties of entity. You probably want to keep any attributes of entity if that entity has a :name attribute equal to "Ivan". Then (d/filter db
(fn [db datom]
(let [eid (.-e datom)
entity (d/entity db eid)]
(= "Ivan" (:name entity))))) |
I am rewriting the datascript todo app. The last example is just what i needed. Thanks! |
I open this issue since i can not find a documentation/test on how to accomplish this.
How can i filter an entity based on one attribute value?
For example, i would like to set a filter that will return entities where :name=="Ivan"
will only return
[[{:db/id 1
:name "Petr"
:email "petya@spb.ru"
:aka ["I" "Great"]
:password ""}]
The text was updated successfully, but these errors were encountered: