Insert
Insert new rows into the database.
This type is used in the examples on this page.
type User struct {
ID int `gosql:"primary"`
Email string
IsActive bool
}
If your user
table has default auto-increment for the primary column, then you can leave it as the zero value.
db.Insert(&User{
Email: "gopher@example.com",
IsActive: true,
})
You can also provide the id.
db.Insert(&User{
ID: 1,
Email: "gopher@example.com",
IsActive: true,
})
Last updated
Was this helpful?