refactors
This commit is contained in:
parent
8afbf55b99
commit
8fd0fd9c7b
12
helpers.go
12
helpers.go
|
@ -452,7 +452,7 @@ func row2mapStr(rows *core.Rows, fields []string) (resultsMap map[string]string,
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func txQuery2(tx *core.Tx, sqlStr string, params ...interface{}) (resultsSlice []map[string]string, err error) {
|
||||
func txQuery2(tx *core.Tx, sqlStr string, params ...interface{}) ([]map[string]string, error) {
|
||||
rows, err := tx.Query(sqlStr, params...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -462,13 +462,8 @@ func txQuery2(tx *core.Tx, sqlStr string, params ...interface{}) (resultsSlice [
|
|||
return rows2Strings(rows)
|
||||
}
|
||||
|
||||
func query2(db *core.DB, sqlStr string, params ...interface{}) (resultsSlice []map[string]string, err error) {
|
||||
s, err := db.Prepare(sqlStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer s.Close()
|
||||
rows, err := s.Query(params...)
|
||||
func query2(db *core.DB, sqlStr string, params ...interface{}) ([]map[string]string, error) {
|
||||
rows, err := db.Query(sqlStr, params...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -602,7 +597,6 @@ func indexName(tableName, idxName string) string {
|
|||
}
|
||||
|
||||
func getFlagForColumn(m map[string]bool, col *core.Column) (val bool, has bool) {
|
||||
|
||||
if len(m) == 0 {
|
||||
return false, false
|
||||
}
|
||||
|
|
|
@ -86,19 +86,13 @@ func (session *Session) QueryString(sqlStr string, args ...interface{}) ([]map[s
|
|||
if session.IsAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
return session.query2(sqlStr, args...)
|
||||
}
|
||||
|
||||
// =============================
|
||||
// for string
|
||||
// =============================
|
||||
func (session *Session) query2(sqlStr string, paramStr ...interface{}) (resultsSlice []map[string]string, err error) {
|
||||
session.queryPreprocess(&sqlStr, paramStr...)
|
||||
session.queryPreprocess(&sqlStr, args...)
|
||||
|
||||
if session.IsAutoCommit {
|
||||
return query2(session.DB(), sqlStr, paramStr...)
|
||||
return query2(session.DB(), sqlStr, args...)
|
||||
}
|
||||
return txQuery2(session.Tx, sqlStr, paramStr...)
|
||||
return txQuery2(session.Tx, sqlStr, args...)
|
||||
}
|
||||
|
||||
// Execute sql
|
||||
|
|
Loading…
Reference in New Issue