I am storing some timestamps in the scyllaDB and when retrieving it is showing error that *“Cannot unmarshal timestamps into string” I am creating a todo API and when retrieving the todos from the DB it gives back the error: “Cannot unmarshal timestamps into *string”. The todo struct containing the createdAt and updatedAt fields are of type time.Time. Help me how to resolve this. Here is the todo struct type:
type Todo struct {
ID gocql.UUID `json:"id"`
UserID string `json:"user_id"`
Title string `json:"title"`
Description string `json:"description"`
Status string `json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Here is the function:
func GetAllTodos(user_id string) ([]*Todo, error) {
var todos []*Todo
query := `SELECT * FROM todo WHERE user_id = ? ALLOW FILTERING`
iter := Session.Query(query, user_id).Iter()
var todo Todo
for iter.Scan(&todo.ID, &todo.UserID, &todo.Title, &todo.Description, &todo.Status, &todo.CreatedAt, &todo.UpdatedAt) {
todos = append(todos, &todo)
todo = Todo{}
}
if err := iter.Close(); err != nil {
return nil, err
}
return todos, nil
}
Tried using different methods including creating separate variables for string or *string and parsing the timestamps using time.Parse or by directly passing it into the todo type struct or using time.Unix functions by taking the timestamps returned in nanoseconds and converting into milliseconds: time.Unix(timeStr/1000,0) Nothing have worked and the error continues to persist.