change marshal strategy
This commit is contained in:
parent
2c54f18374
commit
c3531819bd
|
@ -109,7 +109,7 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "github.com/zr-hebo/util-db",
|
||||
"Rev": "3ff29f916f7b712b3adc53c4b9b19b13b8bbed87"
|
||||
"Rev": "06948bca5665b2d80078f9ff5c015eabb43c54f8"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/zr-hebo/util-http",
|
||||
|
|
|
@ -62,7 +62,7 @@ func (mqp *MysqlQueryPiece) Bytes() (content []byte) {
|
|||
return mqp.jsonContent
|
||||
}
|
||||
|
||||
mqp.jsonContent = marsharQueryPiece(mqp)
|
||||
mqp.jsonContent = marsharQueryPieceMonopolize(mqp)
|
||||
return mqp.jsonContent
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
// "github.com/json-iterator/go"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/pingcap/tidb/util/hack"
|
||||
"time"
|
||||
)
|
||||
|
||||
var jsonIterator = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
|
||||
type QueryPiece interface {
|
||||
String() *string
|
||||
Bytes() []byte
|
||||
|
@ -70,7 +72,7 @@ func (bqp *BaseQueryPiece) Bytes() (content []byte) {
|
|||
return bqp.jsonContent
|
||||
}
|
||||
|
||||
bqp.jsonContent = marsharQueryPiece(bqp)
|
||||
bqp.jsonContent = marsharQueryPieceMonopolize(bqp)
|
||||
return bqp.jsonContent
|
||||
}
|
||||
|
||||
|
@ -81,7 +83,7 @@ func (bqp *BaseQueryPiece) GetSQL() (*string) {
|
|||
func (bqp *BaseQueryPiece) Recovery() {
|
||||
}
|
||||
|
||||
func marsharQueryPiece(qp interface{}) []byte {
|
||||
func marsharQueryPieceShareMemory(qp interface{}) []byte {
|
||||
var cacheBuffer = localSliceBufferPool.Dequeue()
|
||||
if len(cacheBuffer) > 0 {
|
||||
panic("there already have bytes in buffer")
|
||||
|
@ -95,3 +97,12 @@ func marsharQueryPiece(qp interface{}) []byte {
|
|||
|
||||
return buffer.Bytes()
|
||||
}
|
||||
|
||||
func marsharQueryPieceMonopolize(qp interface{}) (content []byte) {
|
||||
content, err := jsonIterator.Marshal(qp)
|
||||
if err != nil {
|
||||
return []byte(err.Error())
|
||||
}
|
||||
|
||||
return content
|
||||
}
|
|
@ -43,12 +43,14 @@ type MysqlDB struct {
|
|||
DatabaseType string
|
||||
DBName string
|
||||
ConnectTimeout int
|
||||
QueryTimeout int
|
||||
}
|
||||
|
||||
// NewMysqlDB 创建MySQL数据库
|
||||
func NewMysqlDB() (md *MysqlDB) {
|
||||
md = new(MysqlDB)
|
||||
md.DatabaseType = dbTypeMysql
|
||||
md.QueryTimeout = 5
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -352,7 +354,7 @@ func (md *MysqlDB) fillConnStr() string {
|
|||
md.UserName, md.Passwd, md.IP, md.Port, md.DBName)
|
||||
if md.ConnectTimeout > 0 {
|
||||
dbServerInfoStr = fmt.Sprintf("%s?timeout=%ds&readTimeout=%ds&writeTimeout=%ds",
|
||||
dbServerInfoStr, md.ConnectTimeout, md.ConnectTimeout, md.ConnectTimeout)
|
||||
dbServerInfoStr, md.ConnectTimeout, md.QueryTimeout, md.QueryTimeout)
|
||||
}
|
||||
|
||||
return dbServerInfoStr
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
|
||||
// PooledMysqlDB Mysql主机实例
|
||||
type PooledMysqlDB struct {
|
||||
MysqlDB
|
||||
|
@ -46,6 +45,7 @@ func NewPooledMysqlDBWithAllParam(
|
|||
func NewPooledMysqlDB() (pmd *PooledMysqlDB) {
|
||||
pmd = new(PooledMysqlDB)
|
||||
pmd.DatabaseType = dbTypeMysql
|
||||
pmd.QueryTimeout = 5
|
||||
pmd.lock = new(sync.Mutex)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue