27 lines
571 B
Go
27 lines
571 B
Go
package slowtwitch
|
|
|
|
import (
|
|
"database/sql"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func GetRelatedArticleIds(postId int, db *sql.DB) ([]int, error) {
|
|
var spaceSeparatedIds string
|
|
rows := db.QueryRow("SELECT RelatedArticles FROM slowtwitch.glinks_Links where ID = ?", postId)
|
|
err := rows.Scan(&spaceSeparatedIds)
|
|
if err != nil {
|
|
return make([]int, 0), err
|
|
}
|
|
|
|
var ids []int
|
|
idsAsStrings := strings.Split(spaceSeparatedIds, "\r\n")
|
|
for _, stringId := range idsAsStrings {
|
|
id, err := strconv.Atoi(stringId)
|
|
if err == nil {
|
|
ids = append(ids, id)
|
|
}
|
|
}
|
|
return ids, nil
|
|
}
|