type User struct { Id int64 Name string } user := User{Id: 1, Name: "John Doe"} err := dbmap.Insert(&user) if err != nil { log.Fatal(err) }
type Product struct { Id int64 Name string Price float64 InStock bool } product := Product{Name: "Laptop", Price: 1399.99, InStock: true} // Insert multiple rows products := []Product{ {Name: "Monitor", Price: 249.99, InStock: true}, {Name: "Keyboard", Price: 69.99, InStock: false}, } _, err := dbmap.Insert(&product, &products) if err != nil { log.Fatal(err) }In this example, we define a struct Product with four fields - Id, Name, Price, and InStock. We create a single product object and an array of product objects. We pass them both to the Insert method to insert multiple rows into the database. Package Library: github.com/coopernurse/gorp