@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 😃...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.
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.
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.
:db/id allows us to reference the node ID as an attribute. It's sort of “magical” that way
You're trying to set it to itself, which is nonsense
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
If you drop that statement, it may help
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.
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 =)...