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:
2026-06-29 18:24:29 -07:00
parent cc44931ea9
commit fbb9c74aab
7 changed files with 117 additions and 4 deletions
+18
View File
@@ -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.