RowsToMap converts the result of db.QueryRowx => rows to array of data can be used on any *sqlx.Rows and assign a typeName
(rows *sqlx.Rows, typeName string)
| 3442 | // RowsToMap converts the result of db.QueryRowx => rows to array of data |
| 3443 | // can be used on any *sqlx.Rows and assign a typeName |
| 3444 | func RowsToMap(rows *sqlx.Rows, typeName string) ([]map[string]interface{}, error) { |
| 3445 | |
| 3446 | columns, err := rows.Columns() |
| 3447 | if err != nil { |
| 3448 | return nil, err |
| 3449 | } |
| 3450 | responseArray := make([]map[string]interface{}, 0) |
| 3451 | |
| 3452 | for rows.Next() { |
| 3453 | |
| 3454 | rc := NewMapStringScan(columns) |
| 3455 | err := rc.Update(rows) |
| 3456 | if err != nil { |
| 3457 | return responseArray, err |
| 3458 | } |
| 3459 | |
| 3460 | dbRow := rc.Get() |
| 3461 | dbRow["__type"] = typeName |
| 3462 | responseArray = append(responseArray, dbRow) |
| 3463 | } |
| 3464 | |
| 3465 | return responseArray, nil |
| 3466 | } |
| 3467 | |
| 3468 | // ResultToArrayOfMap converts the result of db.QueryRowx => rows to array of data |
| 3469 | // fetches the related objects also |
no test coverage detected