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
coby 2021-02-03T17:19:42.007200Z

Is :db/id not actually unique? It https://github.com/replikativ/datahike/blob/development/src/datahike/schema.cljc#L69 in the schema but maybe I am misunderstanding. I am getting a uniqueness error when I try to query with a [:db/id x] tuple rather than just plain x

;; this works
(d/pull db [:post/slug :post/title] 43)
;; this does not work
(d/pull db [:post/slug :post/title] [:db/id 43]) ;; -> Lookup ref attribute should be marked as :db/unique: [:db/id 43]

whilo 2021-02-03T18:12:23.008200Z

@ctamayo Hey, I think it should be. @konrad.kuehne What is your opinion (since you implemented the schema support)?

kkuehne 2021-02-03T19:47:49.014100Z

I can see why this is not working at the moment, @ctamayo. Two things come together. First the implicit-schema only defines :db/ident as db/unique in https://github.com/replikativ/datahike/blob/development/src/datahike/db.cljc#L31. Second if we add :db/id there, the -slice function https://github.com/replikativ/datahike/blob/development/src/datahike/db.cljc#L241 can not find anything since db/id is not an actual attribute in any [e a v t] because the e represents that. In order to get that working one would need to check :db/id as another condition in https://github.com/replikativ/datahike/blob/development/src/datahike/db.cljc#L1042 and check and return the value. I could add a PR for that if you need that.

coby 2021-02-03T20:19:53.018Z

> db/id is not an actual attribute in any `[e a v t]` because the `e` represents that Ah, I see what you mean. I thought it might have something to do with that. On the whole I think what you're saying is that :db/id should always be unique, and the fact that it isn't treated as such right now is basically an implementation detail? I can special-case :db/id in my code for now, but might have to do so in multiple places so it'd be great to have that in core. Thanks!

coby 2021-02-03T20:23:02.019500Z

In any case I might take a stab at a PR myself. Sounds like a pretty well-contained change. Thanks for the detailed response, btw. 🙂

kkuehne 2021-02-04T08:17:45.019800Z

Happy to help. :)