chore: Refactor FetchDiscordIdByUsername and FetchGoogleIdByUsername to handle null values

This commit is contained in:
Frederico Santos 2024-07-10 20:32:16 +01:00
parent 214f7e6238
commit b184e754ce

View File

@ -89,23 +89,31 @@ func FetchUsernameByGoogleId(googleId string) (string, error) {
} }
func FetchDiscordIdByUsername(username string) (string, error) { func FetchDiscordIdByUsername(username string) (string, error) {
var discordId string var discordId sql.NullString
err := handle.QueryRow("SELECT discordId FROM accounts WHERE username = ?", username).Scan(&discordId) err := handle.QueryRow("SELECT discordId FROM accounts WHERE username = ?", username).Scan(&discordId)
if err != nil { if err != nil {
return "", err return "", err
} }
return discordId, nil if !discordId.Valid {
return "", nil
}
return discordId.String, nil
} }
func FetchGoogleIdByUsername(username string) (string, error) { func FetchGoogleIdByUsername(username string) (string, error) {
var googleId string var googleId sql.NullString
err := handle.QueryRow("SELECT googleId FROM accounts WHERE username = ?", username).Scan(&googleId) err := handle.QueryRow("SELECT googleId FROM accounts WHERE username = ?", username).Scan(&googleId)
if err != nil { if err != nil {
return "", err return "", err
} }
return googleId, nil if !googleId.Valid {
return "", nil
}
return googleId.String, nil
} }
func FetchUsernameBySessionToken(token []byte) (string, error) { func FetchUsernameBySessionToken(token []byte) (string, error) {