use super::DataManager; use oiseau::{params, query_row}; use tetratto_core::model::{Error, Result}; impl DataManager { /// Get the number of notifications a user has for the given tag. pub async fn get_notifications_count_by_tag(&self, user: usize, tag: &str) -> Result { let conn = match self.0.connect().await { Ok(c) => c, Err(e) => return Err(Error::DatabaseConnection(e.to_string())), }; let res = query_row!( &conn, "SELECT COUNT(*)::int FROM notifications WHERE owner = $1 AND tag = $2", params![&(user as i64), &tag], |x| { Ok(x.get::(0)) } ); if let Err(e) = res { return Err(Error::DatabaseError(e.to_string())); } Ok(res.unwrap() as usize) } }