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

55 lines
1.2 KiB
Go

package migration
import (
"database/sql"
"errors"
"fmt"
)
type EditorResult struct {
WordpressId int
Username string
Email string
IsSuccess bool
}
func CreateEditorResult(result EditorResult, db *sql.DB) error {
_, err := db.Exec("insert into EditorsResults(WordpressId, Username, Email, IsSuccess) values (?, ?, ?, ?)", result.WordpressId, result.Username, result.Email, result.IsSuccess)
return err
}
func GetEditor(username, email string, db *sql.DB) (EditorResult, error) {
rows, err := db.Query("select WordpressId, Username, Email, (IsSuccess = b'1') from EditorsResults where Username = ? OR Email = ?", username, email)
if err != nil {
fmt.Println(err)
}
defer rows.Close()
for rows.Next() {
editor := EditorResult{}
err := rows.Scan(&editor.WordpressId, &editor.Username, &editor.Email, &editor.IsSuccess)
if err != nil {
fmt.Println(err)
}
if editor.Username == username || editor.Email == email {
return editor, nil
}
}
return EditorResult{}, errors.New("Could not find editor.")
}
func EditorHasBeenMigrated(username, email string, db *sql.DB) bool {
_, err := GetEditor(username, email, db)
if err == nil {
return true
} else {
return false
}
}