intimate/autostore_test.go

58 lines
1.5 KiB
Go
Raw Permalink 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-03 06:17:54 +00:00
)
2020-09-09 08:49:44 +00:00
func TestAutoStore(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-09 08:49:44 +00:00
// queue := store.Table("streamer").Queue(TSreamer{}, CondWhere{Condition: "operator = 0"})
// re, _ := queue.Pop()
2020-09-07 07:13:50 +00:00
2020-09-09 08:49:44 +00:00
// 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{}
2020-09-09 08:49:44 +00:00
streamer.Uid = 1
streamer.UserID = &sql.NullString{String: "xixi", 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-09 08:49:44 +00:00
err = store.Table("streamer").InsertOrUpdate(streamer, DUpdate{Field: "userid"})
2020-09-07 07:13:50 +00:00
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
}