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]
@ctamayo Hey, I think it should be. @konrad.kuehne What is your opinion (since you implemented the schema support)?
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.
> 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!
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. 🙂
Happy to help. :)