package main import ( "github.com/go-xorm/xorm" "fmt" ) type User struct { Id int64 `xorm:"pk autoincr"` Name string `xorm:"not null"` } func main() { engine, err := xorm.NewEngine("mysql", "root:123456@tcp(127.0.0.1:3306)/test") if err != nil { fmt.Println("Error:", err) return } user := User{Name: "John Doe"} affected, err := engine.Insert(&user) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Affected Rows:", affected) }
package main import ( "github.com/go-xorm/xorm" "fmt" ) type User struct { Id int64 `xorm:"pk autoincr"` Name string `xorm:"not null"` } func main() { engine, err := xorm.NewEngine("mysql", "root:123456@tcp(127.0.0.1:3306)/test") if err != nil { fmt.Println("Error:", err) return } users := []User{{Name: "John Doe"}, {Name: "Jane Doe"}} affected, err := engine.Insert(&users) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Affected Rows:", affected) }This example inserts multiple records into the "user" table. The "users" slice contains two "User" structs, each representing a record to insert. The "Insert" method is called with a pointer to the "users" slice to insert all records at once. In conclusion, the package library is github.com.go-xorm.xorm, and it provides a powerful and easy-to-use API for interacting with databases using the ORM pattern. The "Insert" method is a key feature of this package, allowing developers to easily insert data into database tables with just a few lines of code.