20 lines
618 B
Go
20 lines
618 B
Go
package advsql
|
|
|
|
import "context"
|
|
|
|
func QueryOne[T any](db *Database, query string, decoder func(v *T, decode ScanFunc) error) QueryOneFunc[T] {
|
|
ctxfunc := QueryOneContext(db, query, decoder)
|
|
return func(args ...interface{}) *T {
|
|
return ctxfunc(context.Background(), args...)
|
|
}
|
|
}
|
|
|
|
func QueryOneContext[T any](db *Database, query string, decoder func(v *T, decode ScanFunc) error) QueryOneContextFunc[T] {
|
|
manyfunc := QueryManyContext(db, query, decoder)
|
|
return func(ctx context.Context, args ...interface{}) *T {
|
|
nctx, cancel := context.WithCancel(ctx)
|
|
defer cancel()
|
|
return <-manyfunc(nctx, args...)
|
|
}
|
|
}
|