Asami 2.0.0 alpha2 is now up.
This fixes a few things from Alpha 1, including a new serializable datatype for entity nodes that doesnāt use keywords
Again, Iād love any feedback people have. Thank you!
Iād like to comment that the reason itās called an āalphaā is because Iām following the mantra ārelease early, release oftenā.
So there will be things to fix! But any and all feedback will be helpful. Thank you
hello asamists š:skin-tone-2:, Iām somewhat confused by the semantic of retractions in Asami:
(def id
(let [{:keys [tempids db-after]}
@(d/transact conn
[{:db/id -1
:person/name "MsX"
:person/address "10999"}])
id (get tempids -1)]
(println (d/entity db-after id))
id))
(let [{:keys [db-after]}
@(d/transact conn
[[:db/retract id :person/address "10999"]])]
(println (d/entity db-after id)))
Iām seeing :person/address
in the second call to entity
but I wouldnāt expect that. Maybe Iām using wrong transaction data for the retraction? Tested this code with Asami 2.0.0-alpha2 (hereās a notebook to reproduce https://nextjournal.com/a/PDfq1fshbQsrL4dv6GDn6y/edit?token=X6uXajPPMadokXn62oh5Se)That confuses me too. I have a few things happening today look into this as soon as I can
> and then using that in subsequentĀ `:db/retract`Ā statements.
yes exactly. I wonder if in the prior example giving a :db/ident
say āidā instead of the tempid -1
, then a retraction statement like [:db/retract "id" :person/address "10999"]
would have worked. I tend to think about db/idents as https://docs.datomic.com/on-prem/schema/identity.html#lookup-refs but maybe I should not.
Do Asami tx data in the vector form only support actual db/ids? (in other words node-1
mentioned in the wiki https://github.com/threatgrid/asami/wiki/Transactions#tx-data has to be a db/id)
When I found the bug I did notice that it does not support this. I thought that maybe it should, but then realized that this sort of statement means that you are explicitly trying to remove statements during the same transaction that youāre trying to add them. This doesnāt make sense (in Datomic it causes an exception). Itās also difficult, because transactions are performed by performing deletions, followed by assertions. To make it work, these deletions would have to occur after the assertions that autogenerate that ID. Otherwise theyād delete a non-existing statement (a no-op) before inserting it, meaning that the statement would still be created.
I could make it work, but I see no reason why it should. Unless thereās a use-case Iām not seeing?
I think @andrea712 is talking about "id"
as a :db/ident
, not a temp id
is it possible to perform a retraction using an :db/ident
?
asami does not support datomic style lookup refs, e.g. [:db/ident "id"]
correct?
no, sorry for the confusion, itās me not understanding well enough the :db/ident
construct: I thought, since they can be used to lookup an entity which was asserted at any time via (asami.core/entity db my-ident)
I thought that values of :db/ident
could be used in vector statements for retractions in tx-data in 2nd position: eg [:db/retract my-ident attr val]
Asami doesnāt have that lookup styleā¦ no. I made a ticket for it (and it wonāt be hard), but it hasnāt been a priority.
ok, so if you want to retract an attribute using a :db/ident
you need to do a query for its :db/id
first, correct?
okay, weāre currently resolving :db/idents -> :db/id in retraction statements before transactions and it works well enough for the moment, I think
yes @mkvlr doing that currently
idents are used for identifying entities, and we (as inā¦ my team) only really wants to delete things from entities when updating a property (meaning, delete the existing statement, and insert a new one), then weāve used the entity update annotation for that
Internally, all the entity code does those lookups for you. Which is to say that thereās no big deal moving it to other places as well.
understood, supporting [:db/retract [:db/ident my-ident] attr val]
would be useful for us, but of course also easy for us to do it before we submit the tx
So if I have the entity:
{:db/ident "Mary"
:name "Mary Smith"
:age 22}
Then we can update by saying:
{:db/ident "Mary"
:age' 23}
That does the lookup, retracts the [id :age 22]
and assert [id :age 23]
Sorryā¦ I have to leave for an hour
yes, so given that entity with a :db/id
:
{:db/id 123
:db/ident "Mary"
:name "Mary Smith"
:age 22}
you can update like youāve written but if I want to retract the :age
itās only possible (without a query) using [:db/retract 123 :age 22]
and it might be nice to also support [:db/retract [:db/ident "Mary"] :age 22]
like in datomicalso happy to look at that (probably tomorrow) if youād accept a PR for this
If so, then it would go in src/asami/entities.cljc:133 and would probably do something like what line 60 does in that file
(let [node-ref (if id
(and (seq (gr/resolve-triple graph id '?a '?v)) id)
(ffirst (gr/resolve-triple graph '?r :db/ident ident)))
This goes straight to the graph (skipping the query API with the associated costs), and checks if the thing being looked for is valid as an entity node (i.e. it appears in entity-attribute-value tuples in the entity position), and if that doesnāt work out, then it checks to see if the value appears in the value position for a statement where the property is :db/ident
.the resolve-triple
function returns a seq of bindings values. A bindings values is a vector containing position dependent bindings for the requested variables. So the first one will return a seq of vectors that have a count of 2 (representing values for the ?a
and ?v
), and the second will return a seq containing (hopefully) 1 vector, and that vector will have a count of 1.
The (if id ā¦
part means that if a :db/id
is provided, then that is considered canonical, and ignore the :db/ident
These notes are in case you want to go ahead and do it. Otherwise, theyāre a prompt for me to get it done š
(ohā¦ when I said line 133, that was for the deletions. Assertions will need to be treated the same way)
thanks for those pointers, Iāll open a PR shortly
Thank you @mkvlr. Iāve responded to this
I also updated Zuko (which does the deconstruction of entities into triples) to include the lookup refs
Itās in main, and will come out in the next alpha
thank you again
thank you!
@andrea712 OKā¦ itās a bug. Iāve fixed it and am just writing a test for it now. Somewhat embarrassingly, no one I work with retracts statements this way, and I didnāt have full test coverage, so it was overlooked. Thank you very much!
Itās up on github. Iāll make an Alpha 3 when I get back later today
oh, thank you so much! Iāll check that tomorrow.
I have more examples of retracting by db/idents which were not working as expected, will check those against alpha3...
Iām not sure what āretracting by db/identsā might mean.
āRetractionsā are a statement describing an entity-attribute-value tuple to be removed, while a :db/ident
is a way to identify an entity that is stored as multiple tuples. The only thing I can think of is what you provided in your example, where you used :db/ident
to identify the node that represents the entity, and then using that in subsequent :db/retract
statements.
OKā¦ this problem is addressed in 1.2.16 and 2.0.0-alpha3