WIP3
This commit is contained in:
@@ -4,6 +4,13 @@ use rusqlite::fallible_iterator::FallibleIterator;
|
||||
use uuid::Uuid;
|
||||
use crate::video::model::LibraryItemEntity;
|
||||
|
||||
struct LibraryItemRawEntity {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub r#type: i8,
|
||||
pub parent_item_id: Option<Uuid>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct LibraryItemSqliteRepository {
|
||||
pub database_connection: Arc<Mutex<Connection>>,
|
||||
@@ -144,10 +151,24 @@ impl LibraryItemSqliteRepository {
|
||||
)?;
|
||||
let mut rows = prepared_statement.query([library_item_id.to_string()])?;
|
||||
|
||||
if let Some(row) = rows.next()? {
|
||||
Ok(Some(Self::map_to_library_item(&row)?))
|
||||
} else {
|
||||
let raw_data = rows.map(Self::map_to_raw_entity).collect::<Vec<LibraryItemRawEntity>>()?;
|
||||
|
||||
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn map_to_raw_entity(row: &Row) -> Result<LibraryItemRawEntity, Error> {
|
||||
let id_text: String = row.get(0)?;
|
||||
let type_as_number: i8 = row.get(2)?;
|
||||
let parent_item_id_text: Option<String> = row.get(3)?;
|
||||
|
||||
let raw_entity = LibraryItemRawEntity {
|
||||
id: Uuid::parse_str(&id_text).unwrap(),
|
||||
name: row.get(1)?,
|
||||
r#type: type_as_number,
|
||||
parent_item_id: parent_item_id_text.map(|id| Uuid::parse_str(id.as_str()).unwrap())
|
||||
};
|
||||
Ok(raw_entity)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user