Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there built in functionality or a guide on how to use queries with count, coalesce etc? #295

Open
2 tasks done
Designer023 opened this issue Jul 25, 2024 · 0 comments
Open
2 tasks done

Comments

@Designer023
Copy link

Designer023 commented Jul 25, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Question

I have a more complex query which currently is like this:


.grab$({
   ...// the other fields
   count: [
      `count(*[_type== "article" && references(^._id) && coalesce(language, 'en') == 'en'])`,
       q.number()
   ]
})

Is there any built in way, or suggestions on how I can optimize the query so I'm not writing long strings of filters (i.e. the old way).

I'm looking for something like:

q.count(q.("*").filterByType("article").filter(q.coalesce("language", 'en')))
// or 
q.("*").filterByType("article").count()

I guess I could use select to replace the coalesce, but a built in function would be nice to have where possible:

select(
    language => language,
    "en"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant