fix golint issues in core/stores (#527)
This commit is contained in:
@@ -20,8 +20,10 @@ const (
|
||||
var emptyBulkStmt bulkStmt
|
||||
|
||||
type (
|
||||
// ResultHandler defines the method of result handlers.
|
||||
ResultHandler func(sql.Result, error)
|
||||
|
||||
// A BulkInserter is used to batch insert records.
|
||||
BulkInserter struct {
|
||||
executor *executors.PeriodicalExecutor
|
||||
inserter *dbInserter
|
||||
@@ -35,6 +37,7 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
// NewBulkInserter returns a BulkInserter.
|
||||
func NewBulkInserter(sqlConn SqlConn, stmt string) (*BulkInserter, error) {
|
||||
bkStmt, err := parseInsertStmt(stmt)
|
||||
if err != nil {
|
||||
@@ -53,10 +56,12 @@ func NewBulkInserter(sqlConn SqlConn, stmt string) (*BulkInserter, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Flush flushes all the pending records.
|
||||
func (bi *BulkInserter) Flush() {
|
||||
bi.executor.Flush()
|
||||
}
|
||||
|
||||
// Insert inserts given args.
|
||||
func (bi *BulkInserter) Insert(args ...interface{}) error {
|
||||
value, err := format(bi.stmt.valueFormat, args...)
|
||||
if err != nil {
|
||||
@@ -68,17 +73,20 @@ func (bi *BulkInserter) Insert(args ...interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetResultHandler sets the given handler.
|
||||
func (bi *BulkInserter) SetResultHandler(handler ResultHandler) {
|
||||
bi.executor.Sync(func() {
|
||||
bi.inserter.resultHandler = handler
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateOrDelete runs update or delete queries, which flushes pending records first.
|
||||
func (bi *BulkInserter) UpdateOrDelete(fn func()) {
|
||||
bi.executor.Flush()
|
||||
fn()
|
||||
}
|
||||
|
||||
// UpdateStmt updates the insert statement.
|
||||
func (bi *BulkInserter) UpdateStmt(stmt string) error {
|
||||
bkStmt, err := parseInsertStmt(stmt)
|
||||
if err != nil {
|
||||
|
||||
@@ -7,6 +7,7 @@ const (
|
||||
duplicateEntryCode uint16 = 1062
|
||||
)
|
||||
|
||||
// NewMysql returns a mysql connection.
|
||||
func NewMysql(datasource string, opts ...SqlOption) SqlConn {
|
||||
opts = append(opts, withMysqlAcceptable())
|
||||
return NewSqlConn(mysqlDriverName, datasource, opts...)
|
||||
|
||||
@@ -11,9 +11,13 @@ import (
|
||||
const tagName = "db"
|
||||
|
||||
var (
|
||||
ErrNotMatchDestination = errors.New("not matching destination to scan")
|
||||
ErrNotReadableValue = errors.New("value not addressable or interfaceable")
|
||||
ErrNotSettable = errors.New("passed in variable is not settable")
|
||||
// ErrNotMatchDestination is an error that indicates not matching destination to scan.
|
||||
ErrNotMatchDestination = errors.New("not matching destination to scan")
|
||||
// ErrNotReadableValue is an error that indicates value is not addressable or interfaceable.
|
||||
ErrNotReadableValue = errors.New("value not addressable or interfaceable")
|
||||
// ErrNotSettable is an error that indicates the passed in variable is not settable.
|
||||
ErrNotSettable = errors.New("passed in variable is not settable")
|
||||
// ErrUnsupportedValueType is an error that indicates unsupported unmarshal type.
|
||||
ErrUnsupportedValueType = errors.New("unsupported unmarshal type")
|
||||
)
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/tal-tech/go-zero/core/breaker"
|
||||
)
|
||||
|
||||
// ErrNotFound is an alias of sql.ErrNoRows
|
||||
var ErrNotFound = sql.ErrNoRows
|
||||
|
||||
type (
|
||||
@@ -25,8 +26,10 @@ type (
|
||||
Transact(func(session Session) error) error
|
||||
}
|
||||
|
||||
// SqlOption defines the method to customize a sql connection.
|
||||
SqlOption func(*commonSqlConn)
|
||||
|
||||
// StmtSession interface represents a session that can be used to execute statements.
|
||||
StmtSession interface {
|
||||
Close() error
|
||||
Exec(args ...interface{}) (sql.Result, error)
|
||||
@@ -62,6 +65,7 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
// NewSqlConn returns a SqlConn with given driver name and datasource.
|
||||
func NewSqlConn(driverName, datasource string, opts ...SqlOption) SqlConn {
|
||||
conn := &commonSqlConn{
|
||||
driverName: driverName,
|
||||
|
||||
Reference in New Issue
Block a user