comment_get.go: clean up SQL
This commit is contained in:
parent
a05d8eeb07
commit
c94e5ca41f
@ -2,29 +2,20 @@ package main
|
|||||||
|
|
||||||
import ()
|
import ()
|
||||||
|
|
||||||
func commentGetByCommentHex(commentHex string) (comment, error) {
|
var commentsRowColumns = `
|
||||||
if commentHex == "" {
|
comments.commentHex,
|
||||||
return comment{}, errorMissingField
|
comments.commenterHex,
|
||||||
}
|
comments.markdown,
|
||||||
|
comments.html,
|
||||||
statement := `
|
comments.parentHex,
|
||||||
SELECT
|
comments.score,
|
||||||
commentHex,
|
comments.state,
|
||||||
commenterHex,
|
comments.deleted,
|
||||||
markdown,
|
comments.creationDate
|
||||||
html,
|
|
||||||
parentHex,
|
|
||||||
score,
|
|
||||||
state,
|
|
||||||
deleted,
|
|
||||||
creationDate
|
|
||||||
FROM comments
|
|
||||||
WHERE comments.commentHex = $1;
|
|
||||||
`
|
`
|
||||||
row := db.QueryRow(statement, commentHex)
|
|
||||||
|
|
||||||
c := comment{}
|
func commentsRowScan(s sqlScanner, c *comment) error {
|
||||||
if err := row.Scan(
|
return s.Scan(
|
||||||
&c.CommentHex,
|
&c.CommentHex,
|
||||||
&c.CommenterHex,
|
&c.CommenterHex,
|
||||||
&c.Markdown,
|
&c.Markdown,
|
||||||
@ -33,7 +24,24 @@ func commentGetByCommentHex(commentHex string) (comment, error) {
|
|||||||
&c.Score,
|
&c.Score,
|
||||||
&c.State,
|
&c.State,
|
||||||
&c.Deleted,
|
&c.Deleted,
|
||||||
&c.CreationDate); err != nil {
|
&c.CreationDate,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func commentGetByCommentHex(commentHex string) (comment, error) {
|
||||||
|
if commentHex == "" {
|
||||||
|
return comment{}, errorMissingField
|
||||||
|
}
|
||||||
|
|
||||||
|
statement := `
|
||||||
|
SELECT ` + commentsRowColumns + `
|
||||||
|
FROM comments
|
||||||
|
WHERE comments.commentHex = $1;
|
||||||
|
`
|
||||||
|
row := db.QueryRow(statement, commentHex)
|
||||||
|
|
||||||
|
var c comment
|
||||||
|
if err := commentsRowScan(row, &c); err != nil {
|
||||||
// TODO: is this the only error?
|
// TODO: is this the only error?
|
||||||
return c, errorNoSuchComment
|
return c, errorNoSuchComment
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user