commento/api/comment_get.go
2019-09-13 18:13:38 -07:00

43 lines
667 B
Go

package main
import ()
func commentGetByCommentHex(commentHex string) (comment, error) {
if commentHex == "" {
return comment{}, errorMissingField
}
statement := `
SELECT
commentHex,
commenterHex,
markdown,
html,
parentHex,
score,
state,
deleted,
creationDate
FROM comments
WHERE comments.commentHex = $1;
`
row := db.QueryRow(statement, commentHex)
c := comment{}
if err := row.Scan(
&c.CommentHex,
&c.CommenterHex,
&c.Markdown,
&c.Html,
&c.ParentHex,
&c.Score,
&c.State,
&c.Deleted,
&c.CreationDate); err != nil {
// TODO: is this the only error?
return c, errorNoSuchComment
}
return c, nil
}