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

Add template based filter #94

Open
daniel-reed opened this issue Jan 3, 2018 · 0 comments
Open

Add template based filter #94

daniel-reed opened this issue Jan 3, 2018 · 0 comments

Comments

@daniel-reed
Copy link
Member

I would like to add generic template based filter functions to Columns, Tables, Indexes, and ForeignKeys. I find myself often wanting to filter these slices on one or more properties but I feel directly coding it each time I need a new filter will be cumbersome.

It would look something like:

func (c Columns) FilterT(t string) Columns {
  //for column
  //execute template t
  //if result is truthy
  //add to result
  //return result
}

At this point, every user can define templates that render a truthy or falsey string. Then, they can easily filter in templates like this:

{{$noDefaults := .Table.Columns.FilterT "noDefaultValue.gotmpl" -}}
{{$noAutoIncrement := .Table.Columns.FilterT "noAutoIncrement.gotmpl" -}}

Feedback or alternative solutions are welcome. I don't love this implementation but I feel it is better than adding a bunch of custom filters to the code base every time we want something different.

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