January 2019
Intermediate to advanced
520 pages
14h 32m
English
To register a new user with an email address, add the following method:
pub fn register_user(&self, email: &str) -> Result<User, Error> { insert_into(users::table) .values(( users::email.eq(email), )) .returning(( users::id, users::email )) .get_result(&self.conn) .map_err(Error::from)}
The register_user function expects a string with the email of a user, adds a record to a database, and returns a User instance, which represents a record in the users table.
We use the insert_into method with a table type from the users scope, which is automatically created by the table! macro in the schema module. This method returns an IncompleteInsertStatement instance that provides a values method to set values with an INSERT statement. We ...
Read now
Unlock full access