use crate::types::Oid;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ColumnFormat {
#[default]
Text,
Binary,
HyperBinary,
}
impl ColumnFormat {
#[must_use]
pub fn from_code(code: i16) -> Self {
match code {
0 => ColumnFormat::Text,
1 => ColumnFormat::Binary,
2 => ColumnFormat::HyperBinary,
_ => ColumnFormat::Text, }
}
#[must_use]
pub fn to_code(self) -> i16 {
match self {
ColumnFormat::Text => 0,
ColumnFormat::Binary => 1,
ColumnFormat::HyperBinary => 2,
}
}
#[must_use]
pub fn is_binary(self) -> bool {
matches!(self, ColumnFormat::Binary | ColumnFormat::HyperBinary)
}
}
#[derive(Debug, Clone)]
pub struct Column {
pub(crate) name: String,
pub(crate) type_oid: Oid,
pub(crate) type_modifier: i32,
pub(crate) format: ColumnFormat,
}
impl Column {
#[inline]
pub(crate) fn new(
name: String,
type_oid: Oid,
type_modifier: i32,
format: ColumnFormat,
) -> Self {
Column {
name,
type_oid,
type_modifier,
format,
}
}
#[inline]
#[must_use]
pub fn name(&self) -> &str {
&self.name
}
#[inline]
#[must_use]
pub fn type_oid(&self) -> Oid {
self.type_oid
}
#[inline]
#[must_use]
pub fn type_modifier(&self) -> i32 {
self.type_modifier
}
#[inline]
#[must_use]
pub fn format(&self) -> ColumnFormat {
self.format
}
}