From 35ef389bb8619c8fa9a1ada74ab4381f2e91c5e4 Mon Sep 17 00:00:00 2001 From: Florian THIERRY Date: Sun, 19 Jul 2026 21:14:15 +0200 Subject: [PATCH] WIP2 --- backend/infrastructure/src/video/model.rs | 2 +- .../infrastructure/src/video/repository.rs | 24 ++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/backend/infrastructure/src/video/model.rs b/backend/infrastructure/src/video/model.rs index 80b1646..560d1c0 100644 --- a/backend/infrastructure/src/video/model.rs +++ b/backend/infrastructure/src/video/model.rs @@ -20,7 +20,7 @@ pub struct LibraryItemEntity { pub id: Uuid, pub name: String, pub r#type: i8, - pub parent_folder_id: Option + pub parent_folder_id: Option> } impl LibraryItemEntity { diff --git a/backend/infrastructure/src/video/repository.rs b/backend/infrastructure/src/video/repository.rs index 1bc6af7..9ba3529 100644 --- a/backend/infrastructure/src/video/repository.rs +++ b/backend/infrastructure/src/video/repository.rs @@ -2,7 +2,6 @@ use std::sync::{Arc, Mutex, MutexGuard}; use rusqlite::{Connection, Error, Row}; use rusqlite::fallible_iterator::FallibleIterator; use uuid::Uuid; -use lumiere_domain::user::model::User; use crate::video::model::LibraryItemEntity; #[derive(Clone)] @@ -126,13 +125,22 @@ impl LibraryItemSqliteRepository { Take example on the following query and adapt it. */ let mut prepared_statement = database_connection.prepare( - "SELECT - id, - name, - type, - parent_item_id - FROM library_item - WHERE id = ?1;" + "WITH RECURSIVE library_item_hierarchy AS ( + -- Base case: start with the requested item + SELECT id, name, type, parent_folder_id + FROM library_item + WHERE id = ?1 + + UNION ALL + + -- Recursive case: get all ancestors + SELECT li.id, li.name, li.type, li.parent_folder_id + FROM library_item li + INNER JOIN library_item_hierarchy lh ON li.id = lh.parent_folder_id + ) + SELECT id, name, type, parent_folder_id + FROM library_item_hierarchy + ORDER BY id;" )?; let mut rows = prepared_statement.query([library_item_id.to_string()])?;