import ( _ "github.com/mattn/go-sqlite3" "github.com/go-xorm/xorm" ) db, err := xorm.NewEngine("sqlite3", "./test.db") if err != nil { panic(err) } session := db.NewSession() defer session.Close()
type User struct { Id int `xorm:"id"` Name string `xorm:"name"` } session := db.NewSession() users := make([]User, 0) err := db.Find(&users) if err != nil { panic(err) } for _, user := range users { fmt.Println(user.Name) }
type User struct { Id int `xorm:"id"` Name string `xorm:"name"` } session := db.NewSession() user := User{Name: "John Doe"} _, err := session.Insert(&user) if err != nil { panic(err) }
type User struct { Id int `xorm:"id"` Name string `xorm:"name"` } session := db.NewSession() user := User{Id: 1, Name: "Jane Doe"} _, err := session.Update(&user) if err != nil { panic(err) }In conclusion, go-xorm.xorm Session is a library package that provides an easy-to-use interface for working with databases in Golang. It supports many popular databases such as MySQL, PostgreSQL, SQLite, and MSSQL. With its rich set of features and APIs, developers can easily perform CRUD operations and interact with databases efficiently.