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
+23
View File
@@ -60,6 +60,29 @@ func TestUpdateAffected_ReturnsCount(t *testing.T) {
assert.Equal(t, int64(3), n)
}
func TestUpdateOne_NotFound(t *testing.T) {
errNotFound := errors.New("not found")
stmt := mockStatement{
execContextFn: func(_ context.Context) (sql.Result, error) {
return mockResult{rowsAffected: 0}, nil
},
}
err := UpdateOne(mockExecutable{}, stmt, errNotFound)
assert.ErrorIs(t, err, errNotFound)
}
func TestUpdateOne_Success(t *testing.T) {
stmt := mockStatement{
execContextFn: func(_ context.Context) (sql.Result, error) {
return mockResult{rowsAffected: 1}, nil
},
}
err := UpdateOne(mockExecutable{}, stmt, errors.New("not found"))
require.NoError(t, err)
}
func TestDelete_Succeeds(t *testing.T) {
called := false
stmt := mockStatement{