refactor
This commit is contained in:
parent
47c5c70a0f
commit
694d32e3e3
26
scan.go
26
scan.go
|
@ -12,7 +12,7 @@ import (
|
|||
"xorm.io/xorm/dialects"
|
||||
)
|
||||
|
||||
func (engine *Engine) row2mapStr(rows *core.Rows, types []*sql.ColumnType, fields []string) (map[string]string, error) {
|
||||
func row2mapStr(rows *core.Rows, types []*sql.ColumnType, fields []string) (map[string]string, error) {
|
||||
var scanResults = make([]interface{}, len(fields))
|
||||
for i := 0; i < len(fields); i++ {
|
||||
var s sql.NullString
|
||||
|
@ -31,7 +31,7 @@ func (engine *Engine) row2mapStr(rows *core.Rows, types []*sql.ColumnType, field
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func (engine *Engine) row2mapBytes(rows *core.Rows, types []*sql.ColumnType, fields []string) (map[string][]byte, error) {
|
||||
func row2mapBytes(rows *core.Rows, types []*sql.ColumnType, fields []string) (map[string][]byte, error) {
|
||||
var scanResults = make([]interface{}, len(fields))
|
||||
for i := 0; i < len(fields); i++ {
|
||||
var s sql.NullString
|
||||
|
@ -50,7 +50,7 @@ func (engine *Engine) row2mapBytes(rows *core.Rows, types []*sql.ColumnType, fie
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func (engine *Engine) row2sliceStr(rows *core.Rows, types []*sql.ColumnType, fields []string) ([]string, error) {
|
||||
func row2sliceStr(rows *core.Rows, types []*sql.ColumnType, fields []string) ([]string, error) {
|
||||
results := make([]string, 0, len(fields))
|
||||
var scanResults = make([]interface{}, len(fields))
|
||||
for i := 0; i < len(fields); i++ {
|
||||
|
@ -68,6 +68,26 @@ func (engine *Engine) row2sliceStr(rows *core.Rows, types []*sql.ColumnType, fie
|
|||
return results, nil
|
||||
}
|
||||
|
||||
func rows2maps(rows *core.Rows) (resultsSlice []map[string][]byte, err error) {
|
||||
fields, err := rows.Columns()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
types, err := rows.ColumnTypes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for rows.Next() {
|
||||
result, err := row2mapBytes(rows, types, fields)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resultsSlice = append(resultsSlice, result)
|
||||
}
|
||||
|
||||
return resultsSlice, nil
|
||||
}
|
||||
|
||||
func (engine *Engine) row2mapInterface(rows *core.Rows, types []*sql.ColumnType, fields []string) (map[string]interface{}, error) {
|
||||
var resultsMap = make(map[string]interface{}, len(fields))
|
||||
var scanResultContainers = make([]interface{}, len(fields))
|
||||
|
|
|
@ -33,7 +33,7 @@ func (session *Session) rows2Strings(rows *core.Rows) (resultsSlice []map[string
|
|||
}
|
||||
|
||||
for rows.Next() {
|
||||
result, err := session.engine.row2mapStr(rows, types, fields)
|
||||
result, err := row2mapStr(rows, types, fields)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ func (session *Session) rows2SliceString(rows *core.Rows) (resultsSlice [][]stri
|
|||
}
|
||||
|
||||
for rows.Next() {
|
||||
record, err := session.engine.row2sliceStr(rows, types, fields)
|
||||
record, err := row2sliceStr(rows, types, fields)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -130,26 +130,6 @@ func value2Bytes(rawValue *reflect.Value) ([]byte, error) {
|
|||
return []byte(str), nil
|
||||
}
|
||||
|
||||
func (session *Session) rows2maps(rows *core.Rows) (resultsSlice []map[string][]byte, err error) {
|
||||
fields, err := rows.Columns()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
types, err := rows.ColumnTypes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for rows.Next() {
|
||||
result, err := session.engine.row2mapBytes(rows, types, fields)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resultsSlice = append(resultsSlice, result)
|
||||
}
|
||||
|
||||
return resultsSlice, nil
|
||||
}
|
||||
|
||||
func (session *Session) queryBytes(sqlStr string, args ...interface{}) ([]map[string][]byte, error) {
|
||||
rows, err := session.queryRows(sqlStr, args...)
|
||||
if err != nil {
|
||||
|
@ -157,7 +137,7 @@ func (session *Session) queryBytes(sqlStr string, args ...interface{}) ([]map[st
|
|||
}
|
||||
defer rows.Close()
|
||||
|
||||
return session.rows2maps(rows)
|
||||
return rows2maps(rows)
|
||||
}
|
||||
|
||||
func (session *Session) exec(sqlStr string, args ...interface{}) (sql.Result, error) {
|
||||
|
|
Loading…
Reference in New Issue