golang []map[string]interface{} sqlx BUT
Golang often us []interface{} or map[string]interface{}
sqlx.Queryx Alternate Scan Types
rows, err := db.Queryx(“SELECT * FROM place”)
for rows.Next() {
// cols is an []interface{} of all of the column results
cols, err := rows.SliceScan()
}
rows, err := db.Queryx(“SELECT * FROM place”)
for rows.Next() {
results := make(map[string]interface{})
err = rows.MapScan(results)
}
So
func Sqlselectall(db1 *sqlx.DB, table string) []map[string]interface{} {
rows, err := db1.Queryx(“SELECT * FROM " + table)
if err != nil { }
results := []map[string]interface{}{}
for rows.Next() {
result := make(map[string]interface{})
err = rows.MapScan(result)
results = append(results, result)
}
return results
}
BUT results to json use c.JSON(http.StatusOK, results) get warning value