optimize log tool

This commit is contained in:
hoteas
2021-05-25 19:53:34 +08:00
parent 770f0a94c9
commit 740059075a
6 changed files with 41 additions and 27 deletions
+8 -6
View File
@@ -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