main.go
package main
import (
_ "github.com/mattn/go-sqlite3"
"github.com/gocraft/dbr/v2"
)
type User struct {
ID int64
Name string
Age int
}
func main(){
conn, err:= dbr.Open("sqlite3", "test.db", nil)
// CREATE TABLE `user` ( `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, `name` text , age integer)
//conn.SetMaxOpenConns(10)
if nil != err {
panic(err)
}
sess := conn.NewSession(nil)
user := &User{Name:"ooo",Age:11}
sess.InsertInto("user").
Columns("name").
Columns("age").
Record(user).
Exec()
}
only field "age" has value but field "name" is NULL
sess.InsertInto("user").
Columns("age").
Columns("name").
Record(user).
Exec()
only field "name" has value but field "age" is NULL
sess.InsertInto("user").
Record(user).
Exec()
and
sess.InsertInto("user").
Columns("*").
Record(user).
Exec()
and
sess.InsertInto("user").
Columns("name,age").
Record(user).
Exec()
all fail
main.go
only field "age" has value but field "name" is NULL
only field "name" has value but field "age" is NULL
and
and
all fail