36 lines
1021 B
Go
36 lines
1021 B
Go
package migration
|
|
|
|
import "database/sql"
|
|
|
|
type PostResult struct {
|
|
WordpressId int
|
|
SlowtwitchId int
|
|
OldUrl string
|
|
OldUrlStatus int
|
|
NewUrl string
|
|
IsSuccess bool
|
|
ErrorMessage string
|
|
}
|
|
|
|
func CreatePostResult(parameters PostResult, db *sql.DB) (int, error) {
|
|
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)
|
|
if err != nil {
|
|
return 0, err
|
|
} else {
|
|
id, err := result.LastInsertId()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return int(id), nil
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|