asami

2022-07-12T09:04:57.741609Z

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?)

2022-07-12T09:53:29.720039Z

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]

2022-07-12T09:54:15.674899Z

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

2022-07-12T09:54:43.953989Z

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]

2022-07-12T09:55:51.199479Z

I’m missing something fundametal about how (temporary) IDs work. Pointers appreciated 🙂

quoll 2022-07-12T14:34:13.637039Z

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.

2022-07-12T14:38:44.960979Z

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! 🙂

quoll 2022-07-12T14:41:26.436679Z

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

💯 1
Cora (she/her) 2022-07-12T15:30:38.193099Z

partial schemas is a neat idea, I like it

➕ 1
🙏 1
2022-07-12T16:47:27.831999Z

Sounds brilliant, exciting to see where it goes 🙂

Jakub Holý (HolyJak) 2022-07-12T18:28:08.169559Z

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?

quoll 2022-07-12T19:42:44.980579Z

It should… unless the -1 had been used as a temporary entity ID already

2022-07-13T19:08:46.807389Z

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?

quoll 2022-07-13T19:12:16.359799Z

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.

quoll 2022-07-13T19:12:46.350459Z

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

2022-07-13T19:18:52.530249Z

With this:

[:db/add -1 :inventory/replaced-by -2]

2022-07-13T19:19:07.693879Z

How does Asami know -2 is an ID and not just the attribute -2? 🙂

2022-07-13T19:19:52.910039Z

(There is no :db/id right there?)

quoll 2022-07-13T19:20:32.315269Z

In that case, it’s the number -2

2022-07-13T19:20:47.443299Z

That’s out of context, but from the docs at: https://github.com/quoll/asami/wiki/4.-Transactions

2022-07-13T19:20:50.293329Z

Ok.

quoll 2022-07-13T19:21:25.504469Z

If you had said:

[:db/add -2 :db/id -2]
[:db/add -1 :inventory/replaced-by -2]
Then it would be an entity

quoll 2022-07-13T19:21:58.649659Z

Ah, I see your example

quoll 2022-07-13T19:22:26.925809Z

But 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]

2022-07-13T19:22:31.111399Z

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?

quoll 2022-07-13T19:23:23.059159Z

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!

quoll 2022-07-13T19:23:34.949809Z

Which is a problem! I acknowledge that. It needs to be fixed

2022-07-13T19:24:07.602889Z

I see. Thank you, you have more patience explaining than I deserve. Took me awhile but now I’m there 😊

quoll 2022-07-13T19:25:34.381819Z

Oh no… the thing about computers is that there is no universal truth, like in math. Everything was a choice that someone made at some point. Which means trying to learn and understand where they were coming from, and trying to identify the consistent ideas in it

💯 1