优化dbmodule

This commit is contained in:
boyce
2019-02-27 18:39:33 +08:00
parent cafdb2990d
commit a831db0a4e
2 changed files with 20 additions and 5 deletions

View File

@@ -71,6 +71,7 @@ func (slf *DBResult) Close() {
} }
} }
/*
// Next ... // Next ...
func (slf *DBResult) Next() bool { func (slf *DBResult) Next() bool {
if slf.Err != nil { if slf.Err != nil {
@@ -86,7 +87,7 @@ func (slf *DBResult) Scan(arg ...interface{}) error {
} }
return slf.res.Scan(arg...) return slf.res.Scan(arg...)
} }
*/
// SetSpecificTag ... // SetSpecificTag ...
func (slf *DBResult) SetSpecificTag(tag string) *DBResult { func (slf *DBResult) SetSpecificTag(tag string) *DBResult {
slf.tag = tag slf.tag = tag
@@ -297,8 +298,10 @@ func (slf *SyncDBResult) Get(timeoutMs int) DBResult {
func (slf *DBModule) Query(query string, args ...interface{}) DBResult { func (slf *DBModule) Query(query string, args ...interface{}) DBResult {
rows, err := slf.db.Query(query, args...) rows, err := slf.db.Query(query, args...)
return DBResult{ return DBResult{
Err: err, Err: err,
res: rows, res: rows,
tag: "json",
blur: true,
} }
} }

View File

@@ -25,14 +25,26 @@ func TestDBModule(t *testing.T) {
Uuid string `json:"uuid,omitempty"` Uuid string `json:"uuid,omitempty"`
AAAA string `json:"xxx"` AAAA string `json:"xxx"`
}{} }{}
err := res.SetSpecificTag("json").SetBlurMode(true).UnMarshal(&out) err := res.UnMarshal(&out)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
sres := db.SyncQuery("select * from tbl_fun_heelthrow where id >= 1") sres := db.SyncQuery("select * from tbl_fun_heelthrow where id >= 1")
res = sres.Get(1000) res = sres.Get(2000)
if res.Err != nil { if res.Err != nil {
t.Error(res.Err) t.Error(res.Err)
} }
out2 := []struct {
Addtime int64 `json:"addtime"`
Tname string `json:"tname"`
Uuid string `json:"uuid,omitempty"`
AAAA string `json:"xxx"`
}{}
err = res.UnMarshal(&out2)
if err != nil {
t.Error(err)
}
} }