pub async fn add_user(new_user: &NewUser,
                      pool: &PgPool ) -> sqlx::Result<User> {
    // si on fait le hash dans le handler signup alors on enlève les deux lignes après
    //let password_hash = sha3::Sha3_256::digest(new_user.password.as_bytes());
    //let password_hash = format!("{:x}", password_hash);
    let uuid = Uuid::new_v4();

    let row = sqlx::query!(
            r#"
            INSERT INTO users (user_id, user_name, password_hash, role)
            VALUES ($1, $2, $3, $4)
            RETURNING user_id, user_name, password_hash, role
            "#,
            uuid,
            new_user.username.as_ref(),
            new_user.password,
            new_user.role,
        )
        .fetch_one(pool)
        .await?;

    let user = User{
        user_id: row.user_id,
        user_name: row.user_name,
        password_hash: row.password_hash,
        role: row.role.unwrap(),
    };
    Ok(user)
}
///
/// Adds a user to the users table
/// a hashed password must be set before entering the function
///

Adds a user to the users table
a hashed password must be set before entering the function
Adds a user to the users table a hashed password must be set before entering the function
pub async fn add_user(new_user: &NewUser,
                      pool: &PgPool ) -> sqlx::Result<User> {
    // si on fait le hash dans le handler signup alors on enlève les deux lignes après
    //let password_hash = sha3::Sha3_256::digest(new_user.password.as_bytes());
    //let password_hash = format!("{:x}", password_hash);
    let uuid = Uuid::new_v4();
    let row = sqlx::query!(
            r#"
            INSERT INTO users (user_id, user_name, password_hash, role)
            VALUES ($1, $2, $3, $4)
            RETURNING user_id, user_name, password_hash, role
            "#,
            uuid,
            new_user.username.as_ref(),
            new_user.password,
            new_user.role,
        )
        .fetch_one(pool)
        .await?;
    let user = User{
        user_id: row.user_id,
        user_name: row.user_name,
        password_hash: row.password_hash,
        role: row.role.unwrap(),
    };
    Ok(user)
}
pub async fn add_user ( new_user : & NewUser , pool : & PgPool ) -> sqlx :: Result < User > { // si on fait le hash dans le handler signup alors on enlève les deux lignes après
 //let password_hash = sha3::Sha3_256::digest(new_user.password.as_bytes());
 //let password_hash = format!("{:x}", password_hash);
 let uuid = Uuid :: new_v4 ( ) ; let row = sqlx :: query ! ( r#"
            INSERT INTO users (user_id, user_name, password_hash, role)
            VALUES ($1, $2, $3, $4)
            RETURNING user_id, user_name, password_hash, role
            "# uuid new_user username as_ref ( ) new_user password new_user role ) . fetch_one ( pool ) . await ? ; let user = User { user_id : row . user_id , user_name : row . user_name , password_hash : row . password_hash , role : row . role . unwrap ( ) , } ; Ok ( user ) }
Adds a user to the users table
a hashed password must be set before entering the function
Adds a user to the users table a hashed password must be set before entering the function
new_user
&NewUser
pool
&PgPool