Fork me on GitHub
#datascript
<
2023-02-17
>
jeremys21:02:59

Hi, I may be mistaken but is seems that the entity function returns an entity instead of nil when passed an numerical id that isn't in the db. From what I understand datascript.core/entity (which is an alias for datascript.impl.entity/entity) calls datascript.db/entid at the bottom which always returns the id passed to it if its a number. Is this a bug ? Am I missing something ? Cheers

Niki15:02:27

If I remember it mimics Datomic behavior. Basically, do not use entities to check for existence. Entity call is supposed to be super-lightweight, so it doesn’t really touch DB unless you start asking for attributes

jeremys12:02:55

Ok thanks, I'll check with a normal query then. If I may though, for information, the docstring of d/entity has this example in it :

; If entity does not exist, nil is returned:
(entity db 100500) ; => nil
Thanks again, cheers