MCPcopy
hub / github.com/daptin/daptin / RowsToMap

Function RowsToMap

server/resource/dbmethods.go:3444–3466  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
3444func 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

Calls 4

makeFunction · 0.85
NewMapStringScanFunction · 0.85
UpdateMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected