Skip to content

Commit

Permalink
Merge pull request #121 from SeaQL/fmt-doc-comments
Browse files Browse the repository at this point in the history
cargo fmt doc comments
  • Loading branch information
billy1624 committed Sep 3, 2021
2 parents b32fe66 + 5060890 commit aa15c44
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 70 deletions.
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

0 comments on commit aa15c44

Please sign in to comment.