This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-11
Channels
- # announcements (1)
- # asami (10)
- # aws (36)
- # babashka (1)
- # beginners (32)
- # biff (13)
- # calva (2)
- # cider (2)
- # clj-kondo (3)
- # cljs-dev (5)
- # clojure-poland (2)
- # clojured (5)
- # clojurescript (7)
- # core-logic (13)
- # core-matrix (2)
- # core-typed (1)
- # datomic (1)
- # fulcro (19)
- # gratitude (6)
- # meander (15)
- # minecraft (4)
- # pathom (3)
- # podcasts (2)
- # reagent (19)
- # releases (1)
- # shadow-cljs (69)
- # sql (3)
- # tools-deps (22)
- # vim (1)
@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 😃...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
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
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 =)...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.