func (r *SqlRepo) GetItemById(id int64) (*Item, error) { var title, img_url, source, link string st := "SELECT * FROM items WHERE id = ?" err := r.h.Conn().QueryRow(st, id).Scan(&id, &img_url, &title, &source, &link) if err != nil { return &Item{}, err } else { return &Item{Id: id, Title: title, Source: source, Url: img_url, Link: link, Tid: utils.Hash(img_url)}, nil } }
func (r *SqlRepo) GetBestComments() ([]*Item, error) { st := "SELECT comments.*, items.imgurl, items.title, items.source, items.link from comments " + "INNER JOIN items ON comments.item=items.id ORDER BY likes DESC LIMIT 100" rows, err := r.h.Conn().Query(st) defer rows.Close() items := make([]*Item, 0) for rows.Next() { var item_id, comment_id int64 var likes int var date time.Time var text, author, url, title, source, link string err = rows.Scan(&comment_id, &item_id, &date, &text, &author, &likes, &url, &title, &source, &link) if err != nil { return nil, err } item := &Item{Id: item_id, Url: url, Title: title, Source: source, Link: link, Tid: utils.Hash(url)} comment := &Comment{Id: comment_id, Text: text, Author: author, Likes: likes} item.BestComment = comment items = append(items, item) } err = rows.Err() if err != nil { return nil, err } return items, nil }