January 2019
Intermediate to advanced
520 pages
14h 32m
English
The add_member function requires a channel ID and a user ID to add a membership record to the memberships table:
pub fn add_member(&self, channel_id: Id, user_id: Id) -> Result<Membership, Error>{ insert_into(memberships::table) .values(( memberships::channel_id.eq(channel_id), memberships::user_id.eq(user_id), )) .returning(( memberships::id, memberships::channel_id, memberships::user_id, )) .get_result(&self.conn) .map_err(Error::from)}
The implementation is simple and it uses the insert_into function call to prepare the INSERT statement to insert a new Membership value in the table. We also need a function to add new messages to a channel.
Read now
Unlock full access