Skip to content

Commit

Permalink
fix test problems
Browse files Browse the repository at this point in the history
  • Loading branch information
amirrezaask committed Mar 9, 2022
1 parent 84438a7 commit 0ea025a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
5 changes: 2 additions & 3 deletions orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,11 @@ func Update(obj Entity) error {
func Delete(obj Entity) error {
s := getSchemaFor(obj)

q, args, err := NewQueryBuilder[Entity]().SetDialect(s.dialect).Table(s.Table).Where(s.pkName(), genericGetPKValue(obj)).Delete().ToSql()
query, args, err := NewQueryBuilder[Entity]().SetDialect(s.dialect).Table(s.Table).Where(s.pkName(), genericGetPKValue(obj)).SetDelete().ToSql()
if err != nil {
return err
}

_, err = getSchemaFor(obj).getSQLDB().Exec(q, args...)
_, err = getSchemaFor(obj).getSQLDB().Exec(query, args...)
return err
}

Expand Down
5 changes: 3 additions & 2 deletions orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,9 @@ func TestExec(t *testing.T) {
assert.NoError(t, orm.Save(&Post{
Body: "first post",
}))

_, affected, err := orm.Exec[Post](orm.NewQueryBuilder[Post]().Where("id", 1).Delete())
res, err := orm.Query[Post]().Where("id", 1).Delete()
assert.NoError(t, err)
affected, err := res.RowsAffected()
assert.NoError(t, err)
assert.EqualValues(t, 1, affected)
})
Expand Down
4 changes: 2 additions & 2 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ func TestUpdate(t *testing.T) {
}
func TestDelete(t *testing.T) {
t.Run("delete without whereClause", func(t *testing.T) {
d := NewQueryBuilder[Dummy]().Table("users").Delete()
d := NewQueryBuilder[Dummy]().Table("users").SetDelete()
sql, args, err := d.ToSql()
assert.NoError(t, err)
assert.Equal(t, `DELETE FROM users`, sql)
assert.Empty(t, args)
})
t.Run("delete with whereClause", func(t *testing.T) {
d := NewQueryBuilder[Dummy]().Table("users").SetDialect(Dialects.MySQL).Where("created_at", ">", "2012-01-10").Delete()
d := NewQueryBuilder[Dummy]().Table("users").SetDialect(Dialects.MySQL).Where("created_at", ">", "2012-01-10").SetDelete()
sql, args, err := d.ToSql()
assert.NoError(t, err)
assert.Equal(t, `DELETE FROM users WHERE created_at > ?`, sql)
Expand Down

0 comments on commit 0ea025a

Please sign in to comment.