test
This commit is contained in:
parent
f9dab01687
commit
8516f77157
26
logdb.go
26
logdb.go
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
@ -89,3 +90,28 @@ func (logdb *LogDB) Connect() {
|
||||||
logdb.driver = db
|
logdb.driver = db
|
||||||
log.Println("connect is", logdb.Ping(), logdb)
|
log.Println("connect is", logdb.Ping(), logdb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ADInsert 插入数据
|
||||||
|
func (logdb *LogDB) ADInsert(uid, device, platform, area_cc, section_id, response string, spider_id, channel, media, catch_account_id, status, priority int, ts_crawl time.Time) {
|
||||||
|
_, err := logdb.driver.Exec("insert into "+logdb.DB+"(uid, spider_id, device, platform, channel, media, area_cc, catch_account_id, section_id, response, status, priority, ts_crawl) value(?, ?, ?, ?, ?, ?, ?, ?, ?, ? , ? ,? ,? ,?)", uid, spider_id, device, platform, channel, media, area_cc, catch_account_id, section_id, response, status, priority, ts_crawl)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select 插入数据
|
||||||
|
func (logdb *LogDB) Select(query string, args ...interface{}) *sql.Rows {
|
||||||
|
Rows, err := logdb.driver.Query(query, args...)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return Rows
|
||||||
|
}
|
||||||
|
|
||||||
|
// ADError 广告错误后更新
|
||||||
|
func (logdb *LogDB) ADError(query string, args ...interface{}) {
|
||||||
|
_, err := logdb.driver.Exec("update "+logdb.DB+" set status = status + 1000, error_msg=? where uid =?;", args...)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package logdb
|
package logdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
@ -18,4 +19,6 @@ func TestSelect(t *testing.T) {
|
||||||
logdb := NewLogDB("logdb.yaml")
|
logdb := NewLogDB("logdb.yaml")
|
||||||
logdb.Connect()
|
logdb.Connect()
|
||||||
t.Error(logdb)
|
t.Error(logdb)
|
||||||
|
rows := logdb.Select("select * from log_spider limit 10;")
|
||||||
|
log.Println(rows)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user