Skip to content

Commit

Permalink
Remove is_option and is_result from ReturnEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
workingjubilee committed May 15, 2024
1 parent 91cc61b commit bd44aaa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 26 deletions.
16 changes: 3 additions & 13 deletions pgrx-sql-entity-graph/src/pg_extern/entity/returning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,9 @@ use crate::UsedTypeEntity;
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub enum PgExternReturnEntity {
None,
Type {
ty: UsedTypeEntity,
},
SetOf {
ty: UsedTypeEntity,
is_option: bool, /* Eg `Option<SetOfIterator<T>>` */
is_result: bool, /* Eg `Result<SetOfIterator<T>, E>` */
},
Iterated {
tys: Vec<PgExternReturnEntityIteratedItem>,
is_option: bool, /* Eg `Option<TableIterator<T>>` */
is_result: bool, /* Eg `Result<TableIterator<T>, E>` */
},
Type { ty: UsedTypeEntity },
SetOf { ty: UsedTypeEntity },
Iterated { tys: Vec<PgExternReturnEntityIteratedItem> },
Trigger,
}

Expand Down
21 changes: 8 additions & 13 deletions pgrx-sql-entity-graph/src/pg_extern/returning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub struct ReturningIteratedItem {
pub enum Returning {
None,
Type(UsedType),
SetOf { ty: UsedType, is_option: bool, is_result: bool },
Iterated { tys: Vec<ReturningIteratedItem>, is_option: bool, is_result: bool },
SetOf { ty: UsedType },
Iterated { tys: Vec<ReturningIteratedItem> },
// /// Technically we don't ever create this, single triggers have their own macro.
// Trigger,
}
Expand Down Expand Up @@ -116,7 +116,6 @@ impl Returning {
"where's the generic args?",
));
};
is_option = true;
segments = this_path.path.segments.clone(); // recurse deeper
} else {
if segments.last_ident_is("SetOfIterator") {
Expand Down Expand Up @@ -163,7 +162,7 @@ impl Returning {
))
}
};
Ok(Returning::SetOf { ty: used_ty, is_option, is_result })
Ok(Returning::SetOf { ty: used_ty })
} else if is_table_iter {
let last_path_segment = segments.last_mut().unwrap();
let mut iterated_items = vec![];
Expand Down Expand Up @@ -246,7 +245,7 @@ impl Returning {
))
}
};
Ok(Returning::Iterated { tys: iterated_items, is_option, is_result })
Ok(Returning::Iterated { tys: iterated_items })
} else {
let used_ty = UsedType::new(syn::Type::Path(typepath.clone()))?;
Ok(Returning::Type(used_ty))
Expand Down Expand Up @@ -302,17 +301,15 @@ impl ToTokens for Returning {
}
}
}
Returning::SetOf { ty: used_ty, is_option, is_result } => {
Returning::SetOf { ty: used_ty } => {
let used_ty_entity_tokens = used_ty.entity_tokens();
quote! {
::pgrx::pgrx_sql_entity_graph::PgExternReturnEntity::SetOf {
ty: #used_ty_entity_tokens,
is_option: #is_option,
is_result: #is_result
}
}
}
}
Returning::Iterated { tys: items, is_option, is_result } => {
Returning::Iterated { tys: items } => {
let quoted_items = items
.iter()
.map(|ReturningIteratedItem { used_ty, name }| {
Expand All @@ -331,9 +328,7 @@ impl ToTokens for Returning {
tys: vec![
#(#quoted_items),*
],
is_option: #is_option,
is_result: #is_result
}
}
}
}
};
Expand Down

0 comments on commit bd44aaa

Please sign in to comment.