This commit is contained in:
huangsimin 2018-12-10 16:52:46 +08:00
parent f9dab01687
commit 8516f77157
2 changed files with 29 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"log"
"time"
yaml "gopkg.in/yaml.v2"
)
@ -89,3 +90,28 @@ func (logdb *LogDB) Connect() {
logdb.driver = db
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)
}
}

View File

@ -1,6 +1,7 @@
package logdb
import (
"log"
"testing"
_ "github.com/go-sql-driver/mysql"
@ -18,4 +19,6 @@ func TestSelect(t *testing.T) {
logdb := NewLogDB("logdb.yaml")
logdb.Connect()
t.Error(logdb)
rows := logdb.Select("select * from log_spider limit 10;")
log.Println(rows)
}