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 Swim bool Bike bool Run bool } func GetPostBase(id int, db *sql.DB) (SlowtwitchPostBase, error) { var output SlowtwitchPostBase //Get Base row := db.QueryRow("select ID, Title, LinkOwner, Add_Date, Description, (tag_swim = b'1'), (tag_bike = b'1'), (tag_run = b'1') from glinks_Links where ID = ?", id) err := row.Scan(&output.Id, &output.Title, &output.Author, &output.DatePublished, &output.Description, &output.Swim, &output.Bike, &output.Run) 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 }