Post-Migrator/services/slowtwitch/get-related-post-ids.go

27 lines
571 B
Go
Raw Normal View History

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
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
}