1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use crate::DatabaseError;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, PartialEq, Debug)]
pub struct TVShow {
pub id: i64,
}
impl TVShow {
pub async fn count_children(
tx: &mut crate::Transaction<'_>,
id: i64,
) -> Result<i64, DatabaseError> {
#[derive(sqlx::FromRow)]
struct Row {
count: i64,
}
Ok(sqlx::query_as::<_, Row>(
r#"SELECT COUNT(_tblseason.id) as count FROM _tblmedia
INNER JOIN _tblseason on _tblseason.tvshowid = _tblmedia.id
WHERE _tblmedia.id = ?"#,
)
.bind(id)
.fetch_one(&mut *tx)
.await?
.count)
}
}