mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
优化dbmodule
This commit is contained in:
@@ -71,6 +71,7 @@ func (slf *DBResult) Close() {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// Next ...
|
||||
func (slf *DBResult) Next() bool {
|
||||
if slf.Err != nil {
|
||||
@@ -86,7 +87,7 @@ func (slf *DBResult) Scan(arg ...interface{}) error {
|
||||
}
|
||||
return slf.res.Scan(arg...)
|
||||
}
|
||||
|
||||
*/
|
||||
// SetSpecificTag ...
|
||||
func (slf *DBResult) SetSpecificTag(tag string) *DBResult {
|
||||
slf.tag = tag
|
||||
@@ -297,8 +298,10 @@ func (slf *SyncDBResult) Get(timeoutMs int) DBResult {
|
||||
func (slf *DBModule) Query(query string, args ...interface{}) DBResult {
|
||||
rows, err := slf.db.Query(query, args...)
|
||||
return DBResult{
|
||||
Err: err,
|
||||
res: rows,
|
||||
Err: err,
|
||||
res: rows,
|
||||
tag: "json",
|
||||
blur: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,14 +25,26 @@ func TestDBModule(t *testing.T) {
|
||||
Uuid string `json:"uuid,omitempty"`
|
||||
AAAA string `json:"xxx"`
|
||||
}{}
|
||||
err := res.SetSpecificTag("json").SetBlurMode(true).UnMarshal(&out)
|
||||
err := res.UnMarshal(&out)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
sres := db.SyncQuery("select * from tbl_fun_heelthrow where id >= 1")
|
||||
res = sres.Get(1000)
|
||||
res = sres.Get(2000)
|
||||
if res.Err != nil {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user