Add member

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.97.170