Conversation
|
Is it ready to review? |
|
Yes. I added the functions and appropriate doc test already. |
|
Next time please make a better PR title |
Co-authored-by: Chris Tsang <[email protected]>
billy1624
left a comment
There was a problem hiding this comment.
Hey @darkmmon, good first PR!
Take below for example, my imaginated real life example
use sea_orm::sea_query::Expr;
use sea_orm::{entity::*, tests_cfg::cake, DbBackend, QuerySelect, QueryTrait};
assert_eq!(
cake::Entity::find()
.select_only()
.expr(Expr::col((cake::Entity, cake::Column::Id)))
.expr(Expr::col((cake::Entity, cake::Column::Name)))
.build(DbBackend::MySql)
.to_string(),
"SELECT `cake`.`id`, `cake`.`name` FROM `cake`"
);use sea_orm::sea_query::Expr;
use sea_orm::{entity::*, tests_cfg::cake, DbBackend, QuerySelect, QueryTrait};
assert_eq!(
cake::Entity::find()
.select_only()
.exprs([
Expr::col((cake::Entity, cake::Column::Id)),
Expr::col((cake::Entity, cake::Column::Name)),
])
.build(DbBackend::MySql)
.to_string(),
"SELECT `cake`.`id`, `cake`.`name` FROM `cake`"
);Note that I import sea_orm::sea_query::Expr instead of sea_query::Expr. Because the end user does not necessary depends on sea_query but it must depends on sea_orm. So, we better direct user to import the sea_query symbols re-exported by sea_orm. Hope that make sense :)
billy1624
left a comment
There was a problem hiding this comment.
A feature creep: I think we can add expr_as as well
https://docs.rs/sea-query/latest/sea_query/query/struct.SelectStatement.html#method.expr_as
use sea_orm::sea_query::{Expr, Func};
use sea_orm::{entity::*, tests_cfg::cake, DbBackend, QuerySelect, QueryTrait};
assert_eq!(
cake::Entity::find()
.expr_as(Func::upper(Expr::col((cake::Entity, cake::Column::Name))), "name_upper")
.build(DbBackend::MySql)
.to_string(),
"SELECT `cake`.`id`, `cake`.`name`, UPPER(`cake`.`name`) AS `name_upper` FROM `cake`"
);With a real life example. Copy and paste is okay. But feel free to add your own style :)
|
Thanks @billy1624 and @tyt2y3 for all the suggestions! I integrated them to the code. |
| fn expr_as<T, A>(&mut self, expr: T, alias: A) -> &mut Self | ||
| where | ||
| T: Into<SimpleExpr>, | ||
| A: IntoIden, | ||
| { | ||
| self.query().expr_as(expr, alias); | ||
| self | ||
| } |
There was a problem hiding this comment.
One final change, we may well align it with QuerySelect::column_as method and take an alias of I: IntoIdentity
There was a problem hiding this comment.
Hint: better update the example to supply an &str as the alias
| fn expr_as<T, A>(&mut self, expr: T, alias: A) -> &mut Self | ||
| where | ||
| T: Into<SimpleExpr>, | ||
| A: IntoIden, | ||
| { | ||
| self.query().expr_as(expr, alias); | ||
| self | ||
| } |
There was a problem hiding this comment.
Hint: better update the example to supply an &str as the alias
* Optional Field SeaQL/sea-orm#1513 * .gitignore SeaQL/sea-orm#1334 * migration table custom name SeaQL/sea-orm#1511 * OR condition relation SeaQL/sea-orm#1433 * DerivePartialModel SeaQL/sea-orm#1597 * space for migration file naming SeaQL/sea-orm#1570 * composite key up to 12 SeaQL/sea-orm#1508 * seaography integration SeaQL/sea-orm#1599 * QuerySelect SimpleExpr SeaQL/sea-orm#1702 * sqlErr SeaQL/sea-orm#1707 * migration check SeaQL/sea-orm#1519 * postgres array SeaQL/sea-orm#1565 * param intoString SeaQL/sea-orm#1439 * **skipped** re-export SeaQL/sea-orm#1661 * ping SeaQL/sea-orm#1627 * on empty do nothing SeaQL/sea-orm#1708 * on conflict do nothing SeaQL/sea-orm#1712 * **skipped** upgrade versions * active enum fail safe SeaQL/sea-orm#1374 * relation generation check SeaQL/sea-orm#1435 * entity generation bug SeaQL/sea-schema#105 * **skipped** bug fix that does not require edits * EnumIter change SeaQL/sea-orm#1535 * completed and fixed a previous todo SeaQL/sea-orm#1570 * amended wordings and structures * Edit * Remove temp file --------- Co-authored-by: Billy Chan <[email protected]>
🎉 Released In 0.12.1 🎉Thank you everyone for the contribution! |
PR Info
SimpleExprviaQuerySelect#1696New Features
Changes