proof_of_sql/base/database/
table_ref.rsuse alloc::string::ToString;
use core::{
fmt,
fmt::{Display, Formatter},
str::FromStr,
};
use proof_of_sql_parser::{impl_serde_from_str, Identifier, ResourceId};
#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)]
pub struct TableRef {
resource_id: ResourceId,
}
impl TableRef {
pub fn new(resource_id: ResourceId) -> Self {
Self { resource_id }
}
pub fn schema_id(&self) -> Identifier {
self.resource_id.schema()
}
pub fn table_id(&self) -> Identifier {
self.resource_id.object_name()
}
pub fn resource_id(&self) -> ResourceId {
self.resource_id
}
}
impl FromStr for TableRef {
type Err = proof_of_sql_parser::ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self::new(s.parse()?))
}
}
impl Display for TableRef {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
self.resource_id.fmt(f)
}
}
impl_serde_from_str!(TableRef);