1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use crate::DatabaseError;

#[derive(Clone, Copy)]
pub struct Movie;

impl Movie {
    /// Method will return the number of mediafiles linked against this media object.
    pub async fn count_children(
        conn: &mut crate::Transaction<'_>,
        id: i64,
    ) -> Result<i64, DatabaseError> {
        Ok(sqlx::query!(
            "SELECT COUNT(*) AS count FROM mediafile WHERE media_id = ?",
            id
        )
        .fetch_one(&mut *conn)
        .await?
        .count as _)
    }
}