From 74e68f424e547c4d749a3e84a13f19f15c33dc0e Mon Sep 17 00:00:00 2001 From: Yiu Tin Cheung Ivan Date: Wed, 12 Jul 2023 12:14:56 +0800 Subject: [PATCH] QuerySelect SimpleExpr SeaQL/sea-orm#1702 --- SeaORM/docs/0.12.x-CHANGELOG_temp.md | 2 +- SeaORM/docs/08-advanced-query/01-custom-select.md | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/SeaORM/docs/0.12.x-CHANGELOG_temp.md b/SeaORM/docs/0.12.x-CHANGELOG_temp.md index 0655b366a9d..634ccadf01b 100644 --- a/SeaORM/docs/0.12.x-CHANGELOG_temp.md +++ b/SeaORM/docs/0.12.x-CHANGELOG_temp.md @@ -204,7 +204,6 @@ pub enum RelatedEntity { * Add `DeriveEntityRelated` macro https://github.com/SeaQL/sea-orm/pull/1599 The DeriveRelatedEntity derive macro will implement `seaography::RelationBuilder` for `RelatedEntity` enumeration when the `seaography` feature is enabled - ================================ All Changes above was being Documented ================================ * Add `expr`, `exprs` and `expr_as` methods to `QuerySelect` trait ```rs @@ -243,6 +242,7 @@ assert_eq!( "SELECT `cake`.`id`, `cake`.`name`, UPPER(`cake`.`name`) AS `name_upper` FROM `cake`" ); ``` + ================================ All Changes above was being Documented ================================ * Add `DbErr::sql_err()` method to convert error into common database errors `SqlErr`, such as unique constraint or foreign key violation errors. https://github.com/SeaQL/sea-orm/pull/1707 ```rs assert!(matches!( diff --git a/SeaORM/docs/08-advanced-query/01-custom-select.md b/SeaORM/docs/08-advanced-query/01-custom-select.md index b3a7533d7a3..5e8af4235e2 100644 --- a/SeaORM/docs/08-advanced-query/01-custom-select.md +++ b/SeaORM/docs/08-advanced-query/01-custom-select.md @@ -101,6 +101,21 @@ assert_eq!( ); ``` +Alternatively, you can simply select with `expr`, `exprs` and `expr_as` methods. +```rust +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))) + .build(DbBackend::MySql) + .to_string(), + "SELECT `cake`.`id` FROM `cake`" +); +``` + ## Handling Select Results ### Custom Struct