Add SQL query to count children by user: Introduced a new query to count distinct children associated with a user across all their characters. Updated UserCharacterWorker to utilize this new query, replacing the previous count query. This enhances user-specific data retrieval capabilities.

This commit is contained in:
Torsten Schulz (local)
2026-02-02 15:25:13 +01:00
parent 460310ae89
commit 658a9034ed
5 changed files with 35 additions and 264 deletions

View File

@@ -580,6 +580,14 @@ pub const QUERY_COUNT_CHILDREN: &str = r#"
SELECT COUNT(*) AS cnt FROM falukant_data.child_relation WHERE (father_character_id = $1 OR mother_character_id = $1) AND child_character_id != $2;
"#;
/// Zählt Kinder eines Users (über alle Charaktere des Users als Elternteil). Ein Parameter: user_id.
pub const QUERY_COUNT_CHILDREN_BY_USER: &str = r#"
SELECT COUNT(DISTINCT cr.child_character_id) AS cnt
FROM falukant_data.child_relation cr
JOIN falukant_data.character parent ON (parent.id = cr.father_character_id OR parent.id = cr.mother_character_id)
WHERE parent.user_id = $1;
"#;
// user_character worker queries
pub const QUERY_GET_USERS_TO_UPDATE: &str = r#"
SELECT id, CURRENT_DATE - birthdate::date AS age, health