I have a postgre DB and a little Go api.
The idea of the following func is to retrieve all the records in a json response. I just know the table name, I don't know the field names of the table.
Code:
func indexProductHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
setCors(w)
//var products []database.Products
var results []map[string]interface{}
database.DB.Raw("SELECT * from products").Scan(&results)
res, err := json.Marshal(results)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
w.Write(res)
}
This func will retrieve null values.
Is there a way to retrieve the records without passing the model?