Fork me on GitHub
#datascript
<
2019-05-12
>
lilactown16:05:41

I keep seeing { :aliases { :db/cardinality :db.cardinality/many } } as a schema in examples. what does it do?

lilactown16:05:40

I also see transactions with negative :db/id. why is that?

lilactown16:05:53

also, I know that a lot of the core library operates on an atom “connection”. are these changes executed synchronously?

lilactown16:05:07

I want to pretty much ignore the atom and use my own state container

lilactown16:05:22

OK, so it sounds like the alias is being defined as an attribute which is cardinality many. got it.

lilactown16:05:24

it also sounds like negative db/id’s are used as temporary IDs?

tonsky14:05:57

Yes. You can use negative ids or arbitrary strings. All matching ids will resolve to the same real id inside single transaction

ncg17:05:42

That is precisely the case. You can use negative IDs within your transaction to establish relationships, DataScript will fill-in the correct ones.

lilactown17:05:33

I have another newbie question. I’m playing around with moving parts of my application to DataScript

lilactown17:05:11

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"}]}]

tonsky14:05:37

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)

👍 1
lilactown17:05:45

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

lilactown17:05:45

thinking about this now: perhaps it would be better to model it as a cardinality-many of history, and query for the latest one

lilactown17:05:51

gotta figure out how to preserver order..

ncg23:05:14

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.