Commit c94e5ca4 authored by Adhityaa Chandrasekar's avatar Adhityaa Chandrasekar

comment_get.go: clean up SQL

parent a05d8eeb
......@@ -2,38 +2,46 @@ package main
import ()
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,
)
}
func commentGetByCommentHex(commentHex string) (comment, error) {
if commentHex == "" {
return comment{}, errorMissingField
}
statement := `
SELECT
commentHex,
commenterHex,
markdown,
html,
parentHex,
score,
state,
deleted,
creationDate
SELECT ` + commentsRowColumns + `
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 {
var c comment
if err := commentsRowScan(row, &c); err != nil {
// TODO: is this the only error?
return c, errorNoSuchComment
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment