When I try to parse the data into a struct and then append it to the slice, I get nothing. But if I use the query in MySQL Workbench, I get some values...
query, err := db.Query("SELECT 'description','is_done' FROM tasks WHERE 'user_id' = ?;", userId) if err != nil { return nil, err } defer query.Close() var tasks[]TodoUserDTO var currentTask TodoUserDTO for query.Next() { err = query.Scan(¤tTask.Description, ¤tTask.IsDone) if err != nil { panic(err) } tasks = append(tasks, currentTask) }
The TodoDTO structure is as follows:
type TodoUserDTO struct { Description string `json:"desc"` IsDone bool `json:"done"` }
Based on the code, it appears that you are using the wrong column name in the SELECT statement of your query. The SELECT statement should contain the actual column names of the columns in the task table, not literal strings of column names.
Try changing the SELECT statement to:
"Select description, is_done FROM task WHERE user_id = ?"