pub async fn add_player(connection: &PgPool, player_name: &PlayerName) -> Result<Player, ()> {
    match query_player_by_name(connection, player_name).await {
        Some(_) => return Err(()),
        None => match sqlx::query("INSERT INTO players (id, player_name, games_played, games_won) VALUES (DEFAULT, $1, 0, 0);")
            .bind(&player_name.name())
            .execute(connection).await {
                Ok(_) => match query_player_by_name(connection, player_name).await {
                            Some(player) => Ok(player),
                            None => Err(()),
                },
                Err(_) => Err(()),
            },
    }
}
/// Adds a new player to the database.
/// Returns an error if the specified Player is already in the database
/// (if the name of the Player is already in use).
Adds a new player to the database.
Returns an error if the specified Player is already in the database
(if the name of the Player is already in use).
Adds a new player to the database . Returns an error if the specified Player is already in the database ( if the name of the Player is already in use ) .
pub async fn add_player(connection: &PgPool, player_name: &PlayerName) -> Result<Player, ()> {
    match query_player_by_name(connection, player_name).await {
        Some(_) => return Err(()),
        None => match sqlx::query("INSERT INTO players (id, player_name, games_played, games_won) VALUES (DEFAULT, $1, 0, 0);")
            .bind(&player_name.name())
            .execute(connection).await {
                Ok(_) => match query_player_by_name(connection, player_name).await {
                            Some(player) => Ok(player),
                            None => Err(()),
                },
                Err(_) => Err(()),
            },
    }
}
pub async fn add_player ( connection : & PgPool , player_name : & PlayerName ) -> Result < Player , ( ) > { match query_player_by_name ( connection , player_name ) . await { Some ( _ ) => return Err ( ( ) ) , None => match sqlx :: query ( " " ) . bind ( & player_name . name ( ) ) . execute ( connection ) . await { Ok ( _ ) => match query_player_by_name ( connection , player_name ) . await { Some ( player ) => Ok ( player ) , None => Err ( ( ) ) , } , Err ( _ ) => Err ( ( ) ) , } , } }
Adds a new player to the database.
Adds a new player to the database .
connection
&PgPool
player_name
&PlayerName
connection
&PgPool
player_name
&PlayerName