use crate::generators::rust::types::Mapping;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Field {
pub column: String,
pub ident: String,
pub rename: Option<String>,
pub mapping: Mapping,
pub primary_key: bool,
pub generated: bool,
pub nullable: bool,
}
impl Field {
pub fn key_type(&self) -> &str {
self.mapping
.rust
.strip_prefix("Option<")
.and_then(|rest| rest.strip_suffix('>'))
.unwrap_or(&self.mapping.rust)
}
pub fn insertable(&self) -> bool {
!self.generated && !self.timestamp()
}
pub fn updatable(&self) -> bool {
!self.primary_key && !self.generated && !self.timestamp()
}
fn timestamp(&self) -> bool {
matches!(self.column.as_str(), "created_at" | "updated_at")
}
}