2024-02-21 16:10:28 +01:00
|
|
|
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
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-21 16:11:15 +01:00
|
|
|
func NewSimplePaginateFilter(filterClause string, filterParams PP, sort []FilterSort) PaginateFilter {
|
2024-02-21 16:10:28 +01:00
|
|
|
return genericPaginateFilter{
|
2024-02-21 16:11:15 +01:00
|
|
|
sql: func(params PP) (string, string, []string) {
|
|
|
|
params.AddAll(filterParams)
|
2024-02-21 16:10:28 +01:00
|
|
|
return filterClause, "", nil
|
|
|
|
},
|
|
|
|
sort: func() []FilterSort {
|
|
|
|
return sort
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2024-03-11 16:40:41 +01:00
|
|
|
|
|
|
|
func NewEmptyPaginateFilter() PaginateFilter {
|
|
|
|
return genericPaginateFilter{
|
|
|
|
sql: func(params PP) (string, string, []string) { return "1=1", "", nil },
|
|
|
|
sort: func() []FilterSort { return make([]FilterSort, 0) },
|
|
|
|
}
|
|
|
|
}
|