Skip to content

How can I check whether a query result returned something? #973

@arjendevos

Description

@arjendevos
	var socialAccount social.SocialAccount
	err := app.Database().Get(&socialAccount, `SELECT * FROM social_account WHERE username=$1 AND platform=$2 AND deleted_at IS NULL`, request.Validated.Username, request.Validated.Platform)
	if err != nil && !errors.Is(err, sql.ErrNoRows) {
		return response.Error(err, response.WithMessage("Failed to check existing social account"))
	}

It's not possible to make socialAccount *social.SocialAccount as sqlx doesn't accept that. But now the struct is always initialized even when there are no results. I need to check whether the social account exists, but there is no way to do this?

if socialAccount != nil {
}

Now I have to do something like:

if socialAccount.ID != "" {

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions