Fork me on GitHub
#asami
<
2022-06-11
>
folcon19:06:45

@quoll, So trying to insert arbitrary data into asami, I've been using build-triples, but I get a -1 in by :db/add still, should I manually just be using node/new-node, or is there someway I can still use the tempid, system?

(let [testo-db-uri "asami:"
        _ (d/delete-database testo-db-uri)
        _ (d/create-database testo-db-uri)
        testo-conn (d/connect testo-db-uri)
        db (d/db testo-conn)
        new-node (node/new-node (d/graph db))
        tx-triples (entities/build-triples (d/graph db) [[:db/add -1 :db/id -1]
                                                         [:db/add -1 :pear {:fish 12}]])]
    @(d/transact testo-conn {:tx-triples (first tx-triples)}))
=> >
([-1 :db/id :a/node-59480] [:a/node-59480 :pear {:fish 12}])
I've been doing it this way instead of just using update-fn for node creation, because when I tested transacting it as a map I got this:
(#datom[:a/node-59494 :fish 12 1 true]
           #datom[:a/node-59493 :a/owns :a/node-59494 1 true]
           #datom[:a/node-59493 :pear :a/node-59494 1 true]
           #datom[:a/node-59493 :db/ident :a/node-59493 1 true]
           #datom[:a/node-59493 :a/entity true 1 true])
Now, I'm trying to skip creating the a/node-59494, instead nesting it in :a/node-59493 so I can maintain the original datastructure, but I'm assuming other parts of the codebase expect stuff like :db/ident, :a/entity and potentially other keys I'm unaware of to be declared 😃...

quoll23:06:05

It's after 1am, and I’ve had numerous drinks, but I'll comment anyway … [:db/add -1 :db/id -1] is really a bad idea.

quoll23:06:02

:db/id allows us to reference the node ID as an attribute. It's sort of “magical” that way

quoll23:06:44

You're trying to set it to itself, which is nonsense

quoll23:06:16

It will see the id of -1, create an internal id for it, and save it for future use. In your example, -1 is used in the entity position before it does this. That's likely to make the entity an actual -1

quoll23:06:43

If you drop that statement, it may help

folcon23:06:05

Oh, sorry to disturb your partying. Didn't mean to do that. I only did it as the code here in asami.entities seems to expect a :db/id and that seemed to be the correct way to have the system assign a node to a temp-id.

folcon00:06:48

I initially thought I should invoke it like this:

(entities/build-triples (d/graph db) [[:db/add -1 :pear {:fish 12}]])
and asami would treat the -1 as a temp-id, but instead it does this:
{...
:tx-data (#datom[-1 :pear {:fish 12} 1 true])}
I tried manually assigning it a node, but in either case it doesn't create any nodes like:
[:a/node-59493 :db/ident :a/node-59493 1 true]
[:a/node-59493 :a/entity true 1 true]
Which I suspect are important. Also I've done a lot more reading of naga and I have questions when convenient. Enjoy the rest of the party =)...

quoll08:06:47

The build-triples function looks for 3 things: • vectors starting with :db/add • Vectors starting with :db/retract • Maps A :db/id on a map assigns it the internal identifier it should use (negative numbers say that one should be generated and remembered). It should never appear in an add or retract operation.

folcon10:06:29

Ah, ok, so that's part of the decompose map logic, fine. So at this point all triples should have an assigned id, which is a node. Right, so I should pass in an id, not a temp-id.