intimate/autostore_test.go

60 lines
1.4 KiB
Go
Raw Normal View History

2020-09-03 06:17:54 +00:00
package intimate
import (
2020-09-03 10:50:32 +00:00
"database/sql"
2020-09-07 07:13:50 +00:00
"encoding/json"
2020-09-03 06:17:54 +00:00
"testing"
"time"
2020-09-07 07:13:50 +00:00
"github.com/davecgh/go-spew/spew"
2020-09-03 06:17:54 +00:00
)
func estAutoStore(t *testing.T) {
2020-09-04 11:01:51 +00:00
uri := "root:@tcp(127.0.0.1:4000)/test?parseTime=true&loc=Local&charset=utf8mb4&collation=utf8mb4_unicode_ci"
store := NewStore(uri)
2020-09-08 10:24:51 +00:00
queue := store.Table("streamer").Queue(TSreamer{}, CondWhere{Condition: "operator = 0"})
2020-09-07 07:13:50 +00:00
re, _ := queue.Pop()
pstreamer := re.(*TSreamer)
m := make(map[string]interface{})
json.Unmarshal(pstreamer.Iface.([]byte), &m)
spew.Println(re.(*TSreamer), m)
2020-09-04 11:01:51 +00:00
streamer := &TSreamer{}
streamer.Uid = 2
2020-09-07 07:13:50 +00:00
streamer.UserID = &sql.NullString{String: "hehe", Valid: true}
2020-09-04 11:01:51 +00:00
streamer.Name = "streamer"
streamer.Operator = 0
2020-09-07 07:13:50 +00:00
streamer.Bit = 0b11
// streamer.Ext = &sql.NullString{String: "ext", Valid: true}
2020-09-07 07:13:50 +00:00
tag := make(map[string]interface{})
tag["json"] = true
tag["name"] = "test"
btag, err := json.Marshal(tag)
2020-09-04 11:01:51 +00:00
if err != nil {
t.Error(err)
}
2020-09-07 07:13:50 +00:00
streamer.Iface = btag
now := time.Now()
streamer.UpdateTime = &now
2020-09-04 11:01:51 +00:00
2020-09-07 07:13:50 +00:00
err = store.Table("streamer").Insert(streamer)
if err != nil {
t.Error(err)
2020-09-04 11:01:51 +00:00
}
2020-09-07 07:13:50 +00:00
}
2020-09-03 06:17:54 +00:00
2020-09-03 10:50:32 +00:00
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"`
2020-09-03 06:17:54 +00:00
}