This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-05-12
Channels
- # announcements (2)
- # aws (1)
- # beginners (63)
- # cider (2)
- # clj-kondo (1)
- # cljdoc (15)
- # clojure (114)
- # clojure-nl (1)
- # clojure-spec (15)
- # clojure-uk (10)
- # clojurescript (5)
- # clojutre (1)
- # community-development (6)
- # cursive (18)
- # data-science (1)
- # datascript (16)
- # datomic (2)
- # emacs (2)
- # events (3)
- # figwheel-main (2)
- # graphql (3)
- # jobs (2)
- # off-topic (23)
- # reitit (3)
- # shadow-cljs (27)
- # spacemacs (5)
- # sql (27)
- # unrepl (1)
I keep seeing { :aliases { :db/cardinality :db.cardinality/many } }
as a schema in examples. what does it do?
also, I know that a lot of the core library operates on an atom “connection”. are these changes executed synchronously?
OK, so it sounds like the alias
is being defined as an attribute which is cardinality many. got it.
Yes. You can use negative ids or arbitrary strings. All matching ids will resolve to the same real id inside single transaction
That is precisely the case. You can use negative IDs within your transaction to establish relationships, DataScript will fill-in the correct ones.
I have another newbie question. I’m playing around with moving parts of my application to DataScript
my first attempt is at routing. here’s my initial transaction:
[{:db/id -1
:router/current :tap-list
:router/routes [{:id :tap-list
:label "Taps"}
{:id :inspector
:label "Inspector"}]}]
Instead of route/current at separate entity I usually assign :route/current? true
flag on the route that is currently selected. That way you can look up via [:route/current? true] and get the currently selected route (don’t forget to mark it unique/identity)
this is kind of weird, though, because routing is a kind of singleton thing. I’m not sure how to write the transaction to update this yet
thinking about this now: perhaps it would be better to model it as a cardinality-many of history, and query for the latest one
I usually model singletons with idents. Idents are implemented via a separate attribute with the {:db/unique :db.unique/identity} property. Nowadays, this comes built-in (https://github.com/tonsky/datascript/blob/master/src/datascript/db.cljc#L24). In your example, you could the replace {:db/id -1} with {:db/ident :router} and use that throughout your app.