advsql/query_one.go
Timon Ringwald a39f467b93 QueryOne implemented
Query renamed to QueryMany
Default Decoders refactored
2022-07-11 13:00:36 +02:00

20 lines
622 B
Go

package advsql
import "context"
func QueryOne[T any](db *Database, query string, decoder func(v *T, decode DecodeFunc) 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 DecodeFunc) 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...)
}
}