rbdc_mysql/
result_set.rs

1use crate::protocol::text::{ColumnDefinition, ColumnType};
2use rbdc::ext::ustr::UStr;
3
4#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
5pub struct MySqlColumn {
6    pub ordinal: usize,
7    pub name: UStr,
8    pub type_info: MySqlTypeInfo,
9    // #[serde(skip)]
10    // pub flags: Option<ColumnFlags>,
11}
12
13/// Type information for a MySql type.
14#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
15pub struct MySqlTypeInfo {
16    pub r#type: ColumnType,
17    // pub flags: ColumnFlags,
18    pub char_set: u16,
19    // [max_size] for integer types, this is (M) in BIT(M) or TINYINT(M)
20    // #[serde(default)]
21    // pub max_size: Option<u32>,
22}
23impl MySqlTypeInfo {
24    fn is_null(&self) -> bool {
25        matches!(self.r#type, ColumnType::Null)
26    }
27
28    pub const fn binary(ty: ColumnType) -> Self {
29        Self {
30            r#type: ty,
31            // flags: ColumnFlags::BINARY,
32            char_set: 63,
33        }
34    }
35
36    #[doc(hidden)]
37    pub const fn null() -> Self {
38        Self {
39            r#type: ColumnType::Null,
40            // flags: ColumnFlags::BINARY,
41            char_set: 63,
42        }
43    }
44
45    #[doc(hidden)]
46    pub const fn __enum() -> Self {
47        Self {
48            r#type: ColumnType::Enum,
49            // flags: ColumnFlags::BINARY,
50            char_set: 63,
51        }
52    }
53
54    #[doc(hidden)]
55    pub fn __type_feature_gate(&self) -> Option<&'static str> {
56        match self.r#type {
57            ColumnType::Date | ColumnType::Time | ColumnType::Timestamp | ColumnType::Datetime => {
58                Some("time")
59            }
60            ColumnType::Json => Some("json"),
61            ColumnType::NewDecimal => Some("bigdecimal"),
62            _ => None,
63        }
64    }
65
66    pub(crate) fn from_column(column: &ColumnDefinition) -> Self {
67        Self {
68            r#type: column.r#type,
69            // flags: column.flags,
70            char_set: column.char_set,
71        }
72    }
73
74    pub(crate) fn from_type(ty: ColumnType) -> Self {
75        Self {
76            r#type: ty,
77            // flags: column.flags,
78            char_set: 63,
79        }
80    }
81}