feat(query): add Query, MustQuery, and UpdateOne helpers
Adds scan-into-dest query helpers and update-one-row semantics with Context variants, tests, and documentation updates. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -74,6 +74,24 @@ func UpdateAffectedContext(ctx context.Context, sqlo Executable, stmt Statement)
|
||||
return rowsAffected, nil
|
||||
}
|
||||
|
||||
// UpdateOne executes an update statement and returns notFoundErr if zero rows
|
||||
// were affected.
|
||||
func UpdateOne(sqlo Executable, stmt Statement, notFoundErr error) error {
|
||||
return UpdateOneContext(context.Background(), sqlo, stmt, notFoundErr)
|
||||
}
|
||||
|
||||
// UpdateOneContext is the context-aware variant of [UpdateOne].
|
||||
func UpdateOneContext(ctx context.Context, sqlo Executable, stmt Statement, notFoundErr error) error {
|
||||
n, err := UpdateAffectedContext(ctx, sqlo, stmt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if n == 0 {
|
||||
return notFoundErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateReturning executes an update statement that returns the updated row.
|
||||
// The statement MUST be a Jet UpdateStatement with a RETURNING clause. Returns
|
||||
// the updated row object T or an error if the update fails or no rows are returned.
|
||||
|
||||
Reference in New Issue
Block a user