Zhuinden / realm-monarchy

[ACTIVE-ISH] A wrapper over Realm which exposes it as LiveData, managing Realm lifecycle internally.
Apache License 2.0
88 stars 11 forks source link

fetching single record #36

Open timolor opened 2 years ago

timolor commented 2 years ago

Would there be a provision to fetching/finding just one record? Say maybe a findOneCopiedWithChanges

Zhuinden commented 2 years ago

Theoretically you could do that, but because of how Realm queries work for single object, it's much safer to get them in a single item list. You can even use LIMIT(1) to ensure it. 👀

Then if it's empty, then it's empty, otherwise get(0)

timolor commented 2 years ago

Yeah, thanks. I had to do just that. I suppose distinct should work as well with a where clause, especially when the find parameter is a unique/primary column