Skip to content

Commit

Permalink
Add multirange kind and run cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
jkosh44 committed Nov 21, 2022
1 parent f413e66 commit 0c86f93
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 564 deletions.
24 changes: 21 additions & 3 deletions codegen/src/type_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct Type {
variant: String,
ident: String,
kind: String,
typtype: Option<String>,
element: u32,
doc: String,
}
Expand Down Expand Up @@ -217,12 +218,18 @@ fn parse_types() -> BTreeMap<u32, Type> {
continue;
}

let typtype = raw_type.get("typtype").cloned();

let element = match &*kind {
"R" => match &*raw_type["typtype"] {
"R" => match typtype
.as_ref()
.expect("range type must have typtype")
.as_str()
{
"r" => range_elements[&oid],
"m" => multi_range_elements[&oid],
typtype => panic!("invalid range typtype {}", typtype),
}
},
"A" => oids_by_name[&raw_type["typelem"]],
_ => 0,
};
Expand All @@ -248,6 +255,7 @@ fn parse_types() -> BTreeMap<u32, Type> {
variant,
ident,
kind: "A".to_string(),
typtype: None,
element: oid,
doc,
};
Expand All @@ -259,6 +267,7 @@ fn parse_types() -> BTreeMap<u32, Type> {
variant,
ident,
kind,
typtype,
element,
doc,
};
Expand Down Expand Up @@ -362,7 +371,16 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
let kind = match &*type_.kind {
"P" => "Pseudo".to_owned(),
"A" => format!("Array(Type(Inner::{}))", types[&type_.element].variant),
"R" => format!("Range(Type(Inner::{}))", types[&type_.element].variant),
"R" => match type_
.typtype
.as_ref()
.expect("range type must have typtype")
.as_str()
{
"r" => format!("Range(Type(Inner::{}))", types[&type_.element].variant),
"m" => format!("Multirange(Type(Inner::{}))", types[&type_.element].variant),
typtype => panic!("invalid range typtype {}", typtype),
},
_ => "Simple".to_owned(),
};

Expand Down
2 changes: 2 additions & 0 deletions postgres-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ pub enum Kind {
Array(Type),
/// A range type along with the type of its elements.
Range(Type),
/// A multirange type along with the type of its elements.
Multirange(Type),
/// A domain type along with its underlying type.
Domain(Type),
/// A composite type along with information about its fields.
Expand Down
Loading

0 comments on commit 0c86f93

Please sign in to comment.