How to make simple select count with Ash

Hi, maybe a noob question here 😅 but I'm wondering which is the right way of making a simple select count of my Users on a Postgres-based app. I could do that with MyApi.count(MyResource) but on the docs that method belongs to the ambigous Ash.Filter.ShadowApi module. I can't find anything else on the docs 🤷🏼‍♂️ For context, I'm trying to make some filtered and unfiltered counts on my direct resource and not an aggregate count on related resources.
3 Replies
ZachDaniel
ZachDaniel3y ago
I should hide that ShadowApi module from the docs 🙂 count/1 is defined on your own api module as described Yeah, it looks like we don't document those in the callbacks section, sorry about that but resource |> Ash.Query.for_read(...) |> YourApi.count() should be what you are looking for I've updated the docs so it should show up in Ash.Api as a callback so you'd still call YourApi.count(ResourceOrQuery)
moissela
moisselaOP3y ago
Thank you @Zach Daniel 😊
ZachDaniel
ZachDaniel3y ago
The docs changes I made won't show up until a new version is released though, just FYI My pleasure 🙇

Did you find this page helpful?