func (d *database) GetComment(commentID gox.ID) (*Comment, error) { c := &Comment{} var content, atUserIDs []byte err := d.QueryRow("select "+commentFields+" from comments where id=?", commentID).Scan(&c.ID, &c.UserID, &c.ItemID, &c.ItemType, &c.ToCommentID, &content, &c.CreatedAt, &c.Status, &c.Floor, &atUserIDs, &c.Location, &c.Lat, &c.Lng) if err != nil { gox.LError(err) return nil, err } gox.JSONUnmarshal(content, &c.Content) gox.JSONUnmarshal(atUserIDs, &c.AtUserIDs) return c, nil }
func (d *database) GetLastComment(itemID gox.ID, itemType int) (*Comment, error) { c := &Comment{} var content, atUserIDs []byte err := d.QueryRow("select "+commentFields+" from comments where item_id=? and item_type=? order by id desc limit 1", itemID, itemType).Scan(&c.ID, &c.UserID, &c.ItemID, &c.ItemType, &c.ToCommentID, &content, &c.CreatedAt, &c.Status, &c.Floor, &atUserIDs, &c.Location, &c.Lat, &c.Lng) if err != nil { gox.LError("GetLastComment", err) return nil, err } gox.JSONUnmarshal(content, &c.Content) gox.JSONUnmarshal(atUserIDs, &c.AtUserIDs) return c, nil }
func (d *database) GetTopic(topicID gox.ID) (*Topic, error) { t := &Topic{} var content, atUserIDs, types, tags []byte err := d.QueryRow("select "+topicFields+" from topics where id=?", topicID).Scan(&t.ID, &t.UserID, &t.ChannelID, &content, &t.CreatedAt, &t.CommentedAt, &t.Status, &types, &tags, &atUserIDs, &t.Location, &t.Lat, &t.Lng) if err != nil { gox.LError(err) return nil, err } gox.JSONUnmarshal(content, &t.Content) gox.JSONUnmarshal(atUserIDs, &t.AtUserIDs) gox.JSONUnmarshal(types, &t.Types) gox.JSONUnmarshal(tags, &t.Tags) return t, nil }
func (d *database) parseComments(rows *sql.Rows) (CommentList, error) { defer rows.Close() comments := make(CommentList, 0, 30) for rows.Next() { c := &Comment{} var content, atUserIDs []byte err := rows.Scan(&c.ID, &c.UserID, &c.ItemID, &c.ItemType, &c.ToCommentID, &content, &c.CreatedAt, &c.Status, &c.Floor, &atUserIDs, &c.Location, &c.Lat, &c.Lng) if err != nil { gox.LError("parseComments", err) return comments[0:0], err } gox.JSONUnmarshal(content, &c.Content) gox.JSONUnmarshal(atUserIDs, &c.AtUserIDs) comments = append(comments, c) } return comments, nil }
func parseTopics(rows *sql.Rows) (TopicList, error) { defer rows.Close() topics := make(TopicList, 0, 50) for rows.Next() { t := &Topic{} var content, atUserIDs, types, tags []byte err := rows.Scan(&t.ID, &t.UserID, &t.ChannelID, &content, &t.CreatedAt, &t.CommentedAt, &t.Status, &types, &tags, &atUserIDs, &t.Location, &t.Lat, &t.Lng) if err != nil { gox.LError(err) return nil, err } gox.JSONUnmarshal(content, &t.Content) gox.JSONUnmarshal(atUserIDs, &t.AtUserIDs) gox.JSONUnmarshal(types, &t.Types) gox.JSONUnmarshal(tags, &t.Tags) topics = append(topics, t) } return topics, nil }
func (d *database) GetNotices(userID gox.ID, sinceID gox.ID, size int) (notices []*Notice, err error) { var rows *sql.Rows defer func() { if rows != nil { rows.Close() } if err != nil { notices = nil gox.LError(err) } }() notices = make([]*Notice, 0, size) if sinceID <= 0 { rows, err = d.Query("select "+noticeFields+" from notices where user_id=? order by id desc limit ?", userID, size) } else { rows, err = d.Query("select "+noticeFields+" from notices where user_id=? and id<? order by id desc limit ?", userID, sinceID, size) } if err != nil { return } var uid gox.ID for rows.Next() { n := &Notice{} var content []byte err = rows.Scan(&n.ID, &uid, &n.Type, &n.ContentID, &content, &n.Title, &n.TotalCount, &n.NewCount, &n.UpdatedAt) if err != nil { return } gox.JSONUnmarshal(content, &n.Content) notices = append(notices, n) } return }