Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@lucavenir

Description

@lucavenir

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions