WIP2
This commit is contained in:
@@ -20,7 +20,7 @@ pub struct LibraryItemEntity {
|
|||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub r#type: i8,
|
pub r#type: i8,
|
||||||
pub parent_folder_id: Option<Uuid>
|
pub parent_folder_id: Option<Box<LibraryItemEntity>>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LibraryItemEntity {
|
impl LibraryItemEntity {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use std::sync::{Arc, Mutex, MutexGuard};
|
|||||||
use rusqlite::{Connection, Error, Row};
|
use rusqlite::{Connection, Error, Row};
|
||||||
use rusqlite::fallible_iterator::FallibleIterator;
|
use rusqlite::fallible_iterator::FallibleIterator;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use lumiere_domain::user::model::User;
|
|
||||||
use crate::video::model::LibraryItemEntity;
|
use crate::video::model::LibraryItemEntity;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@@ -126,13 +125,22 @@ impl LibraryItemSqliteRepository {
|
|||||||
Take example on the following query and adapt it.
|
Take example on the following query and adapt it.
|
||||||
*/
|
*/
|
||||||
let mut prepared_statement = database_connection.prepare(
|
let mut prepared_statement = database_connection.prepare(
|
||||||
"SELECT
|
"WITH RECURSIVE library_item_hierarchy AS (
|
||||||
id,
|
-- Base case: start with the requested item
|
||||||
name,
|
SELECT id, name, type, parent_folder_id
|
||||||
type,
|
FROM library_item
|
||||||
parent_item_id
|
WHERE id = ?1
|
||||||
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()])?;
|
let mut rows = prepared_statement.query([library_item_id.to_string()])?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user