-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Current status
Me and @Tydragon00 want to improve the status quo:
1) Wall of Mappings:
2) Sad Wall of Single Filters:
Proposal 1: Small QoL improvements
Easy to implement and use, expect a PR soon-ish
New func filtermap.AddOptionalFilter(query, attribute, filter)
Essentially identical to filtermap.AddFilters but handles a single filter and includes the ... if filter != "" inside the func itself, so we don't have to repeat the check every time
New Func filtermap.AddPayloadFilters(query, payload)
A func that "magically" (via reflection) maps the payload fields to the map, avoiding multiple filtermap.AddFilters one after another. This should work for both Huma and Goa.
This will solve the Sad Wall of Single Filters replacing it via a single function call
Proposal 2: Radical code-gen approach (Huma-only)
More involved, might be done eventually.
The idea is to define the endpoint payload as usual but with some extra comments, ie:
type ListDCRsRequest struct {
// db:filter bob_gen.ColumnNames.DCRS.Type
Type string `query:"type"`
// db:filter bob_gen.ColumnNames.DCRS.Status
Status string `query:"status"`
}Then run go generate, some magic codegen will create a func for you:
func (r *ListDCRsRequest) AddFilters(q *[]bob.Mod[*dialect.SelectQuery]) error (Codegen so we can catch any typo at compile time, with no surprises)
This could solve both the Wall of Mappings and the Sad Wall of Single Filters via a single function call