use rusqlite::Row;
use crate::catalog::CatalogVersion;
use crate::fromdb::FromDb;
use crate::lrobject::{LrId, LrObject};
#[derive(Clone)]
pub struct Keyword {
id: LrId,
uuid: String,
pub name: String,
pub parent: LrId,
}
impl LrObject for Keyword {
fn id(&self) -> LrId {
self.id
}
fn uuid(&self) -> &str {
&self.uuid
}
}
impl FromDb for Keyword {
fn read_from(_version: CatalogVersion, row: &Row) -> crate::Result<Self> {
let name = row.get(3).ok();
let parent = row.get(4).ok();
Ok(Keyword {
id: row.get(0)?,
uuid: row.get(1)?,
name: name.unwrap_or_default(),
parent: parent.unwrap_or(0),
})
}
fn read_db_tables(_version: CatalogVersion) -> &'static str {
"AgLibraryKeyword"
}
fn read_db_columns(_version: CatalogVersion) -> &'static str {
"id_local,id_global,cast(dateCreated as text),name,parent"
}
}
impl Keyword {
pub fn new(id: LrId, parent: LrId, uuid: &str, name: &str) -> Keyword {
Keyword {
id,
parent,
uuid: String::from(uuid),
name: String::from(name),
}
}
}