lrcat/
libraryfiles.rs

1/*
2 This Source Code Form is subject to the terms of the Mozilla Public
3 License, v. 2.0. If a copy of the MPL was not distributed with this
4 file, You can obtain one at http://mozilla.org/MPL/2.0/.
5*/
6
7use rusqlite::Row;
8
9use crate::catalog::CatalogVersion;
10use crate::fromdb::FromDb;
11use crate::lrobject::{LrId, LrObject};
12
13/// Define a backing file in the `Catalog`. `Images` are
14/// connected to one.
15pub struct LibraryFile {
16    id: LrId,
17    uuid: String,
18    /// Basename (no extension) of the file
19    pub basename: String,
20    /// Extension of the file
21    pub extension: String,
22    /// `Folder` id containing file
23    pub folder: LrId,
24    /// Extensions of the sidecar(s), comma separated.
25    pub sidecar_extensions: String,
26}
27
28impl LrObject for LibraryFile {
29    fn id(&self) -> LrId {
30        self.id
31    }
32    fn uuid(&self) -> &str {
33        &self.uuid
34    }
35}
36
37impl FromDb for LibraryFile {
38    fn read_from(_version: CatalogVersion, row: &Row) -> crate::Result<Self> {
39        Ok(LibraryFile {
40            id: row.get(0)?,
41            uuid: row.get(1)?,
42            basename: row.get(2)?,
43            extension: row.get(3)?,
44            folder: row.get(4)?,
45            sidecar_extensions: row.get(5)?,
46        })
47    }
48    fn read_db_tables(_version: CatalogVersion) -> &'static str {
49        "AgLibraryFile"
50    }
51    fn read_db_columns(_version: CatalogVersion) -> &'static str {
52        "id_local,id_global,baseName,extension,folder,sidecarExtensions"
53    }
54}
55
56impl LibraryFile {}