Skip to content

Commit

Permalink
Supporting types and implementations for replacing SeaORM's `ColumnTy…
Browse files Browse the repository at this point in the history
…pe` (#579)

* Implements `PartialEq` for `ColumnType`

* Add helper function to construct `ColumnType::Custom`
  • Loading branch information
billy1624 authored and tyt2y3 committed Jan 18, 2023
1 parent b697eac commit f3a3021
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions src/table/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,48 @@ pub enum ColumnType {
MacAddr,
}

impl PartialEq for ColumnType {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Char(l0), Self::Char(r0)) => l0 == r0,
(Self::String(l0), Self::String(r0)) => l0 == r0,
(Self::Decimal(l0), Self::Decimal(r0)) => l0 == r0,
(Self::Year(l0), Self::Year(r0)) => l0 == r0,
(Self::Interval(l0, l1), Self::Interval(r0, r1)) => l0 == r0 && l1 == r1,
(Self::Binary(l0), Self::Binary(r0)) => l0 == r0,
(Self::VarBinary(l0), Self::VarBinary(r0)) => l0 == r0,
(Self::Bit(l0), Self::Bit(r0)) => l0 == r0,
(Self::VarBit(l0), Self::VarBit(r0)) => l0 == r0,
(Self::Money(l0), Self::Money(r0)) => l0 == r0,
(Self::Custom(l0), Self::Custom(r0)) => l0.to_string() == r0.to_string(),
(
Self::Enum {
name: l_name,
variants: l_variants,
},
Self::Enum {
name: r_name,
variants: r_variants,
},
) => {
l_name.to_string() == r_name.to_string()
&& l_variants
.iter()
.map(|v| v.to_string())
.eq(r_variants.iter().map(|v| v.to_string()))
}
(Self::Array(l0), Self::Array(r0)) => l0 == r0,
_ => core::mem::discriminant(self) == core::mem::discriminant(other),
}
}
}

impl ColumnType {
pub fn custom(ty: &str) -> ColumnType {
ColumnType::Custom(Alias::new(ty).into_iden())
}
}

/// All column specification keywords
#[derive(Debug, Clone)]
pub enum ColumnSpec {
Expand Down Expand Up @@ -86,13 +128,13 @@ pub enum PgInterval {
}

// All MySQL year type field length sizes
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum MySqlYear {
Two,
Four,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum BlobSize {
Tiny,
/// MySQL & SQLite support `binary(length)` column type
Expand Down

0 comments on commit f3a3021

Please sign in to comment.