Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

converting NULL to string is unsupported #1134

Open
vizvasrj opened this issue Aug 1, 2023 · 0 comments
Open

converting NULL to string is unsupported #1134

vizvasrj opened this issue Aug 1, 2023 · 0 comments

Comments

@vizvasrj
Copy link

vizvasrj commented Aug 1, 2023

how to convert null to string .?

here token is null and I want it to convert it to""empty string

func find_a_user_with_username(db *sql.DB, username string) (models.Users, error) {
	if username == "" {
		return models.Users{}, myerror.New("invalid username is none")
	}

	var user models.Users

	err := db.QueryRow(`
	SELECT id, username, password_hash, 
		email, token, refresh_token, 
		created_at, updated_at
	FROM users WHERE username = $1
	`, username).Scan(
		&user.Id, &user.Username, &user.PasswordHash,
		&user.Email, &user.Token, &user.RefreshToken,
		&user.CreatedAt, &user.UpdatedAt,
	)
	if err != nil {
		if err == sql.ErrNoRows {
			return user, myerror.New("No matching rows found.")
		} else {
			return user, myerror.WrapError(err, "Error retriving row")
		}
	}
	return user, nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant