func (engine *Engine) Get(bean interface{}, condiBeans ...interface{}) (bool, error)
type Employee struct { ID int64 Name string Age int Salary float64 } func getEmployeeByID(id int) (*Employee, error) { engine, err := xorm.NewEngine("mysql", "root:password@tcp(127.0.0.1:3306)/test") if err != nil { return nil, err } defer engine.Close() employee := &Employee{ID: id} has, err := engine.Get(employee) if err != nil { return nil, err } if has { return employee, nil } return nil, errors.New("Employee not found") }
type User struct { ID int `xorm:"pk autoincr"` Username string Password string } func main() { engine, err := xorm.NewEngine("mysql", "root:password@tcp(127.0.0.1:3306)/test") if err != nil { log.Fatal(err) } defer engine.Close() user := &User{Username: "user1", Password: "password1"} _, err = engine.Insert(user) if err != nil { log.Fatal(err) } user2 := &User{} engine.Where("username = ?", "user1").Get(user2) fmt.Printf("%+v", user2) }This example inserts a new user record into the database and then retrieves it using the `engine.Get()` method. The `Where()` method is used to specify the criteria for selecting the data.