2024-05-21 21:15:43 +00:00
|
|
|
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
|
2024-05-25 02:03:56 +00:00
|
|
|
idsAsStrings := strings.Split(spaceSeparatedIds, "\r\n")
|
2024-05-21 21:15:43 +00:00
|
|
|
for _, stringId := range idsAsStrings {
|
|
|
|
id, err := strconv.Atoi(stringId)
|
|
|
|
if err == nil {
|
|
|
|
ids = append(ids, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ids, nil
|
|
|
|
}
|