2023-01-12 12:42:16 +00:00
|
|
|
package model
|
2022-11-05 12:59:49 +00:00
|
|
|
|
2023-02-22 08:53:53 +00:00
|
|
|
import "context"
|
2022-11-05 12:59:49 +00:00
|
|
|
|
2023-02-22 08:53:53 +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 {
|
2023-02-22 08:53:53 +00:00
|
|
|
return nil, err
|
2022-11-05 12:59:49 +00:00
|
|
|
}
|
2023-02-22 08:53:53 +00:00
|
|
|
return db.Select(ctx, s, args...)
|
2022-11-05 12:59:49 +00:00
|
|
|
}
|
|
|
|
|
2023-02-22 08:53:53 +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 {
|
2023-02-22 08:53:53 +00:00
|
|
|
return nil, err
|
2022-11-05 12:59:49 +00:00
|
|
|
}
|
2023-02-22 08:53:53 +00:00
|
|
|
ctx = context.WithValue(ctx, "handle=>", "scanner")
|
2022-11-05 12:59:49 +00:00
|
|
|
var r []T
|
2023-02-22 08:53:53 +00:00
|
|
|
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
|
|
|
}
|