Commit 82884287 authored by 贾浩@五瓣科技's avatar 贾浩@五瓣科技

update db config

parent 7c4ee096
......@@ -20,4 +20,5 @@ type QuestConfig struct {
User string
Password string
Database string
Debug bool
}
......@@ -19,6 +19,9 @@ func NewQuest(cfg *conf.QuestConfig) (q *Quest) {
if err != nil {
panic(err)
}
if cfg.Debug {
_db = _db.Debug()
}
testSQL := "SELECT 1;"
err = _db.Raw(testSQL).Error
if err != nil {
......@@ -37,7 +40,7 @@ func (q *Quest) GetProofs(startTimestamp, endTimestamp int64, lastTaskID string,
"ORDER BY `TaskId` ASC " +
"LIMIT ?;"
err = q.db.Debug().Raw(querySQL, startTimestamp, endTimestamp, lastTaskID, limit).Scan(&proofs).Error
err = q.db.Raw(querySQL, startTimestamp, endTimestamp, lastTaskID, limit).Scan(&proofs).Error
return
}
......@@ -49,7 +52,7 @@ func (q *Quest) GetPendingWorkload(startTimestamp int64, address string) (worklo
"WHERE `TaskFinishTimestamp` >= ?" +
"AND `TaskProfitAccount` = ? ;"
err = q.db.Debug().Raw(querySQL, startTimestamp, address).First(&proof).Error
err = q.db.Raw(querySQL, startTimestamp, address).First(&proof).Error
if err != nil {
if err == gorm.ErrRecordNotFound {
return 0, nil
......@@ -63,7 +66,7 @@ func (q *Quest) GetGlobalWorkload(startTimestamp int64) (workload uint64, err er
querySQL := "SELECT " +
"SUM(`TaskWorkload`) " +
"FROM `proof` " +
"WHERE `TaskFinishTimestamp` >= ? ;"
err = q.db.Debug().Raw(querySQL, startTimestamp).Row().Scan(&workload)
"WHERE `TaskFinishTimestamp` >= ? AND `TaskFinishTimestamp` < ?;"
err = q.db.Raw(querySQL, startTimestamp, startTimestamp+86400).Row().Scan(&workload)
return workload, err
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment