package migration import ( "database/sql" "errors" "fmt" ) type CategoryResult struct { WordpressId int SlowtwitchId int OldUrl string OldUrlStatus int NewUrl string IsSuccess bool ErrorMessage string } func CreateCategoryResult(result CategoryResult, db *sql.DB) error { _, err := db.Exec("insert into CategoryResults (SlowtwitchId, WordpressId, OldUrl, NewUrl, IsSuccess, ErrorMessage, OldUrlStatus) values (?, ?, ?, ?, ?, ?, ?);", result.SlowtwitchId, result.WordpressId, result.OldUrl, result.NewUrl, result.IsSuccess, result.ErrorMessage) return err } func GetSlowtwitchCategoryResult(slowtwitchId int, db *sql.DB) (CategoryResult, error) { rows, err := db.Query("select WordpressId, SlowtwitchId, OldUrl, NewUrl, (IsSuccess = b'1'), ErrorMessage, OldUrlStatus from CategoryResults where SlowtwitchId = ?", slowtwitchId) if err != nil { fmt.Println(err) } defer rows.Close() for rows.Next() { var slowtwitchCategoryResult CategoryResult err = rows.Scan(&slowtwitchCategoryResult.WordpressId, &slowtwitchCategoryResult.SlowtwitchId, &slowtwitchCategoryResult.OldUrl, &slowtwitchCategoryResult.NewUrl, &slowtwitchCategoryResult.IsSuccess, &slowtwitchCategoryResult.ErrorMessage, &slowtwitchCategoryResult.OldUrlStatus) if err != nil { fmt.Println(err) } if slowtwitchCategoryResult.SlowtwitchId == slowtwitchId { return slowtwitchCategoryResult, nil } } return CategoryResult{}, errors.New("Category Not Found") }