v0.0.389
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Has been cancelled
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Has been cancelled
This commit is contained in:
parent
3cc8dccc63
commit
9e586f7706
2
go.mod
2
go.mod
@ -29,7 +29,7 @@ require (
|
||||
github.com/google/uuid v1.5.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/compress v1.17.6 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -66,6 +66,8 @@ github.com/klauspost/compress v1.17.6/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6K
|
||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc=
|
||||
github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
|
||||
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
|
||||
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
|
||||
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
|
||||
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
|
||||
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
|
||||
|
@ -1,5 +1,5 @@
|
||||
package goext
|
||||
|
||||
const GoextVersion = "0.0.388"
|
||||
const GoextVersion = "0.0.389"
|
||||
|
||||
const GoextVersionTimestamp = "2024-02-20T09:19:06+0100"
|
||||
const GoextVersionTimestamp = "2024-02-21T16:10:28+0100"
|
||||
|
49
sq/filter.go
Normal file
49
sq/filter.go
Normal file
@ -0,0 +1,49 @@
|
||||
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
|
||||
},
|
||||
}
|
||||
}
|
@ -3,22 +3,11 @@ package sq
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
ct "gogs.mikescher.com/BlackForestBytes/goext/cursortoken"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/exerr"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
pag "gogs.mikescher.com/BlackForestBytes/goext/pagination"
|
||||
)
|
||||
|
||||
type PaginateFilter interface {
|
||||
SQL(params PP) (filterClause string, joinClause string, joinTables []string)
|
||||
Sort() []FilterSort
|
||||
}
|
||||
|
||||
type FilterSort struct {
|
||||
Field string
|
||||
Direction ct.SortDirection
|
||||
}
|
||||
|
||||
func Paginate[TData any](ctx context.Context, q Queryable, table string, filter PaginateFilter, scanMode StructScanMode, scanSec StructScanSafety, page int, limit *int) ([]TData, pag.Pagination, error) {
|
||||
prepParams := PP{}
|
||||
|
||||
|
@ -20,6 +20,12 @@ func (pp *PP) Add(v any) string {
|
||||
return id
|
||||
}
|
||||
|
||||
func (pp *PP) AddAll(other PP) {
|
||||
for id, v := range other {
|
||||
(*pp)[id] = v
|
||||
}
|
||||
}
|
||||
|
||||
func PPID() string {
|
||||
return "p_" + langext.RandBase62(8)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user