Code optimized (#523)

* optimized markdown generator

* optimized markdown generator

* optimized markdown generator

* add more comment

* add comment

* add comment

* add comments for rpc tool

* add comments for model tool

* add comments for model tool

* add comments for model tool

* add comments for config tool

* add comments for config tool

* add comments

* add comments

* add comments

* add comments

* add comment

* remove rpc main head info

* add comment

* optimized

Co-authored-by: anqiansong <anqiansong@xiaoheiban.cn>
This commit is contained in:
kingxt
2021-02-26 16:11:47 +08:00
committed by GitHub
parent ef146cf5ba
commit e6ef1fca12
104 changed files with 651 additions and 375 deletions

View File

@@ -9,6 +9,7 @@ import (
)
type (
// MockConn defines a mock connection instance for mysql
MockConn struct {
db *sql.DB
}
@@ -17,43 +18,51 @@ type (
}
)
// NewMockConn creates an instance for MockConn
func NewMockConn(db *sql.DB) *MockConn {
return &MockConn{db: db}
}
// Exec executes sql and returns the result
func (conn *MockConn) Exec(query string, args ...interface{}) (sql.Result, error) {
return exec(conn.db, query, args...)
}
// Prepare executes sql by sql.DB
func (conn *MockConn) Prepare(query string) (sqlx.StmtSession, error) {
st, err := conn.db.Prepare(query)
return statement{stmt: st}, err
}
// QueryRow executes sql and returns a query row
func (conn *MockConn) QueryRow(v interface{}, q string, args ...interface{}) error {
return query(conn.db, func(rows *sql.Rows) error {
return unmarshalRow(v, rows, true)
}, q, args...)
}
// QueryRowPartial executes sql and returns a partial query row
func (conn *MockConn) QueryRowPartial(v interface{}, q string, args ...interface{}) error {
return query(conn.db, func(rows *sql.Rows) error {
return unmarshalRow(v, rows, false)
}, q, args...)
}
// QueryRows executes sql and returns query rows
func (conn *MockConn) QueryRows(v interface{}, q string, args ...interface{}) error {
return query(conn.db, func(rows *sql.Rows) error {
return unmarshalRows(v, rows, true)
}, q, args...)
}
// QueryRowsPartial executes sql and returns partial query rows
func (conn *MockConn) QueryRowsPartial(v interface{}, q string, args ...interface{}) error {
return query(conn.db, func(rows *sql.Rows) error {
return unmarshalRows(v, rows, false)
}, q, args...)
}
// Transact is the implemention of sqlx.SqlConn, nothing to do
func (conn *MockConn) Transact(func(session sqlx.Session) error) error {
return nil
}