January 2019
Intermediate to advanced
520 pages
14h 32m
English
We will add a method that sets the is_public flag of a channel record to true. Look at the following implementation:
pub fn publish_channel(&self, channel_id: Id) -> Result<(), Error> { let channel = channels::table .filter(channels::id.eq(channel_id)) .select(( channels::id, channels::user_id, channels::title, channels::is_public, channels::created_at, channels::updated_at, )) .first::<Channel>(&self.conn) .optional() .map_err(Error::from)?; if let Some(channel) = channel { diesel::update(&channel) .set(channels::is_public.eq(true)) .execute(&self.conn)?; Ok(()) } else { Err(format_err!("channel not found")) }}
The function expects channel_id, and we use the table value to create a statement. We use the filter method of ...
Read now
Unlock full access