This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-26
Channels
- # announcements (28)
- # asami (13)
- # babashka (10)
- # beginners (170)
- # boot (1)
- # calva (35)
- # cider (21)
- # circleci (13)
- # clara (6)
- # clj-http (1)
- # clj-kondo (29)
- # cljdoc (5)
- # clojure (89)
- # clojure-czech (2)
- # clojure-europe (20)
- # clojure-france (16)
- # clojure-nl (6)
- # clojure-uk (5)
- # clojurescript (80)
- # community-development (6)
- # conjure (13)
- # cursive (18)
- # datascript (9)
- # datomic (1)
- # duct (1)
- # gratitude (2)
- # helix (7)
- # jobs (2)
- # kaocha (3)
- # lsp (22)
- # malli (5)
- # meander (1)
- # other-languages (34)
- # pathom (18)
- # polylith (24)
- # quil (10)
- # re-frame (5)
- # releases (1)
- # remote-jobs (4)
- # reveal (7)
- # shadow-cljs (8)
- # tools-deps (53)
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?
You can add values to a node by either transacting a map or individual :db/add
statements. Either approach works.
[{: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
[{: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)