v0.0.384 QuerySingleOpt
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m28s

This commit is contained in:
Mike Schwörer 2024-02-09 15:20:46 +01:00
parent 30ce8c4b60
commit 1869ff3d75
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
2 changed files with 19 additions and 2 deletions

View File

@ -1,5 +1,5 @@
package goext
const GoextVersion = "0.0.383"
const GoextVersion = "0.0.384"
const GoextVersionTimestamp = "2024-02-09T15:17:51+0100"
const GoextVersionTimestamp = "2024-02-09T15:20:46+0100"

View File

@ -103,6 +103,23 @@ func QuerySingle[TData any](ctx context.Context, q Queryable, sql string, pp PP,
return data, nil
}
func QuerySingleOpt[TData any](ctx context.Context, q Queryable, sqlstr string, pp PP, mode StructScanMode, sec StructScanSafety) (*TData, error) {
rows, err := q.Query(ctx, sqlstr, pp)
if err != nil {
return nil, err
}
data, err := ScanSingle[TData](ctx, q, rows, mode, sec, true)
if errors.Is(err, sql.ErrNoRows) {
return nil, nil
}
if err != nil {
return nil, err
}
return &data, nil
}
func QueryAll[TData any](ctx context.Context, q Queryable, sql string, pp PP, mode StructScanMode, sec StructScanSafety) ([]TData, error) {
rows, err := q.Query(ctx, sql, pp)
if err != nil {