Skip to content

Commit 384a928

Browse files
committed
chore(codegen): move enum out of function
1 parent 911d09a commit 384a928

1 file changed

Lines changed: 33 additions & 33 deletions

File tree

sea-orm-codegen/src/entity/writer/frontend.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,39 @@ use std::collections::HashSet;
33

44
use super::*;
55

6+
// seperate enum so `ColumnType` doesnt need to derive `Hash` or `Eq`
7+
#[derive(Hash, PartialEq, Eq)]
8+
enum ExternalTypes {
9+
JsonOrJsonBinary,
10+
Date,
11+
Time,
12+
DateTime,
13+
Timestamp,
14+
TimestampWithTimeZone,
15+
DecimalOrMoney,
16+
Uuid,
17+
Vector,
18+
CidrOrInet,
19+
}
20+
21+
impl ExternalTypes {
22+
fn from_column_type(col_type: &ColumnType) -> Option<Self> {
23+
Some(match col_type {
24+
ColumnType::Json | ColumnType::JsonBinary => Self::JsonOrJsonBinary,
25+
ColumnType::Date => Self::Date,
26+
ColumnType::Time => Self::Time,
27+
ColumnType::DateTime => Self::DateTime,
28+
ColumnType::Timestamp => Self::Timestamp,
29+
ColumnType::TimestampWithTimeZone => Self::TimestampWithTimeZone,
30+
ColumnType::Decimal(..) | ColumnType::Money(..) => Self::DecimalOrMoney,
31+
ColumnType::Uuid => Self::Uuid,
32+
ColumnType::Vector(..) => Self::Vector,
33+
ColumnType::Cidr | ColumnType::Inet => Self::CidrOrInet,
34+
_ => return None,
35+
})
36+
}
37+
}
38+
639
impl EntityWriter {
740
#[allow(clippy::too_many_arguments)]
841
pub fn gen_frontend_code_blocks(
@@ -83,39 +116,6 @@ impl EntityWriter {
83116
}
84117

85118
pub fn gen_import_frontend(entity: &Entity, opt: &ColumnOption) -> TokenStream {
86-
// seperate enum so `ColumnType` doesnt need to derive `Hash` or `Eq`
87-
#[derive(Hash, PartialEq, Eq)]
88-
enum ExternalTypes {
89-
JsonOrJsonBinary,
90-
Date,
91-
Time,
92-
DateTime,
93-
Timestamp,
94-
TimestampWithTimeZone,
95-
DecimalOrMoney,
96-
Uuid,
97-
Vector,
98-
CidrOrInet,
99-
}
100-
101-
impl ExternalTypes {
102-
fn from_column_type(col_type: &ColumnType) -> Option<Self> {
103-
Some(match col_type {
104-
ColumnType::Json | ColumnType::JsonBinary => Self::JsonOrJsonBinary,
105-
ColumnType::Date => Self::Date,
106-
ColumnType::Time => Self::Time,
107-
ColumnType::DateTime => Self::DateTime,
108-
ColumnType::Timestamp => Self::Timestamp,
109-
ColumnType::TimestampWithTimeZone => Self::TimestampWithTimeZone,
110-
ColumnType::Decimal(..) | ColumnType::Money(..) => Self::DecimalOrMoney,
111-
ColumnType::Uuid => Self::Uuid,
112-
ColumnType::Vector(..) => Self::Vector,
113-
ColumnType::Cidr | ColumnType::Inet => Self::CidrOrInet,
114-
_ => return None,
115-
})
116-
}
117-
}
118-
119119
fn collect(
120120
col_type: &ColumnType,
121121
opt: &ColumnOption,

0 commit comments

Comments
 (0)