Mike Schwörer
9e586f7706
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Has been cancelled
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package sq
|
|
|
|
import ct "gogs.mikescher.com/BlackForestBytes/goext/cursortoken"
|
|
|
|
type FilterSort struct {
|
|
Field string
|
|
Direction ct.SortDirection
|
|
}
|
|
|
|
type PaginateFilter interface {
|
|
SQL(params PP) (filterClause string, joinClause string, joinTables []string)
|
|
Sort() []FilterSort
|
|
}
|
|
|
|
type genericPaginateFilter struct {
|
|
sql func(params PP) (filterClause string, joinClause string, joinTables []string)
|
|
sort func() []FilterSort
|
|
}
|
|
|
|
func (g genericPaginateFilter) SQL(params PP) (filterClause string, joinClause string, joinTables []string) {
|
|
return g.sql(params)
|
|
}
|
|
|
|
func (g genericPaginateFilter) Sort() []FilterSort {
|
|
return g.sort()
|
|
}
|
|
|
|
func NewPaginateFilter(sql func(params PP) (filterClause string, joinClause string, joinTables []string), sort []FilterSort) PaginateFilter {
|
|
return genericPaginateFilter{
|
|
sql: func(params PP) (filterClause string, joinClause string, joinTables []string) {
|
|
return sql(params)
|
|
},
|
|
sort: func() []FilterSort {
|
|
return sort
|
|
},
|
|
}
|
|
}
|
|
|
|
func NewSimplePaginateFilter(filterClause string, params PP, sort []FilterSort) PaginateFilter {
|
|
return genericPaginateFilter{
|
|
sql: func(params PP) (filterClause string, joinClause string, joinTables []string) {
|
|
params.AddAll(params)
|
|
return filterClause, "", nil
|
|
},
|
|
sort: func() []FilterSort {
|
|
return sort
|
|
},
|
|
}
|
|
}
|