sqlx_xugu/
type_info.rs

1use std::fmt::{self, Display, Formatter};
2
3pub(crate) use sqlx_core::type_info::*;
4
5use crate::protocol::text::{ColumnDefinition, ColumnFlags, ColumnType};
6
7/// Type information for a Xugu type.
8#[derive(Debug, Clone)]
9#[cfg_attr(feature = "offline", derive(serde::Serialize, serde::Deserialize))]
10pub struct XuguTypeInfo {
11    pub(crate) r#type: ColumnType,
12    pub(crate) flags: ColumnFlags,
13}
14
15impl XuguTypeInfo {
16    pub(crate) const fn binary(ty: ColumnType) -> Self {
17        Self {
18            r#type: ty,
19            flags: ColumnFlags::IS_LOB,
20        }
21    }
22
23    #[doc(hidden)]
24    pub fn __type_feature_gate(&self) -> Option<&'static str> {
25        match self.r#type {
26            ColumnType::DATE
27            | ColumnType::TIME
28            | ColumnType::DATETIME
29            | ColumnType::TIME_TZ
30            | ColumnType::DATETIME_TZ => Some("time"),
31
32            ColumnType::JSON => Some("json"),
33            ColumnType::NUMERIC => Some("numeric"),
34
35            _ => None,
36        }
37    }
38
39    pub(crate) fn from_column(column: &ColumnDefinition) -> Self {
40        Self {
41            r#type: column.r#type,
42            flags: column.flags,
43        }
44    }
45}
46
47impl Display for XuguTypeInfo {
48    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
49        f.pad(self.name())
50    }
51}
52
53impl TypeInfo for XuguTypeInfo {
54    fn is_null(&self) -> bool {
55        matches!(self.r#type, ColumnType::NONE | ColumnType::NULL)
56    }
57
58    fn name(&self) -> &str {
59        self.r#type.name()
60    }
61}
62
63impl PartialEq<XuguTypeInfo> for XuguTypeInfo {
64    fn eq(&self, other: &XuguTypeInfo) -> bool {
65        if self.r#type != other.r#type {
66            return false;
67        }
68
69        true
70    }
71}
72
73impl Eq for XuguTypeInfo {}