|
| 1 | +package query |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | +) |
| 9 | + |
| 10 | +func TestExec(t *testing.T) { |
| 11 | + NewTableForQueryTest() |
| 12 | + qb := getTestBuilder() |
| 13 | + rows := qb.From("table_test_query as t"). |
| 14 | + Where("email", "like", "%@yao.run"). |
| 15 | + OrderBy("id"). |
| 16 | + MustGet() |
| 17 | + |
| 18 | + assert.Equal(t, 4, len(rows), "the return rows should have 4 items") |
| 19 | + if len(rows) == 4 { |
| 20 | + assert.Equal(t, "96.32", fmt.Sprintf("%.2f", rows[0].Get("score")), "the return value should be true") |
| 21 | + assert.Equal(t, "64.56", fmt.Sprintf("%.2f", rows[1].Get("score")), "the return value should be true") |
| 22 | + assert.Equal(t, "99.27", fmt.Sprintf("%.2f", rows[2].Get("score")), "the return value should be true") |
| 23 | + assert.Equal(t, "48.12", fmt.Sprintf("%.2f", rows[3].Get("score")), "the return value should be true") |
| 24 | + } |
| 25 | + |
| 26 | + // Exec |
| 27 | + res, err := qb.Exec("update table_test_query set score = 100 where email like ?", "%@yao.run") |
| 28 | + assert.Nil(t, err, "the error should be nil") |
| 29 | + affected, err := res.RowsAffected() |
| 30 | + assert.Nil(t, err, "the error should be nil") |
| 31 | + assert.Equal(t, int64(4), affected, "the rows affected should be 4") |
| 32 | +} |
0 commit comments