MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / apply_alias

Method apply_alias

src/query/combine.rs:36–74  ·  view source on GitHub ↗
(mut self, pre: &str)

Source from the content-addressed store, hash-verified

34 E: EntityTrait,
35{
36 pub(crate) fn apply_alias(mut self, pre: &str) -> Self {
37 self.query().exprs_mut_for_each(|sel| {
38 match &sel.alias {
39 Some(alias) => {
40 let alias = format!("{}{}", pre, alias.to_string().as_str());
41 sel.alias = Some(SeaRc::new(Alias::new(alias)));
42 }
43 None => {
44 let col = match &sel.expr {
45 SimpleExpr::Column(col_ref) => match &col_ref {
46 ColumnRef::Column(col)
47 | ColumnRef::TableColumn(_, col)
48 | ColumnRef::SchemaTableColumn(_, _, col) => col,
49 ColumnRef::Asterisk | ColumnRef::TableAsterisk(_) => {
50 panic!("cannot apply alias for Column with asterisk")
51 }
52 },
53 SimpleExpr::AsEnum(_, simple_expr) => match simple_expr.as_ref() {
54 SimpleExpr::Column(col_ref) => match &col_ref {
55 ColumnRef::Column(col)
56 | ColumnRef::TableColumn(_, col)
57 | ColumnRef::SchemaTableColumn(_, _, col) => col,
58 ColumnRef::Asterisk | ColumnRef::TableAsterisk(_) => {
59 panic!("cannot apply alias for AsEnum with asterisk")
60 }
61 },
62 _ => {
63 panic!("cannot apply alias for AsEnum with expr other than Column")
64 }
65 },
66 _ => panic!("cannot apply alias for expr other than Column or AsEnum"),
67 };
68 let alias = format!("{}{}", pre, col.to_string().as_str());
69 sel.alias = Some(SeaRc::new(Alias::new(alias)));
70 }
71 };
72 });
73 self
74 }
75
76 /// Selects extra Entity and returns it together with the Entity from `Self`
77 pub fn select_also<F>(mut self, _: F) -> SelectTwo<E, F>

Callers 4

select_alsoMethod · 0.80
select_withMethod · 0.80
find_also_linkedMethod · 0.80
find_with_linkedMethod · 0.80

Calls 3

as_refMethod · 0.80
newFunction · 0.50
queryMethod · 0.45

Tested by

no test coverage detected