Post-Migrator/services/migration/post-result.go

61 lines
1.6 KiB
Go
Raw Normal View History

2024-05-19 21:00:33 +00:00
package migration
2024-06-03 22:28:17 +00:00
import (
"database/sql"
"log"
)
2024-05-19 21:00:33 +00:00
type PostResult struct {
WordpressId int
SlowtwitchId int
OldUrl string
OldUrlStatus int
NewUrl string
IsSuccess bool
ErrorMessage string
}
2024-06-03 22:28:17 +00:00
func GetAllPostResults(db *sql.DB) []PostResult {
var results []PostResult
rows, err := db.Query("select WordpressId, SlowtwitchId, OldUrl, OldUrlStatus, NewUrl, (IsSuccess = b'1'), ErrorMessage from PostResults")
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
result := PostResult{}
err = rows.Scan(&result.WordpressId, &result.SlowtwitchId, &result.OldUrl, &result.OldUrlStatus, &result.NewUrl, &result.IsSuccess, &result.ErrorMessage)
if err != nil {
log.Fatal(err)
}
results = append(results, result)
}
return results
}
2024-05-19 21:00:33 +00:00
func CreatePostResult(parameters PostResult, db *sql.DB) (int, error) {
2024-05-20 01:35:53 +00:00
result, err := db.Exec("insert into PostResults (WordpressId, SlowtwitchId, OldUrl, OldUrlStatus, NewUrl, IsSuccess, ErrorMessage) values (?, ?, ?, ?, ?, ?, ?)", parameters.WordpressId, parameters.SlowtwitchId, parameters.OldUrl, parameters.OldUrlStatus, parameters.NewUrl, parameters.IsSuccess, parameters.ErrorMessage)
2024-05-19 21:00:33 +00:00
if err != nil {
return 0, err
} else {
id, err := result.LastInsertId()
if err != nil {
return 0, err
}
return int(id), nil
}
}
2024-05-21 21:15:43 +00:00
func GetWordpressPostIdBySlowtwitchPostId(slowtwitchPostId int, db *sql.DB) (int, error) {
var wordpressId int
post := db.QueryRow("select WordpressId from PostResults where SlowtwitchId = (?)", slowtwitchPostId)
err := post.Scan(&wordpressId)
return wordpressId, err
}