1use rusqlite::Row;
8
9use crate::catalog::CatalogVersion;
10use crate::fromdb::FromDb;
11use crate::lrobject::{LrId, LrObject};
12
13#[derive(Clone)]
15pub struct Keyword {
16 id: LrId,
18 uuid: String,
20 pub name: String,
23 pub parent: LrId,
25}
26
27impl LrObject for Keyword {
28 fn id(&self) -> LrId {
29 self.id
30 }
31 fn uuid(&self) -> &str {
32 &self.uuid
33 }
34}
35
36impl FromDb for Keyword {
37 fn read_from(_version: CatalogVersion, row: &Row) -> crate::Result<Self> {
38 let name = row.get(3).ok();
39 let parent = row.get(4).ok();
40 Ok(Keyword {
41 id: row.get(0)?,
42 uuid: row.get(1)?,
43 name: name.unwrap_or_default(),
44 parent: parent.unwrap_or(0),
45 })
46 }
47
48 fn read_db_tables(_version: CatalogVersion) -> &'static str {
49 "AgLibraryKeyword"
50 }
51
52 fn read_db_columns(_version: CatalogVersion) -> &'static str {
53 "id_local,id_global,cast(dateCreated as text),name,parent"
54 }
55}
56
57impl Keyword {
58 pub fn new(id: LrId, parent: LrId, uuid: &str, name: &str) -> Keyword {
60 Keyword {
61 id,
62 parent,
63 uuid: String::from(uuid),
64 name: String::from(name),
65 }
66 }
67}