optimize log tool
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
@@ -20,7 +22,7 @@ type HoTimeDB struct {
|
||||
LastQuery string
|
||||
LastData []interface{}
|
||||
ConnectFunc func(err ...*Error) (*sql.DB, *sql.DB)
|
||||
LastErr Error
|
||||
LastErr *Error
|
||||
limit Slice
|
||||
*sql.Tx //事务对象
|
||||
SlaveDB *sql.DB
|
||||
@@ -67,11 +69,11 @@ func (that *HoTimeDB) Action(action func(db HoTimeDB) bool) bool {
|
||||
return result
|
||||
}
|
||||
|
||||
func (that *HoTimeDB) InitDb(err ...*Error) Error {
|
||||
func (that *HoTimeDB) InitDb(err ...*Error) *Error {
|
||||
if len(err) != 0 {
|
||||
that.LastErr = *(err[0])
|
||||
that.LastErr = err[0]
|
||||
}
|
||||
that.DB, that.SlaveDB = that.ConnectFunc(&that.LastErr)
|
||||
that.DB, that.SlaveDB = that.ConnectFunc(that.LastErr)
|
||||
if that.DB == nil {
|
||||
return that.LastErr
|
||||
}
|
||||
@@ -149,7 +151,7 @@ func (that *HoTimeDB) Row(resl *sql.Rows) []Map {
|
||||
if e != nil {
|
||||
that.LastErr.SetError(e)
|
||||
} else {
|
||||
lis.JsonToMap(string(jlis), &that.LastErr)
|
||||
lis.JsonToMap(string(jlis), that.LastErr)
|
||||
}
|
||||
|
||||
dest = append(dest, lis)
|
||||
@@ -342,7 +344,7 @@ func (that *HoTimeDB) Query(query string, args ...interface{}) []Map {
|
||||
return that.Row(resl)
|
||||
}
|
||||
|
||||
func (that *HoTimeDB) Exec(query string, args ...interface{}) (sql.Result, Error) {
|
||||
func (that *HoTimeDB) Exec(query string, args ...interface{}) (sql.Result, *Error) {
|
||||
|
||||
that.LastQuery = query
|
||||
that.LastData = args
|
||||
|
||||
Reference in New Issue
Block a user