Skip to content
New issue

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

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

Already on GitHub? # to your account

New :selectable option to let users pluck columns out of a query #537

Open
lucavenir opened this issue Feb 1, 2025 · 0 comments
Open

New :selectable option to let users pluck columns out of a query #537

lucavenir opened this issue Feb 1, 2025 · 0 comments

Comments

@lucavenir
Copy link

lucavenir commented Feb 1, 2025

Is your feature request related to a problem? Please describe.
I'm not sure this is in the scope of Flop, and if it isn't, I'm sorry.

Lately, I've been wondering how to receive a select filter option, e.g. /resource?select=name,city, so that I can output my entity, but with the only filtered fields (name and city in the above example).

Should Flop help with this problem? I personally instinctively reached to Flop to solve this.

Describe the solution you'd like
Right now, with Flop, we can write:

@derive {
  Flop.Schema,
  filterable: [:name, :this, :that],
  sortable: [:name],
  pagination_types: [:page]
}

This allows my endpoint to receive /resource?name=some&this=thing&that=else&page=0&page_size=10.
I'll just feed this to Flop and call it a day. Great.
I would love the same just works™ feel, but with an additional :selectable option.

@derive {
  Flop.Schema,
  filterable: [:name, :this, :that],
  sortable: [:name],
  selectable: [:name, :city],
  pagination_types: [:page]
}

The above would allow to receive /resource?name=some&this=thing&that=else&page=0&page_size=10&select=name,city, and Flop would the results (filtered by other options), but it would SELECT just name and city out of it.

Describe alternatives you've considered
Simply, to implement this by hand: params validation and Ecto's :select option. Pain.

@lucavenir lucavenir changed the title Let Flop offer a :selectable option which allows to filter out columns out of a query New :selectable option to let users pluck columns out of a query Feb 1, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

1 participant