MCPcopy
hub / github.com/go-gorm/gorm / TestRows

Function TestRows

tests/sql_builder_test.go:48–70  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

46}
47
48func TestRows(t *testing.T) {
49 user1 := User{Name: "RowsUser1", Age: 1}
50 user2 := User{Name: "RowsUser2", Age: 10}
51 user3 := User{Name: "RowsUser3", Age: 20}
52 DB.Save(&user1).Save(&user2).Save(&user3)
53
54 rows, err := DB.Table("users").Where("name = ? or name = ?", user2.Name, user3.Name).Select("name, age").Rows()
55 if err != nil {
56 t.Errorf("Not error should happen, got %v", err)
57 }
58
59 count := 0
60 for rows.Next() {
61 var name string
62 var age int64
63 rows.Scan(&name, &age)
64 count++
65 }
66
67 if count != 2 {
68 t.Errorf("Should found two records")
69 }
70}
71
72func TestRaw(t *testing.T) {
73 user1 := User{Name: "ExecRawSqlUser1", Age: 1}

Callers

nothing calls this directly

Calls 7

SaveMethod · 0.80
NextMethod · 0.80
RowsMethod · 0.65
SelectMethod · 0.65
WhereMethod · 0.65
TableMethod · 0.65
ScanMethod · 0.65

Tested by

no test coverage detected