Function get_user_by_id

Source
pub async fn get_user_by_id(pool: &Pool<MySql>, id: i64) -> Result<User>
Expand description

Retrieves a specific user by their unique identifier.

This function fetches detailed information about a single user record. It’s typically used when specific user details are needed, such as for displaying user profiles or performing user-specific operations.

§Arguments

  • pool - Database connection pool for executing the query
  • id - Unique identifier of the user to retrieve

§Returns

  • Ok(User) - Successfully retrieved user information
  • Err(anyhow::Error) - Failed to fetch user (including if not found)

§Error Handling

Returns an error if no user with the given ID exists or if a database error occurs during the query execution.