commento/api/comment_get.go

51 lines
878 B
Go
Raw Permalink Normal View History

2019-05-16 00:13:39 +08:00
package main
2019-05-16 02:46:11 +08:00
import ()
2019-05-16 00:13:39 +08:00
2019-12-28 09:00:14 +08:00
var commentsRowColumns = `
comments.commentHex,
comments.commenterHex,
comments.markdown,
comments.html,
comments.parentHex,
comments.score,
comments.state,
comments.deleted,
comments.creationDate
`
func commentsRowScan(s sqlScanner, c *comment) error {
return s.Scan(
&c.CommentHex,
&c.CommenterHex,
&c.Markdown,
&c.Html,
&c.ParentHex,
&c.Score,
&c.State,
&c.Deleted,
&c.CreationDate,
)
}
2019-05-16 00:13:39 +08:00
func commentGetByCommentHex(commentHex string) (comment, error) {
if commentHex == "" {
return comment{}, errorMissingField
}
statement := `
2019-12-28 09:00:14 +08:00
SELECT ` + commentsRowColumns + `
2019-05-16 00:13:39 +08:00
FROM comments
WHERE comments.commentHex = $1;
`
row := db.QueryRow(statement, commentHex)
2019-12-28 09:00:14 +08:00
var c comment
if err := commentsRowScan(row, &c); err != nil {
2019-05-16 00:13:39 +08:00
// TODO: is this the only error?
return c, errorNoSuchComment
}
return c, nil
}