Fork me on GitHub

Asami 2.0.0 alpha2 is now up.

🚀 15
👍 3

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

(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


That confuses me too. I have a few things happening today look into this as soon as I can


@U9EQP1K0X 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!

🙂 3

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.


> 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 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 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 @U9EQP1K0X 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?

👍 3

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 @U5H74UNSF 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 datomic


also happy to look at that (probably tomorrow) if you’d accept a PR for this

👍 3

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 😉

🙏 3

(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 @U5H74UNSF. I’ve responded to this

👀 3

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!


OK… this problem is addressed in 1.2.16 and 2.0.0-alpha3

🙏 9