wp-go/model/query.go

26 lines
593 B
Go
Raw Normal View History

2023-01-12 12:42:16 +00:00
package model
2022-11-05 12:59:49 +00:00
import "context"
2022-11-05 12:59:49 +00:00
func finds[T Model](db dbQuery[T], ctx context.Context, q *QueryCondition) ([]T, error) {
s, args, err := BuildQuerySql[T](q)
2022-11-05 12:59:49 +00:00
if err != nil {
return nil, err
2022-11-05 12:59:49 +00:00
}
return db.Select(ctx, s, args...)
2022-11-05 12:59:49 +00:00
}
func scanners[T Model](db dbQuery[T], ctx context.Context, q *QueryCondition) ([]T, error) {
s, args, err := BuildQuerySql[T](q)
2022-11-05 12:59:49 +00:00
if err != nil {
return nil, err
2022-11-05 12:59:49 +00:00
}
ctx = context.WithValue(ctx, "handle=>", "scanner")
2022-11-05 12:59:49 +00:00
var r []T
ctx = context.WithValue(ctx, "fn", func(t T) {
r = append(r, t)
})
_, err = db.Select(ctx, s, args...)
return r, err
2022-11-05 12:59:49 +00:00
}