Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo fmt doc comments #121

Merged
merged 2 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
format_code_in_doc_comments=true
26 changes: 17 additions & 9 deletions src/entity/base_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,18 @@ pub trait EntityTrait: EntityName {
/// assert_eq!(
/// db.into_transaction_log(),
/// vec![
/// Transaction::from_sql_and_values(
/// DbBackend::Postgres, r#"SELECT "cake"."id", "cake"."name" FROM "cake" LIMIT $1"#, vec![1u64.into()]
/// ),
/// Transaction::from_sql_and_values(
/// DbBackend::Postgres, r#"SELECT "cake"."id", "cake"."name" FROM "cake""#, vec![]
/// ),
/// ]);
/// Transaction::from_sql_and_values(
/// DbBackend::Postgres,
/// r#"SELECT "cake"."id", "cake"."name" FROM "cake" LIMIT $1"#,
/// vec![1u64.into()]
/// ),
/// Transaction::from_sql_and_values(
/// DbBackend::Postgres,
/// r#"SELECT "cake"."id", "cake"."name" FROM "cake""#,
/// vec![]
/// ),
/// ]
/// );
/// ```
fn find() -> Select<Self> {
Select::new()
Expand Down Expand Up @@ -186,8 +191,11 @@ pub trait EntityTrait: EntityName {
/// assert_eq!(
/// db.into_transaction_log(),
/// vec![Transaction::from_sql_and_values(
/// DbBackend::Postgres, r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE "cake"."id" = $1"#, vec![11i32.into()]
/// )]);
/// DbBackend::Postgres,
/// r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE "cake"."id" = $1"#,
/// vec![11i32.into()]
/// )]
/// );
/// ```
/// Find by composite key
/// ```
Expand Down
4 changes: 2 additions & 2 deletions src/entity/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub trait ColumnTrait: IdenStatic + Iterable + FromStr {
///
/// assert_eq!(
/// cake::Entity::find()
/// .filter(cake::Column::Id.between(2,3))
/// .filter(cake::Column::Id.between(2, 3))
/// .build(DbBackend::MySql)
/// .to_string(),
/// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`id` BETWEEN 2 AND 3"
Expand All @@ -121,7 +121,7 @@ pub trait ColumnTrait: IdenStatic + Iterable + FromStr {
///
/// assert_eq!(
/// cake::Entity::find()
/// .filter(cake::Column::Id.not_between(2,3))
/// .filter(cake::Column::Id.not_between(2, 3))
/// .build(DbBackend::MySql)
/// .to_string(),
/// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`id` NOT BETWEEN 2 AND 3"
Expand Down
76 changes: 43 additions & 33 deletions src/executor/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,15 @@ where
///
/// # let _: Result<(), DbErr> = smol::block_on(async {
/// #
/// let res: Vec<SelectResult> = cake::Entity::find().from_raw_sql(
/// Statement::from_sql_and_values(
/// DbBackend::Postgres, r#"SELECT "cake"."name", count("cake"."id") AS "num_of_cakes" FROM "cake""#, vec![]
/// )
/// )
/// .into_model::<SelectResult>()
/// .all(&db)
/// .await?;
/// let res: Vec<SelectResult> = cake::Entity::find()
/// .from_raw_sql(Statement::from_sql_and_values(
/// DbBackend::Postgres,
/// r#"SELECT "cake"."name", count("cake"."id") AS "num_of_cakes" FROM "cake""#,
/// vec![],
/// ))
/// .into_model::<SelectResult>()
/// .all(&db)
/// .await?;
///
/// assert_eq!(
/// res,
Expand All @@ -318,11 +319,12 @@ where
///
/// assert_eq!(
/// db.into_transaction_log(),
/// vec![
/// Transaction::from_sql_and_values(
/// DbBackend::Postgres, r#"SELECT "cake"."name", count("cake"."id") AS "num_of_cakes" FROM "cake""#, vec![]
/// ),
/// ]);
/// vec![Transaction::from_sql_and_values(
/// DbBackend::Postgres,
/// r#"SELECT "cake"."name", count("cake"."id") AS "num_of_cakes" FROM "cake""#,
/// vec![]
/// ),]
/// );
/// ```
pub fn into_model<M>(self) -> SelectorRaw<SelectModel<M>>
where
Expand Down Expand Up @@ -407,22 +409,26 @@ where
///
/// # let _: Result<(), DbErr> = smol::block_on(async {
/// #
/// let _: Option<cake::Model> = cake::Entity::find().from_raw_sql(
/// Statement::from_sql_and_values(
/// DbBackend::Postgres, r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE "id" = $1"#, vec![1.into()]
/// )
/// ).one(&db).await?;
/// let _: Option<cake::Model> = cake::Entity::find()
/// .from_raw_sql(Statement::from_sql_and_values(
/// DbBackend::Postgres,
/// r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE "id" = $1"#,
/// vec![1.into()],
/// ))
/// .one(&db)
/// .await?;
/// #
/// # Ok(())
/// # });
///
/// assert_eq!(
/// db.into_transaction_log(),
/// vec![
/// Transaction::from_sql_and_values(
/// DbBackend::Postgres, r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE "id" = $1"#, vec![1.into()]
/// ),
/// ]);
/// vec![Transaction::from_sql_and_values(
/// DbBackend::Postgres,
/// r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE "id" = $1"#,
/// vec![1.into()]
/// ),]
/// );
/// ```
pub async fn one(self, db: &DatabaseConnection) -> Result<Option<S::Item>, DbErr> {
let row = db.query_one(self.stmt).await?;
Expand All @@ -442,22 +448,26 @@ where
///
/// # let _: Result<(), DbErr> = smol::block_on(async {
/// #
/// let _: Vec<cake::Model> = cake::Entity::find().from_raw_sql(
/// Statement::from_sql_and_values(
/// DbBackend::Postgres, r#"SELECT "cake"."id", "cake"."name" FROM "cake""#, vec![]
/// )
/// ).all(&db).await?;
/// let _: Vec<cake::Model> = cake::Entity::find()
/// .from_raw_sql(Statement::from_sql_and_values(
/// DbBackend::Postgres,
/// r#"SELECT "cake"."id", "cake"."name" FROM "cake""#,
/// vec![],
/// ))
/// .all(&db)
/// .await?;
/// #
/// # Ok(())
/// # });
///
/// assert_eq!(
/// db.into_transaction_log(),
/// vec![
/// Transaction::from_sql_and_values(
/// DbBackend::Postgres, r#"SELECT "cake"."id", "cake"."name" FROM "cake""#, vec![]
/// ),
/// ]);
/// vec![Transaction::from_sql_and_values(
/// DbBackend::Postgres,
/// r#"SELECT "cake"."id", "cake"."name" FROM "cake""#,
/// vec![]
/// ),]
/// );
/// ```
pub async fn all(self, db: &DatabaseConnection) -> Result<Vec<S::Item>, DbErr> {
let rows = db.query_all(self.stmt).await?;
Expand Down
6 changes: 2 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@
//! let fruits: Vec<fruit::Model> = cheese.find_related(Fruit).all(db).await?;
//!
//! // find related models (eager)
//! let cake_with_fruits: Vec<(cake::Model, Vec<fruit::Model>)> = Cake::find()
//! .find_with_related(Fruit)
//! .all(db)
//! .await?;
//! let cake_with_fruits: Vec<(cake::Model, Vec<fruit::Model>)> =
//! Cake::find().find_with_related(Fruit).all(db).await?;
//!
//! # Ok(())
//! # }
Expand Down
42 changes: 21 additions & 21 deletions src/query/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ where
///
/// assert_eq!(
/// Insert::one(cake::Model {
/// id: 1,
/// name: "Apple Pie".to_owned(),
/// })
/// .build(DbBackend::Postgres)
/// .to_string(),
/// id: 1,
/// name: "Apple Pie".to_owned(),
/// })
/// .build(DbBackend::Postgres)
/// .to_string(),
/// r#"INSERT INTO "cake" ("id", "name") VALUES (1, 'Apple Pie')"#,
/// );
/// ```
Expand All @@ -57,11 +57,11 @@ where
///
/// assert_eq!(
/// Insert::one(cake::ActiveModel {
/// id: Unset(None),
/// name: Set("Apple Pie".to_owned()),
/// })
/// .build(DbBackend::Postgres)
/// .to_string(),
/// id: Unset(None),
/// name: Set("Apple Pie".to_owned()),
/// })
/// .build(DbBackend::Postgres)
/// .to_string(),
/// r#"INSERT INTO "cake" ("name") VALUES ('Apple Pie')"#,
/// );
/// ```
Expand All @@ -79,17 +79,17 @@ where
///
/// assert_eq!(
/// Insert::many(vec![
/// cake::Model {
/// id: 1,
/// name: "Apple Pie".to_owned(),
/// },
/// cake::Model {
/// id: 2,
/// name: "Orange Scone".to_owned(),
/// }
/// ])
/// .build(DbBackend::Postgres)
/// .to_string(),
/// cake::Model {
/// id: 1,
/// name: "Apple Pie".to_owned(),
/// },
/// cake::Model {
/// id: 2,
/// name: "Orange Scone".to_owned(),
/// }
/// ])
/// .build(DbBackend::Postgres)
/// .to_string(),
/// r#"INSERT INTO "cake" ("id", "name") VALUES (1, 'Apple Pie'), (2, 'Orange Scone')"#,
/// );
/// ```
Expand Down
2 changes: 1 addition & 1 deletion src/query/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Update {
/// Update many ActiveModel
///
/// ```
/// use sea_orm::{entity::*, query::*, tests_cfg::fruit, sea_query::Expr, DbBackend};
/// use sea_orm::{entity::*, query::*, sea_query::Expr, tests_cfg::fruit, DbBackend};
///
/// assert_eq!(
/// Update::many(fruit::Entity)
Expand Down