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 handler:
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
var createdAtTime, updatedAtTime time.Time
for iter.Scan(&todo.ID, &todo.UserID, &todo.Title, &todo.Description, &todo.Status, &ctodo.CreatedAt,&todo.UpdatedAt) {
todos = append(todos, &todo)
todo = Todo{}
}
if err := iter.Close(); err != nil {
return nil, err
}
return todos, nil
}