use crate::generators::tetherscript::types::Kind;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Field {
pub column: String,
pub kind: Kind,
pub primary_key: bool,
pub generated: bool,
pub nullable: bool,
}
impl Field {
pub fn insertable(&self) -> bool {
!self.generated && !self.timestamp()
}
pub fn updatable(&self) -> bool {
!self.primary_key && !self.generated && !self.timestamp()
}
pub fn required(&self) -> bool {
!self.nullable && self.insertable()
}
fn timestamp(&self) -> bool {
matches!(self.column.as_str(), "created_at" | "updated_at")
}
}