Hi just wanted to check if this is a typo or if I'm doing something wrong: https://github.com/threatgrid/asami/wiki/4.-Transactions#temporary-ids When I use a new db:
(da/transact db
[{: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]])
(->>
(da/q
'[:find ?e
:where [?e]]
db)
(map first)
(map (partial da/entity (da/db db)))
)
I get the following:
({:inventory/label "Widget",
:inventory/part-nr "THX-1138",
:inventory/stock-count 2187,
:inventory/replaced-by {:db/ident :tg/node-113217}}
{:inventory/label "Doohicky",
:inventory/part-nr "AA-23",
:inventory/stock-count 5,
:inventory/replaces -1})
Unlike in the wiki, :inventory/replaces in the second result doesn't refer to another entity, it just sets the value to -1.
I'm also not sure I understand it if that's NOT the correct behavior. For example, with the
[:db/add -1 :inventory/replaced-by -2]
How does asami know that -2 is a reference and not just a negative number value?This is a semantic issue which I think is vague, yes. It’s fine when it’s in the “entity” position, but not in the “value” position. This is why using {:db/id -2} is better.
BTW, this was written before it was possible to say:
(da/q
'[:find [?e ...]
:where [?e]]
db)
Which lets you skip the (map first) stepAh cool. Yeah I missed the part where datoms in asami aren't [e a v] but [:tg/node-10502 :relates-to :tg/node-10499 1 true] So to assign values in a node you need to transact a map right? And to refer to other nodes in the same transaction with a tempid, you would need a separate :db/add vector to make the association, right?
Datoms are that way for Datomic as well
You can add values to a node by either transacting a map or individual :db/add statements. Either approach works.
I usually use maps though
[{:db/ident "THX-1138"
:inventory/label "Widget"
:inventory/part-nr "THX-1138"
:inventory/stock-count 2187
:inventory/replaced-by {:db/ident "AA-23"}}
{:db/ident "AA-23"
:inventory/label "Doohicky"
:inventory/part-nr "AA-23"
:inventory/stock-count 5
:inventory/replaces {:db/ident "THX-1138"}]Can that example be done using tempids though? Or is it generally better to always use explicit :db/ident values like that
It can be, though I need to check that I have the syntax right
[{:db/id -1
:inventory/label "Widget"
:inventory/part-nr "THX-1138"
:inventory/stock-count 2187
:inventory/replaced-by {:db/id -2}}
{:db/id -2
:inventory/label "Doohicky"
:inventory/part-nr "AA-23"
:inventory/stock-count 5
:inventory/replaces {:db/id -1}]
And because it’s :db/id now and not :db/ident, then I believe we also support the Datomic syntax of:
[{:db/id -1
:inventory/label "Widget"
:inventory/part-nr "THX-1138"
:inventory/stock-count 2187
:inventory/replaced-by [:db/id -2]}
{:db/id -2
:inventory/label "Doohicky"
:inventory/part-nr "AA-23"
:inventory/stock-count 5
:inventory/replaces [:db/id -1]]
(someone else submitted this as a patch)Gotcha, that makes sense, thanks!