Refine the context and Try to fix the nil issue.
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"github.com/eyebluecn/tank/code/core"
|
||||
"github.com/eyebluecn/tank/code/tool/result"
|
||||
"github.com/nu7hatch/gouuid"
|
||||
"time"
|
||||
@ -15,7 +16,7 @@ func (this *PreferenceDao) Fetch() *Preference {
|
||||
|
||||
// Read
|
||||
var preference = &Preference{}
|
||||
db := CONTEXT.GetDB().First(preference)
|
||||
db := core.CONTEXT.GetDB().First(preference)
|
||||
if db.Error != nil {
|
||||
|
||||
if db.Error.Error() == result.DB_ERROR_NOT_FOUND {
|
||||
@ -39,7 +40,7 @@ func (this *PreferenceDao) Create(preference *Preference) *Preference {
|
||||
preference.CreateTime = time.Now()
|
||||
preference.UpdateTime = time.Now()
|
||||
preference.Sort = time.Now().UnixNano() / 1e6
|
||||
db := CONTEXT.GetDB().Create(preference)
|
||||
db := core.CONTEXT.GetDB().Create(preference)
|
||||
this.PanicError(db.Error)
|
||||
|
||||
return preference
|
||||
@ -49,7 +50,7 @@ func (this *PreferenceDao) Create(preference *Preference) *Preference {
|
||||
func (this *PreferenceDao) Save(preference *Preference) *Preference {
|
||||
|
||||
preference.UpdateTime = time.Now()
|
||||
db := CONTEXT.GetDB().Save(preference)
|
||||
db := core.CONTEXT.GetDB().Save(preference)
|
||||
this.PanicError(db.Error)
|
||||
|
||||
return preference
|
||||
@ -59,6 +60,6 @@ func (this *PreferenceDao) Save(preference *Preference) *Preference {
|
||||
func (this *PreferenceDao) Cleanup() {
|
||||
|
||||
this.logger.Info("[PreferenceDao]执行清理:清除数据库中所有Preference记录。")
|
||||
db := CONTEXT.GetDB().Where("uuid is not null").Delete(Preference{})
|
||||
db := core.CONTEXT.GetDB().Where("uuid is not null").Delete(Preference{})
|
||||
this.PanicError(db.Error)
|
||||
}
|
||||
|
Reference in New Issue
Block a user