autofill/db/models/
address.rsuse super::Metadata;
use rusqlite::Row;
use sync_guid::Guid;
#[derive(Debug, Clone, Default)]
pub struct UpdatableAddressFields {
pub name: String,
pub organization: String,
pub street_address: String,
pub address_level3: String,
pub address_level2: String,
pub address_level1: String,
pub postal_code: String,
pub country: String,
pub tel: String,
pub email: String,
}
#[derive(Debug, Clone, Hash, PartialEq, Eq, Default)]
pub struct Address {
pub guid: String,
pub name: String,
pub organization: String,
pub street_address: String,
pub address_level3: String,
pub address_level2: String,
pub address_level1: String,
pub postal_code: String,
pub country: String,
pub tel: String,
pub email: String,
pub time_created: i64,
pub time_last_used: Option<i64>,
pub time_last_modified: i64,
pub times_used: i64,
}
impl From<InternalAddress> for Address {
fn from(ia: InternalAddress) -> Self {
Address {
guid: ia.guid.to_string(),
name: ia.name,
organization: ia.organization,
street_address: ia.street_address,
address_level3: ia.address_level3,
address_level2: ia.address_level2,
address_level1: ia.address_level1,
postal_code: ia.postal_code,
country: ia.country,
tel: ia.tel,
email: ia.email,
time_created: u64::from(ia.metadata.time_created) as i64,
time_last_used: if ia.metadata.time_last_used.0 == 0 {
None
} else {
Some(ia.metadata.time_last_used.0 as i64)
},
time_last_modified: u64::from(ia.metadata.time_last_modified) as i64,
times_used: ia.metadata.times_used,
}
}
}
#[derive(Default, Debug, Clone)]
pub struct InternalAddress {
pub guid: Guid,
pub name: String,
pub organization: String,
pub street_address: String,
pub address_level3: String,
pub address_level2: String,
pub address_level1: String,
pub postal_code: String,
pub country: String,
pub tel: String,
pub email: String,
pub metadata: Metadata,
}
impl InternalAddress {
pub fn from_row(row: &Row<'_>) -> Result<InternalAddress, rusqlite::Error> {
Ok(Self {
guid: row.get("guid")?,
name: row.get("name")?,
organization: row.get("organization")?,
street_address: row.get("street_address")?,
address_level3: row.get("address_level3")?,
address_level2: row.get("address_level2")?,
address_level1: row.get("address_level1")?,
postal_code: row.get("postal_code")?,
country: row.get("country")?,
tel: row.get("tel")?,
email: row.get("email")?,
metadata: Metadata {
time_created: row.get("time_created")?,
time_last_used: row.get("time_last_used")?,
time_last_modified: row.get("time_last_modified")?,
times_used: row.get("times_used")?,
sync_change_counter: row.get("sync_change_counter")?,
},
})
}
}