v0.0.389
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Has been cancelled

This commit is contained in:
Mike Schwörer 2024-02-21 16:10:28 +01:00
parent 3cc8dccc63
commit 9e586f7706
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
6 changed files with 60 additions and 14 deletions

2
go.mod
View File

@ -29,7 +29,7 @@ require (
github.com/google/uuid v1.5.0 // indirect github.com/google/uuid v1.5.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.6 // 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/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-isatty v0.0.20 // indirect

2
go.sum
View File

@ -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.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 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc=
github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= 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/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 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=

View File

@ -1,5 +1,5 @@
package goext 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
View 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
},
}
}

View File

@ -3,22 +3,11 @@ package sq
import ( import (
"context" "context"
"fmt" "fmt"
ct "gogs.mikescher.com/BlackForestBytes/goext/cursortoken"
"gogs.mikescher.com/BlackForestBytes/goext/exerr" "gogs.mikescher.com/BlackForestBytes/goext/exerr"
"gogs.mikescher.com/BlackForestBytes/goext/langext" "gogs.mikescher.com/BlackForestBytes/goext/langext"
pag "gogs.mikescher.com/BlackForestBytes/goext/pagination" 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) { 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{} prepParams := PP{}

View File

@ -20,6 +20,12 @@ func (pp *PP) Add(v any) string {
return id return id
} }
func (pp *PP) AddAll(other PP) {
for id, v := range other {
(*pp)[id] = v
}
}
func PPID() string { func PPID() string {
return "p_" + langext.RandBase62(8) return "p_" + langext.RandBase62(8)
} }