Fetch multipe objects into a slice or a map, use Find:

var everyone []Userinfo
err := engine.Find(&everyone)

users := make(map[int64]Userinfo)
err := engine.Find(&users)
  • also you can use Where, Limit
var allusers []Userinfo
err := engine.Where("id > ?", "3").Limit(10,20).Find(&allusers) //Get id>3 limit 10 offset 20
  • or you can use a struct query
var tenusers []Userinfo
err := engine.Limit(10).Find(&tenusers, &Userinfo{Name:"xlw"}) //Get All Name="xlw" limit 10 offset 0
  • or In function
var tenusers []Userinfo
err := engine.In("id", 1, 3, 5).Find(&tenusers) //Get All id in (1, 3, 5)
  • The default will query all columns of a table. Use Cols function if you want to select some columns
var tenusers []Userinfo
err := engine.Cols("id", "name").Find(&tenusers) //Find only id and name
  • You can also use slice of ints if you only want one column
var ints []int64
err := engine.Table("user").Cols("id").Find(&ints)