最后手动版本

This commit is contained in:
eson 2020-12-09 17:43:47 +08:00
parent b3a0b1d35e
commit 529aa6a6ff
2 changed files with 44 additions and 14 deletions

40
database.go Normal file
View File

@ -0,0 +1,40 @@
package main
import (
"time"
"github.com/go-xorm/xorm"
)
// Database mysql数据结构
type Database struct {
engine *xorm.Engine
T struct {
CountLiveAnchors *xorm.Session
}
}
// 默认全局的数据库对象
var db *Database
func databaseInit() {
db := &Database{}
// 初始化数据myrocks驱动链接
engine, err := xorm.NewEngine("mysql", "root:Nono-databoard@tcp(127.0.0.1:3306)/databoard?parseTime=true&loc=Local&charset=utf8&collation=utf8_unicode_ci")
if err != nil {
panic(err)
}
db.engine = engine
// 数据库表对象
db.T.CountLiveAnchors = engine.Table("count_live_anchors")
}
// CountLiveAnchors count_live_anchors
type CountLiveAnchors struct {
UID string `xorm:"uid"`
CreateAt time.Time `xorm:"create_at"`
IsCounted int `xorm:"is_counted"`
CountMap string `xorm:"count_map"`
}

18
main.go
View File

@ -10,16 +10,12 @@ import (
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"git.nonolive.co/eson.hsm/databoard-collect/database" "git.nonolive.co/eson.hsm/databoard-collect/database"
"github.com/go-xorm/xorm"
"github.com/google/uuid" "github.com/google/uuid"
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
) )
type CountLiveAnchors struct { func init() {
UID string `xorm:"uid"` databaseInit()
CreateAt time.Time `xorm:"create_at"`
IsCounted int `xorm:"is_counted"`
CountMap string `xorm:"count_map"`
} }
func getArgsStartTime() time.Time { func getArgsStartTime() time.Time {
@ -41,13 +37,6 @@ func getArgsStartTime() time.Time {
func main() { func main() {
mdb := database.NewStatisticsDB("mongodb://sg-board1.livenono.com:27018") mdb := database.NewStatisticsDB("mongodb://sg-board1.livenono.com:27018")
engine, err := xorm.NewEngine("mysql", "root:Nono-databoard@tcp(127.0.0.1:3306)/databoard?parseTime=true&loc=Local&charset=utf8&collation=utf8_unicode_ci")
if err != nil {
panic(err)
}
cla := engine.Table("count_live_anchors")
start := getArgsStartTime() start := getArgsStartTime()
log.Println("start from ", start) log.Println("start from ", start)
// start, err := time.ParseInLocation("2006-01-02 15:04:03", "2020-11-30 16:29:17", time.Local) // start, err := time.ParseInLocation("2006-01-02 15:04:03", "2020-11-30 16:29:17", time.Local)
@ -65,6 +54,7 @@ func main() {
panic(err) panic(err)
} }
c := &CountLiveAnchors{} c := &CountLiveAnchors{}
c.UID = uuid.New().String() c.UID = uuid.New().String()
c.IsCounted = 0 c.IsCounted = 0
c.CreateAt = la.CreateAt c.CreateAt = la.CreateAt
@ -74,7 +64,7 @@ func main() {
panic(err) panic(err)
} }
c.CountMap = string(data) c.CountMap = string(data)
_, err = cla.Insert(c) _, err = db.T.CountLiveAnchors.Insert(c)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} }