Post-Migrator/services/slowtwitch/get-post-base.go

47 lines
1.0 KiB
Go
Raw Normal View History

2024-05-17 18:49:55 +00:00
package slowtwitch
import (
"database/sql"
"federated.computer/wp-sync-slowtwitch/services/shared"
)
type SlowtwitchPostBase struct {
Id int
CategoryIds []int
Title string
Author string
Description string
DatePublished sql.NullTime
}
func GetPostBase(id int, db *sql.DB) (SlowtwitchPostBase, error) {
var output SlowtwitchPostBase
//Get Base
row := db.QueryRow("select ID, Title, LinkOwner, Add_Date, Description from glinks_Links where ID = ?", id)
err := row.Scan(&output.Id, &output.Title, &output.Author, &output.DatePublished, &output.Description)
if err != nil {
return output, err
}
//Get category Ids
var categoryIds []int
rows, err := db.Query("select CategoryID from glinks_CatLinks where LinkID = ?", id)
if err != nil {
return output, err
}
defer rows.Close()
for rows.Next() {
var id shared.Id
err := rows.Scan(&id.Id)
if err != nil {
return output, err
}
categoryIds = append(categoryIds, int(id.Id))
}
output.CategoryIds = categoryIds
return output, nil
}