package intimate import ( "database/sql" "encoding/json" "testing" "time" ) func TestAutoStore(t *testing.T) { uri := "root:@tcp(127.0.0.1:4000)/test?parseTime=true&loc=Local&charset=utf8mb4&collation=utf8mb4_unicode_ci" store := NewStore(uri) // queue := store.Table("streamer").Queue(TSreamer{}, CondWhere{Condition: "operator = 0"}) // re, _ := queue.Pop() // pstreamer := re.(*TSreamer) // m := make(map[string]interface{}) // json.Unmarshal(pstreamer.Iface.([]byte), &m) // spew.Println(re.(*TSreamer), m) streamer := &TSreamer{} streamer.Uid = 1 streamer.UserID = &sql.NullString{String: "xixi", Valid: true} streamer.Name = "streamer" streamer.Operator = 0 streamer.Bit = 0b11 // streamer.Ext = &sql.NullString{String: "ext", Valid: true} tag := make(map[string]interface{}) tag["json"] = true tag["name"] = "test" btag, err := json.Marshal(tag) if err != nil { t.Error(err) } streamer.Iface = btag now := time.Now() streamer.UpdateTime = &now err = store.Table("streamer").InsertOrUpdate(streamer, DUpdate{Field: "userid"}) if err != nil { t.Error(err) } } type TSreamer struct { Uid int `field:"uid" uid:"auto"` Name interface{} `field:"name"` UserID *sql.NullString `field:"userid"` Ext *sql.NullString `field:"ext"` Iface interface{} `field:"tag"` Bit uint64 `field:"bit"` Operator int `field:"operator"` UpdateTime *time.Time `field:"update_time"` }