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

Feature Request: Add Support filters and search in count_ functions #49

Open
rafaelofreitas opened this issue Oct 6, 2021 · 1 comment

Comments

@rafaelofreitas
Copy link

rafaelofreitas commented Oct 6, 2021

Change the count_my_schemas function, to receive search and filter parameters.

  def count_my_schemas(field \\ :id) do
    Repo.aggregate(MySchema, :count, field)
  end

Something like that:

 def count_my_schemas(params \\ %{}) do
   search = params[:search]
   search_fields = params[:search_fields] || []
   filters = params[:filters] || %{}

   MySchema
   |> Crudry.Query.search(search, search_fields)
   |> Crudry.Query.filter(filters)
   |> Repo.count()
 end
@gabrielpra1
Copy link
Member

Sounds good!

Small thing: there's no Repo.count function, and I think we should still accept the field to be counted as argument

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

2 participants