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:
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user