This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-19
Channels
- # announcements (10)
- # aws (3)
- # aws-lambda (1)
- # babashka (24)
- # beginners (57)
- # boot (5)
- # calva (20)
- # chlorine-clover (3)
- # cider (14)
- # clj-kondo (37)
- # clojars (17)
- # clojure (200)
- # clojure-dev (40)
- # clojure-europe (9)
- # clojure-france (7)
- # clojure-gamedev (5)
- # clojure-hungary (4)
- # clojure-italy (8)
- # clojure-losangeles (2)
- # clojure-nl (9)
- # clojure-uk (97)
- # clojurebridge (1)
- # clojured (3)
- # clojuredesign-podcast (23)
- # clojurescript (13)
- # code-reviews (2)
- # component (22)
- # core-typed (7)
- # cursive (64)
- # datascript (12)
- # datomic (60)
- # emacs (6)
- # fulcro (54)
- # graalvm (11)
- # graphql (3)
- # hoplon (25)
- # jobs (1)
- # joker (85)
- # juxt (5)
- # kaocha (10)
- # klipse (8)
- # malli (2)
- # off-topic (36)
- # parinfer (1)
- # pathom (1)
- # re-frame (9)
- # reagent (4)
- # reitit (1)
- # remote-jobs (1)
- # shadow-cljs (24)
- # spacemacs (1)
- # sql (39)
- # tools-deps (10)
- # tree-sitter (18)
- # xtdb (18)
Hello guys.
Can someone point me to the documentation or example of how to work properly with nested entities in datascript?
for example, I have an entity parent
which has a children
property and this property is a reference with cardinality many
It’s simple to add the new references but it’s not clear how to delete references (without deleting child entities itself)
I will appreciate for any help.
Hello @UF2GC1JRM 👋 This is relatively straightforward using retractions:
(d/transact conn {:tx-data [[:db/retract parent :children child1]])
This would retract the fact that child1
is a child of parent
. You would first need to query for the entity ids to obtain both parent
and child1
, and then use them in the transaction. If you wanted to remove multiple parent/child relationships in one go:
(d/transact conn {:tx-data [[:db/retract parent :children child1]
[:db/retract parent :children child2]
[:db/retract parent :children child3]]})
Here is a potentially helpful reference page: https://github.com/tonsky/datascript/wiki/FAQ Keep in mind that the Datomic API docs are usually helpful as well, with a few differences. Cross referencing the Datomic documentation with the datascript wiki is a good strategy.
Hi @U6GFE9HS7. Thanks, will give it a try
(def schema
{:thing/parent {:db/unique :db.unique/identity}
:thing/child {:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many
:db/isComponent true}})
The key part is the :db/isComponent true
Will usually improve your experience with parent/child stuff
Yes, it could help but in my case from domain modeling perspective the child entity it's not the component of the parent entity
Right. :db/isComponent
will cause the child to be retracted along with the parent, which from your problem description is not what you want.
To answer your specific question, to delete a reference from :thing/parent
to :thing/child
you can simply assert
(d/trasnsact conn
[[:db/retract [:thing/parent parent-id] :thing/children [:thing/child child-id]])
Not sure if that helpsCan you define rules in the :where
clause? I.e, as opposed to passing them into :in
?
I'm using Roam Research, a web app for note taking with built in Datascript queries of your notes. It supports the where
clause, but not in
. I tried this:
[:find ?content
:where
[?e :node/title ?title]
[(re-find #"February 21st" ?title)]
[(parent ?a ?b)
[?a :block/children ?b]]
(parent ?e ?x)
[?x :block/string ?content]
]
The idea is to make a rule called parent
that I can use in another rule called ancestor
, allowing me to do recursive queries. But I get the following error:
Cannot parse binding, expected (bind-scalar | bind-tuple | bind-coll | bind-rel)