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 }
12
13#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
15pub struct MySqlTypeInfo {
16 pub r#type: ColumnType,
17 pub char_set: u16,
19 }
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 char_set: 63,
33 }
34 }
35
36 #[doc(hidden)]
37 pub const fn null() -> Self {
38 Self {
39 r#type: ColumnType::Null,
40 char_set: 63,
42 }
43 }
44
45 #[doc(hidden)]
46 pub const fn __enum() -> Self {
47 Self {
48 r#type: ColumnType::Enum,
49 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 char_set: column.char_set,
71 }
72 }
73
74 pub(crate) fn from_type(ty: ColumnType) -> Self {
75 Self {
76 r#type: ty,
77 char_set: 63,
79 }
80 }
81}