January 2019
Intermediate to advanced
520 pages
14h 32m
English
The first subcommand of our users management tool is add. This command extracts the NAME and EMAIL of the user from the arguments and generates a new user identifier using the uuid crate. We will use this type across all our microservices. Look at the following code:
(CMD_ADD, Some(matches)) => { let conn = pool.get()?; let name = matches.value_of("NAME").unwrap(); let email = matches.value_of("EMAIL").unwrap(); let uuid = format!("{}", uuid::Uuid::new_v4()); let new_user = models::NewUser { id: &uuid, name: &name, email: &email, }; diesel::insert_into(schema::users::table) .values(&new_user) .execute(&conn)?;}
After we have extracted all the parameters, we create a NewUser instance from the models ...
Read now
Unlock full access