This commit is contained in:
suyl
2021-07-23 14:54:52 +08:00
parent a3b287d5e8
commit 1c8b65a414

View File

@@ -26,7 +26,7 @@ func Insert(db *sqlx.DB, obj interface{}) (err error) {
}
sname := stype.Name()
sql.WriteString("INSERT INTO ")
for i := 1; i < stype.NumField(); i++ {
for i := 0; i < stype.NumField(); i++ {
if stype.Field(i).Type.String() == "*time.Time" {
if direct.Field(i).Interface().(*time.Time) != nil {
values.WriteString(stype.Field(i).Tag.Get("json") + ",")
@@ -49,6 +49,8 @@ func Insert(db *sqlx.DB, obj interface{}) (err error) {
sql.WriteString("?")
}
sql.WriteString(")")
fmt.Println(sql.String())
fmt.Println(sqlParams)
_, err = db.DB.Exec(sql.String(), sqlParams...)
return err
}