diff --git a/application.go b/application.go index ed7db0a..233b601 100644 --- a/application.go +++ b/application.go @@ -180,7 +180,10 @@ func (that *Application) SetCache() { cacheIns := HoTimeCache{} cacheIns.Init(that.Config.GetMap("cache"), HoTimeDBInterface(&that.Db), &that.Error) that.HoTimeCache = &cacheIns - that.Db.HoTimeCache = &cacheIns + //debug模式开启的时候关闭数据库缓存,防止调试出问题 + if that.Config.GetInt("debug") == 0 { + that.Db.HoTimeCache = &cacheIns + } } // SetConfig 设置配置文件路径全路径或者相对路径 diff --git a/db/db.go b/db/db.go index 2226a32..84b6e70 100644 --- a/db/db.go +++ b/db/db.go @@ -142,7 +142,7 @@ func (that *HoTimeDB) Row(resl *sql.Rows) []Map { if a[j] != nil && reflect.ValueOf(a[j]).Type().String() == "[]uint8" { lis[strs[j]] = string(a[j].([]byte)) } else { - lis[strs[j]] = a[j] + lis[strs[j]] = a[j] //取实际类型 } } @@ -472,7 +472,7 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map { //如果缓存有则从缓存取 cacheData := that.HoTimeCache.Db(table + ":" + md5) - if cacheData.Data != nil { + if cacheData != nil && cacheData.Data != nil { return cacheData.ToMapArray() } } diff --git a/example/admin/user.go b/example/admin/user.go index eab8397..678128e 100644 --- a/example/admin/user.go +++ b/example/admin/user.go @@ -2,11 +2,16 @@ package admin import ( . "../../../hotime" + . "../../../hotime/common" + "fmt" ) var UserCtr = Ctr{ "info": func(this *Context) { + user := this.Db.Get(this.RouterString[1], "*", Map{"uid": this.RouterString[2]}) + fmt.Println(user.Get("utime"), user.GetFloat64("utime"), user.GetInt("utime")) + this.Display(0, user) }, "add": func(this *Context) { @@ -18,6 +23,8 @@ var UserCtr = Ctr{ }, "search": func(this *Context) { - + user := this.Db.Select(this.RouterString[1], "*") + fmt.Println(user) + this.Display(0, user) }, } diff --git a/var.go b/var.go index 37d428c..07cb138 100644 --- a/var.go +++ b/var.go @@ -41,7 +41,7 @@ var ConfigNote = Map{ "logFile": "无默认,非必须,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置", "webConnectLogShow": "默认true,非必须,访问日志如果需要web访问链接、访问ip、访问时间打印,false为关闭true开启此功能", "webConnectLogFile": "无默认,非必须,webConnectLogShow开启之后才能使用,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置", - "debug": "默认1,必须,0关闭,其他开启,0用于生产环境;其他值用于开发测试,会显示更多内容并能够辅助研发,自动生成配置文件、代码等功能,web无缓存", //debug 0关闭1开启 + "debug": "默认1,必须,0关闭,其他开启,0用于生产环境;其他值用于开发测试,会显示更多内容并能够辅助研发,自动生成配置文件、代码等功能,web无缓存,数据库不启用缓存", //debug 0关闭1开启 "db": Map{ "注释": "配置即启用,非必须,默认使用sqlite数据库", "mysql": Map{