Skip to content

Commit 37abbb2

Browse files
authored
Merge pull request diesel-rs#1078 from diesel-rs/sg-remove-path-handling
Remove path handling from `diesel_infer_schema`
2 parents 9b69c28 + 24441cf commit 37abbb2

5 files changed

Lines changed: 18 additions & 32 deletions

File tree

diesel_infer_schema/src/codegen.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,9 @@ fn column_def_tokens(
6868
e,
6969
).into()),
7070
};
71-
let tpe = if column_type.path[0] == "diesel" && column_type.path[1] == "types" {
72-
let path_segments = column_type.path
73-
.into_iter()
74-
.skip(2)
75-
.map(syn::PathSegment::from)
76-
.collect();
77-
syn::Path { global: false, segments: path_segments }
78-
} else {
79-
let path_segments = column_type.path
80-
.into_iter()
81-
.map(syn::PathSegment::from)
82-
.collect();
83-
syn::Path { global: true, segments: path_segments }
71+
let tpe = syn::Path {
72+
global: false,
73+
segments: vec![syn::PathSegment::from(column_type.rust_name)],
8474
};
8575
let mut tpe = quote!(#tpe);
8676

diesel_infer_schema/src/data_structures.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct ColumnInformation {
1717
}
1818

1919
pub struct ColumnType {
20-
pub path: Vec<String>,
20+
pub rust_name: String,
2121
pub is_array: bool,
2222
pub is_nullable: bool,
2323
}

diesel_infer_schema/src/mysql.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn determine_column_type(attr: &ColumnInformation) -> Result<ColumnType, Box
6868
let tpe = determine_type_name(&attr.type_name)?;
6969

7070
Ok(ColumnType {
71-
path: vec!["diesel".into(), "types".into(), capitalize(tpe)],
71+
rust_name: capitalize(tpe),
7272
is_array: false,
7373
is_nullable: attr.nullable,
7474
})

diesel_infer_schema/src/pg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn determine_column_type(attr: &ColumnInformation) -> Result<ColumnType, Box
2323
}
2424

2525
Ok(ColumnType {
26-
path: vec!["diesel".into(), "types".into(), capitalize(tpe)],
26+
rust_name: capitalize(tpe),
2727
is_array: is_array,
2828
is_nullable: attr.nullable,
2929
})

diesel_infer_schema/src/sqlite.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -148,41 +148,37 @@ pub fn get_primary_keys(conn: &SqliteConnection, table: &TableData) -> QueryResu
148148
.collect())
149149
}
150150

151-
fn diesel_type(t: &str) -> Vec<String> {
152-
vec!["diesel".into(), "types".into(), t.into()]
153-
}
154-
155151
pub fn determine_column_type(attr: &ColumnInformation) -> Result<ColumnType, Box<Error>> {
156152
let type_name = attr.type_name.to_lowercase();
157153
let path = if is_bool(&type_name) {
158-
diesel_type("Bool")
154+
String::from("Bool")
159155
} else if is_smallint(&type_name) {
160-
diesel_type("SmallInt")
156+
String::from("SmallInt")
161157
} else if is_bigint(&type_name) {
162-
diesel_type("BigInt")
158+
String::from("BigInt")
163159
} else if type_name.contains("int") {
164-
diesel_type("Integer")
160+
String::from("Integer")
165161
} else if is_text(&type_name) {
166-
diesel_type("Text")
162+
String::from("Text")
167163
} else if type_name.contains("blob") || type_name.is_empty() {
168-
diesel_type("Binary")
164+
String::from("Binary")
169165
} else if is_float(&type_name) {
170-
diesel_type("Float")
166+
String::from("Float")
171167
} else if is_double(&type_name) {
172-
diesel_type("Double")
168+
String::from("Double")
173169
} else if type_name == "datetime" || type_name == "timestamp" {
174-
diesel_type("Timestamp")
170+
String::from("Timestamp")
175171
} else if type_name == "date" {
176-
diesel_type("Date")
172+
String::from("Date")
177173
} else if type_name == "time" {
178-
diesel_type("Time")
174+
String::from("Time")
179175
}
180176
else {
181177
return Err(format!("Unsupported type: {}", type_name).into())
182178
};
183179

184180
Ok(ColumnType {
185-
path: path,
181+
rust_name: path,
186182
is_array: false,
187183
is_nullable: attr.nullable,
188184
})

0 commit comments

Comments
 (0)