use crate::protocol::text::{ColumnDefinition, ColumnType};
use rbdc::ext::ustr::UStr;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct MySqlColumn {
pub ordinal: usize,
pub name: UStr,
pub type_info: MySqlTypeInfo,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct MySqlTypeInfo {
pub r#type: ColumnType,
pub char_set: u16,
}
impl MySqlTypeInfo {
fn is_null(&self) -> bool {
matches!(self.r#type, ColumnType::Null)
}
pub const fn binary(ty: ColumnType) -> Self {
Self {
r#type: ty,
char_set: 63,
}
}
#[doc(hidden)]
pub const fn null() -> Self {
Self {
r#type: ColumnType::Null,
char_set: 63,
}
}
#[doc(hidden)]
pub const fn __enum() -> Self {
Self {
r#type: ColumnType::Enum,
char_set: 63,
}
}
#[doc(hidden)]
pub fn __type_feature_gate(&self) -> Option<&'static str> {
match self.r#type {
ColumnType::Date | ColumnType::Time | ColumnType::Timestamp | ColumnType::Datetime => {
Some("time")
}
ColumnType::Json => Some("json"),
ColumnType::NewDecimal => Some("bigdecimal"),
_ => None,
}
}
pub(crate) fn from_column(column: &ColumnDefinition) -> Self {
Self {
r#type: column.r#type,
char_set: column.char_set,
}
}
pub(crate) fn from_type(ty: ColumnType) -> Self {
Self {
r#type: ty,
char_set: 63,
}
}
}