This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-12
Channels
- # aleph (5)
- # announcements (1)
- # asami (29)
- # babashka (2)
- # beginners (36)
- # biff (1)
- # cider (6)
- # clj-kondo (29)
- # clj-together (5)
- # clojars (21)
- # clojure (11)
- # clojure-austin (5)
- # clojure-czech (1)
- # clojure-europe (23)
- # clojure-hk (1)
- # clojure-italy (1)
- # clojure-nl (1)
- # clojure-uk (1)
- # clojurescript (38)
- # clojurewerkz (1)
- # cursive (10)
- # data-science (2)
- # datalevin (15)
- # datomic (8)
- # duct (5)
- # emacs (36)
- # events (4)
- # fulcro (7)
- # garden (1)
- # gratitude (1)
- # interop (4)
- # introduce-yourself (1)
- # leiningen (1)
- # missionary (3)
- # music (3)
- # nbb (4)
- # off-topic (21)
- # polylith (6)
- # remote-jobs (5)
- # shadow-cljs (19)
- # specter (4)
- # xtdb (4)
So, on my (long) way to grokking Asami, I’m trying to understand IDs. I’m trying to do my homework, but a quick question - how does Asami figure out a value represents an ID? (For now, the way out I see is that Asami doesn’t care when storing data, only when resolving queries - but that still leaves temporary IDs. How does Asami figure out I don’t just want the regular negative numer as a property value?)
In case I’m just noobishly off target here, I’ll keep this in a thread. I tried transacting this part from the docs:
{:db/id -1
:inventory/label "Widget"
:inventory/part-nr "THX-1138"
:inventory/stock-count 2187}
{:db/id -2
:inventory/label "Doohicky"
:inventory/part-nr "AA-23"
:inventory/stock-count 5
:inventory/replaces -1}
[:db/add -1 :inventory/replaced-by -2]
The result as shown in the docs is:
:a/node-1031 :inventory/label "Widget"
:a/node-1031 :inventory/part-nr "THX-1138"
:a/node-1031 :inventory/stock-count 2187
:a/node-1032 :inventory/label "Doohicky"
:a/node-1032 :inventory/part-nr "AA-23"
:a/node-1032 :inventory/stock-count 5
:a/node-1032 :inventory/replaces :a/node-1031
:a/node-1031 :inventory/replaced-by :a/node-1032
While I see this:
[:a/node-24040 :inventory/label "Widget"]
[:a/node-24040 :inventory/part-nr "THX-1138"]
[:a/node-24040 :inventory/stock-count 2187]
[:a/node-24040 :db/ident :a/node-24040]
[:a/node-24040 :a/entity true]
[:a/node-24040 :inventory/replaced-by :a/node-24041]
[:a/node-24041 :inventory/label "Doohicky"]
[:a/node-24041 :inventory/part-nr "AA-23"]
[:a/node-24041 :inventory/stock-count 5]
[:a/node-24041 :inventory/replaces -1]
[:a/node-24041 :db/ident :a/node-24041]
[:a/node-24041 :a/entity true]
I’m missing something fundametal about how (temporary) IDs work. Pointers appreciated 🙂
Nope… you read it right. The whole negative-number-in-an-entity thing doesn’t work right. The way around it was to use :db/add
but with Jakub’s update that can have problems too 😕
I want to introduce schemas (both temporary and stored) that can solve this. This would allow attributes to say if they reference a number or another entity. That would solve the problem completely.
Ah, right. Makes sense. Hoping you can find a compromise, I find the schemaless world both freeing and productive. Anyway, thanks for clearing that bit up! 🙂
The idea is that a schema could be either inserted or added as a parameter to a transact
(since it accepts a map with numerous keys already). This could allow attribute descriptions for the attributes you want to treat a particular way, and just treat everything else as usual
I guess if you replaced :inventory/replaces -1
in the entity map with a separate [:db/add -2 :inventory/replaced-by -1]
it would work, no?
Just to show my ignorance, how does using -1 with a :dn/add vector tell Asami its a reference and not a regular plain number?
If the attribute in a :db/add
is :db/id
then you’re explicitly telling the transaction that it should treat the value as an alias for the entity. If that’s a negative number, then that means it’s a temporary entity ID.
All subsequent statements that include that temporary entity ID will have it replaced with the actual entity.
This has the potential to cause problems. I realize that. It’s come about through some recent changes. Rather than just not allowing the changes, this ambiguity is being allowed until schemas get introduced.
If you haven’t used a negative number as an ID, then a :db/add
will just see it as a negative number, and you’ll be fine
That’s out of context, but from the docs at: https://github.com/quoll/asami/wiki/4.-Transactions
If you had said:
[:db/add -2 :db/id -2]
[:db/add -1 :inventory/replaced-by -2]
Then it would be an entityBut do you see how the -2 was already associated with an entity?
{:db/id -1
:inventory/label "Widget"
:inventory/part-nr "THX-1138"
:inventory/stock-count 2187}
{:db/id -2
:inventory/label "Doohicky"
:inventory/part-nr "AA-23"
:inventory/stock-count 5
:inventory/replaces -1}
[:db/add -1 :inventory/replaced-by -2]
Ok, my fault for copying just that part then. Ok, so you mean all negative numbers that have been used as IDs are thereafter used as references in the same transaction?
That’s 3 things. An entity that gets aliased to -1, and entity that gets aliased to -2, and a statement that uses both of those aliases. Unfortunately, once those aliases are set, then you lose the ability to use those negative numbers!