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,
})

GoSQL will add the primary key (in this case "id") to the insert query if it is not the zero value for its type.

Last updated