Merge branch 'master' into last-insert-id

This commit is contained in:
Billy Chan 2021-09-30 11:28:29 +08:00
commit a241bc9d7b
No known key found for this signature in database
GPG Key ID: A2D690CAC7DF3CC7
4 changed files with 46 additions and 2 deletions

View File

@ -1,5 +1,7 @@
# Architecture # Architecture
> Let's dive under the Sea 🤿
To understand the architecture of SeaORM, let's discuss what is an ORM. ORM exists to provide abstractions over common operations you would do against a database and hide the implementation details like the actual SQL queries. To understand the architecture of SeaORM, let's discuss what is an ORM. ORM exists to provide abstractions over common operations you would do against a database and hide the implementation details like the actual SQL queries.
With a good ORM, you shouldn't bother to look under the API surface. Until you do. I hear you say *'abstraction leaks'*, and yes, it does. With a good ORM, you shouldn't bother to look under the API surface. Until you do. I hear you say *'abstraction leaks'*, and yes, it does.

View File

@ -239,7 +239,7 @@ fruit::Entity::delete_many()
1. [Design](https://github.com/SeaQL/sea-orm/tree/master/DESIGN.md) 1. [Design](https://github.com/SeaQL/sea-orm/tree/master/DESIGN.md)
1. [Architecture](https://github.com/SeaQL/sea-orm/tree/master/ARCHITECTURE.md) 1. [Architecture](https://github.com/SeaQL/sea-orm/tree/master/ARCHITECTURE.md)
1. [Compare with Diesel](https://www.sea-ql.org/SeaORM/docs/internal-design/diesel) 1. [Change Log](https://github.com/SeaQL/sea-orm/tree/master/CHANGELOG.md)
## License ## License

View File

@ -335,7 +335,7 @@
//! //!
//! 1. [Design](https://github.com/SeaQL/sea-orm/tree/master/DESIGN.md) //! 1. [Design](https://github.com/SeaQL/sea-orm/tree/master/DESIGN.md)
//! 1. [Architecture](https://github.com/SeaQL/sea-orm/tree/master/ARCHITECTURE.md) //! 1. [Architecture](https://github.com/SeaQL/sea-orm/tree/master/ARCHITECTURE.md)
//! 1. [Compare with Diesel](https://www.sea-ql.org/SeaORM/docs/internal-design/diesel) //! 1. [Change Log](https://github.com/SeaQL/sea-orm/tree/master/CHANGELOG.md)
//! //!
//! ## License //! ## License
//! //!

View File

@ -269,6 +269,48 @@ pub trait QueryFilter: Sized {
/// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`id` = 4 OR `cake`.`id` = 5" /// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`id` = 4 OR `cake`.`id` = 5"
/// ); /// );
/// ``` /// ```
///
/// Add a runtime-built condition tree.
/// ```
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
/// struct Input {
/// name: Option<String>,
/// }
/// let input = Input { name: Some("cheese".to_owned()) };
///
/// let mut conditions = Condition::all();
/// if let Some(name) = input.name {
/// conditions = conditions.add(cake::Column::Name.contains(&name));
/// }
///
/// assert_eq!(
/// cake::Entity::find()
/// .filter(conditions)
/// .build(DbBackend::MySql)
/// .to_string(),
/// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`name` LIKE '%cheese%'"
/// );
/// ```
///
/// Add a runtime-built condition tree, functional-way.
/// ```
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
/// struct Input {
/// name: Option<String>,
/// }
/// let input = Input { name: Some("cheese".to_owned()) };
///
/// assert_eq!(
/// cake::Entity::find()
/// .filter(
/// Condition::all()
/// .add_option(input.name.map(|n| cake::Column::Name.contains(&n)))
/// )
/// .build(DbBackend::MySql)
/// .to_string(),
/// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`name` LIKE '%cheese%'"
/// );
/// ```
fn filter<F>(mut self, filter: F) -> Self fn filter<F>(mut self, filter: F) -> Self
where where
F: IntoCondition, F: IntoCondition,