datahike

https://datahike.io/, Join the conversation at https://discord.com/invite/kEBzMvb, history for this channel is available at https://clojurians.zulipchat.com/#narrow/stream/180378-slack-archive/topic/datahike
zane 2020-01-02T00:09:18.005Z

Do you even need the lookup ref there?

cjsauer 2020-01-02T03:03:21.009300Z

@sfyire you don’t need the lookup ref, as zane said. Internally, lookup refs are resolved to the :db/id of the specific entity, so what you have written is “redundant”. If charlie-id is indeed a :db/id, then you can transact the link directly:

(datahike/transact
  connection
  {:tx-data [{:db/id bob-id, :best-friend charlie-id}]})
With ref-type attributes, the v in the [e a v] tuple is the e of the entity to reference. So in your example the tuple would be [bob-id :best-friend charlie-id] . In fact, I don’t believe [:db/id 123] is even a valid lookup ref (as you’ve discovered), because :db/id is a built-in attribute; it’s not a ref-type attribute defined in your schema.

2
Adrian Smith 2020-01-02T15:16:41.010900Z

Thank you for the information, what's the significance of :tx-data? I'm not at my laptop but I thought I could do non ref based updates without the :tx-data key I just assumed I could update anything with that "syntax"

cjsauer 2020-01-02T16:47:53.014700Z

@sfyire you’re correct in that you can process transactions without using the :tx-data key, and can pass the sequence directly. I believe that it’s there in order to be compatible with Datomic (where its use is mandated). Datahike is based on the Datascript project, where the syntax is a bit “looser”.

cjsauer 2020-01-02T16:49:17.016Z

Datomic supports an additional :timeout key as well, so the map form is more open in the options it can accept.

Adrian Smith 2020-01-02T17:04:31.017100Z

@cjsauer oh I see so I would need to add :tx-data all the time in updates for Datomic? But Datascript and thus Datahike will accept without a :tx-data in some circumstances?

cjsauer 2020-01-02T18:42:23.019300Z

@sfyire right. If compatibility with Datomic is important, for example if you foresee one day migrating, then it might be better to use the more portable map form. This is my impression anyway. Others here might have more insight.

👍 2