第一个插入数据成功

This commit is contained in:
eson 2020-07-07 12:04:05 +08:00
parent db782a3533
commit 8a0d71a34e
4 changed files with 37 additions and 6 deletions

View File

@ -7,6 +7,7 @@ import (
"github.com/474420502/hunter"
)
var targetTypeRanking = "openrec_ranking"
var openrecRanking *OpenrecRanking
// storeOpenrec 源存储实例, 为存储源数据的实现. 表格具体参考sql/intimate_source.sql
@ -30,24 +31,36 @@ func init() {
}
/*
CREATE TABLE `platform_openrec` (
CREATE TABLE `platform_openrec` (
`url` text NOT NULL,
`target_type` varchar(64) NOT NULL,
`source` longtext DEFAULT NULL,
`ext` json DEFAULT NULL,
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`operator` tinyint NOT NULL,
KEY `operator_idx` (`operator`),
KEY `update_time_idx` (`update_time`),
KEY `target_type_idx` (`target_type`)
);
*/
// PlatformOpenrec 存储源结构
type PlatformOpenrec struct {
Url string //
TargetType string //
Source sql.NullString //
Ext interface{} //
UpdateTime time.Time //
Operator int32 //
}
// GetOperator Get return Operator int32
func (po *PlatformOpenrec) GetOperator() int32 {
return po.Operator
}
// SetOperator Set Operator int32
func (po *PlatformOpenrec) SetOperator(Operator int32) {
po.Operator = Operator
}
// GetUpdateTime Get return UpdateTime time.Time
@ -60,12 +73,12 @@ func (po *PlatformOpenrec) SetUpdateTime(UpdateTime time.Time) {
po.UpdateTime = UpdateTime
}
// GetExt Get return Ext map[string]interface
// GetExt Get return Ext interface{}
func (po *PlatformOpenrec) GetExt() interface{} {
return po.Ext
}
// SetExt Set Ext map[string]interface
// SetExt Set Ext interface{}
func (po *PlatformOpenrec) SetExt(Ext interface{}) {
po.Ext = Ext
}
@ -111,5 +124,11 @@ func (or *OpenrecRanking) Execute(cxt *hunter.TaskContext) {
if err != nil {
panic(err)
}
cxt.SetShare("test", string(resp.Content()))
data := &PlatformOpenrec{}
content := resp.Content()
data.SetSource(sql.NullString{String: string(content), Valid: len(content) > 0})
data.SetUrl(cxt.Workflow().GetRawURL())
data.SetTargetType(targetTypeRanking)
storeOpenrec.Save(data)
}

View File

@ -7,6 +7,8 @@ CREATE TABLE IF NOT EXISTS `platform_openrec` (
`source` longtext DEFAULT NULL,
`ext` json DEFAULT NULL,
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`operator` int DEFAULT 0,
KEY `operator_idx` (`operator`),
KEY `update_time_idx` (`update_time`),
KEY `target_type_idx` (`target_type`)
);

View File

@ -35,6 +35,6 @@ func NewStore() *Store {
func (store *Store) Save(isource ISource) {
_, err := store.db.Exec("insert into `platform_openrec`(url, target_type, source, ext) values(?,?,?,?)", isource.GetUrl(), isource.GetTargetType(), isource.GetSource(), isource.GetExt())
if err != nil {
log.Println(err)
log.Fatalln(err)
}
}

10
store_test.go Normal file
View File

@ -0,0 +1,10 @@
package main
import (
"testing"
)
func TestStoreInsert(t *testing.T) {
// ht := hunter.NewHunter(openrecRanking)
// ht.Execute()
}