2022-07-11 13:00:36 +02:00
|
|
|
package advsql
|
|
|
|
|
|
|
|
import "context"
|
|
|
|
|
2022-07-12 17:56:06 +02:00
|
|
|
func QueryOne[T any](db *Database, query string, decoder func(v *T, decode ScanFunc) error) QueryOneFunc[T] {
|
2022-07-11 13:00:36 +02:00
|
|
|
ctxfunc := QueryOneContext(db, query, decoder)
|
|
|
|
return func(args ...interface{}) *T {
|
|
|
|
return ctxfunc(context.Background(), args...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-12 17:56:06 +02:00
|
|
|
func QueryOneContext[T any](db *Database, query string, decoder func(v *T, decode ScanFunc) error) QueryOneContextFunc[T] {
|
2022-07-11 13:00:36 +02:00
|
|
|
manyfunc := QueryManyContext(db, query, decoder)
|
|
|
|
return func(ctx context.Context, args ...interface{}) *T {
|
|
|
|
nctx, cancel := context.WithCancel(ctx)
|
|
|
|
defer cancel()
|
|
|
|
return <-manyfunc(nctx, args...)
|
|
|
|
}
|
|
|
|
}
|