gchdb 0.2.8

Provides a record abstraction for storing chat records extracted by different chat software, and provides full-text search feature
Documentation
use super::*;

#[derive(Queryable, Insertable, Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
#[table_name = "attachments"]
pub struct Attachment {
    pub id: Option<i32>,
    pub record_id: i32,
    pub name: String,
    pub hash: i64,
}

impl<'a> Attachment {
    pub fn new<R: Into<RecordType<'a>>>(hash: i64, name: String, record: R) -> Self {
        Self {
            id: None,
            record_id: match record.into() {
                RecordType::Id(id) => id,
                RecordType::Record(record) | RecordType::RecordWithAttaches { record, .. } => {
                    record.get_id()
                }
                RecordType::RecordRef(record) | RecordType::RecordRefWithAttaches { record, .. } => {
                    record.get_id()
                }
            },
            name,
            hash,
        }
    }

    pub fn get_id(&self) -> i32 {
        self.id.unwrap_or_default()
    }
}