55 lines
1.1 KiB
Go
55 lines
1.1 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 string, db *sql.DB) (EditorResult, error) {
|
||
|
rows, err := db.Query("select WordpressId, Username, Email, (IsSuccess = b'1') from EditorsResults where Username = ?", username)
|
||
|
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 {
|
||
|
return editor, nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return EditorResult{}, errors.New("Could not find editor.")
|
||
|
}
|
||
|
|
||
|
func EditorHasBeenMigrated(username string, db *sql.DB) bool {
|
||
|
_, err := GetEditor(username, db)
|
||
|
|
||
|
if err == nil {
|
||
|
return true
|
||
|
} else {
|
||
|
return false
|
||
|
}
|
||
|
}
|