Skip to content

Commit

Permalink
Merge pull request #3 from billy1624/pr/890
Browse files Browse the repository at this point in the history
  • Loading branch information
shpun817 authored Sep 21, 2022
2 parents 2fbb964 + 32169c0 commit 5698638
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 95 deletions.
20 changes: 10 additions & 10 deletions examples/actix3_example/core/src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl Mutation {
id: i32,
form_data: post::Model,
) -> Result<post::Model, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post::ActiveModel {
id: post.id,
Expand All @@ -38,11 +38,11 @@ impl Mutation {
}

pub async fn delete_post(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post.delete(db).await
}
Expand Down
20 changes: 10 additions & 10 deletions examples/actix_example/core/src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl Mutation {
id: i32,
form_data: post::Model,
) -> Result<post::Model, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post::ActiveModel {
id: post.id,
Expand All @@ -38,11 +38,11 @@ impl Mutation {
}

pub async fn delete_post(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post.delete(db).await
}
Expand Down
20 changes: 10 additions & 10 deletions examples/axum_example/core/src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl Mutation {
id: i32,
form_data: post::Model,
) -> Result<post::Model, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post::ActiveModel {
id: post.id,
Expand All @@ -38,11 +38,11 @@ impl Mutation {
}

pub async fn delete_post(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post.delete(db).await
}
Expand Down
20 changes: 10 additions & 10 deletions examples/graphql_example/core/src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ impl Mutation {
id: i32,
form_data: note::Model,
) -> Result<note::Model, DbErr> {
let note: note::ActiveModel = if let Ok(Some(note)) = Note::find_by_id(id).one(db).await {
note.into()
} else {
return Err(DbErr::Custom("Cannot find note.".to_owned()));
};
let note: note::ActiveModel = Note::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find note.".to_owned()))
.map(Into::into)?;

note::ActiveModel {
id: note.id,
Expand All @@ -39,11 +39,11 @@ impl Mutation {
}

pub async fn delete_note(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
let note: note::ActiveModel = if let Ok(Some(note)) = Note::find_by_id(id).one(db).await {
note.into()
} else {
return Err(DbErr::Custom("Cannot find note.".to_owned()));
};
let note: note::ActiveModel = Note::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find note.".to_owned()))
.map(Into::into)?;

note.delete(db).await
}
Expand Down
2 changes: 1 addition & 1 deletion examples/jsonrpsee_example/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl PostRpcServer for PpcImpl {
async fn insert(&self, p: post::Model) -> RpcResult<i32> {
let new_post = Mutation::create_post(&self.conn, p)
.await
.expect("could not insert post");
.internal_call_error()?;

Ok(new_post.id.unwrap())
}
Expand Down
20 changes: 10 additions & 10 deletions examples/jsonrpsee_example/core/src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl Mutation {
id: i32,
form_data: post::Model,
) -> Result<post::Model, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post::ActiveModel {
id: post.id,
Expand All @@ -38,11 +38,11 @@ impl Mutation {
}

pub async fn delete_post(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post.delete(db).await
}
Expand Down
20 changes: 10 additions & 10 deletions examples/poem_example/core/src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl Mutation {
id: i32,
form_data: post::Model,
) -> Result<post::Model, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post::ActiveModel {
id: post.id,
Expand All @@ -38,11 +38,11 @@ impl Mutation {
}

pub async fn delete_post(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post.delete(db).await
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[default]
template_dir = "templates/"
template_dir = "api/templates/"

[default.databases.sea_orm]
# Mysql
Expand Down
1 change: 1 addition & 0 deletions examples/rocket_example/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ rocket_dyn_templates = { version = "0.1.0-rc.1", features = [
serde_json = { version = "^1" }
entity = { path = "../entity" }
migration = { path = "../migration" }
tokio = "1.20.0"

[dependencies.sea-orm-rocket]
path = "../../../sea-orm-rocket/lib" # remove this line in your own project and use the git line
Expand Down
9 changes: 6 additions & 3 deletions examples/rocket_example/api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#[macro_use]
extern crate rocket;

use futures::executor::block_on;
use rocket::fairing::{self, AdHoc};
use rocket::form::{Context, Form};
use rocket::fs::{relative, FileServer};
Expand Down Expand Up @@ -144,7 +143,8 @@ async fn run_migrations(rocket: Rocket<Build>) -> fairing::Result {
Ok(rocket)
}

fn rocket() -> Rocket<Build> {
#[tokio::main]
async fn start() -> Result<(), rocket::Error> {
rocket::build()
.attach(Db::init())
.attach(AdHoc::try_on_ignite("Migrations", run_migrations))
Expand All @@ -155,10 +155,13 @@ fn rocket() -> Rocket<Build> {
)
.register("/", catchers![not_found])
.attach(Template::fairing())
.launch()
.await
.map(|_| ())
}

pub fn main() {
let result = block_on(rocket().launch());
let result = start();

println!("Rocket: deorbit.");

Expand Down
20 changes: 10 additions & 10 deletions examples/rocket_example/core/src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl Mutation {
id: i32,
form_data: post::Model,
) -> Result<post::Model, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post::ActiveModel {
id: post.id,
Expand All @@ -38,11 +38,11 @@ impl Mutation {
}

pub async fn delete_post(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post.delete(db).await
}
Expand Down
20 changes: 10 additions & 10 deletions examples/salvo_example/core/src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl Mutation {
id: i32,
form_data: post::Model,
) -> Result<post::Model, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post::ActiveModel {
id: post.id,
Expand All @@ -38,11 +38,11 @@ impl Mutation {
}

pub async fn delete_post(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post.delete(db).await
}
Expand Down
20 changes: 10 additions & 10 deletions examples/tonic_example/core/src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl Mutation {
id: i32,
form_data: post::Model,
) -> Result<post::Model, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post::ActiveModel {
id: post.id,
Expand All @@ -38,11 +38,11 @@ impl Mutation {
}

pub async fn delete_post(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post.delete(db).await
}
Expand Down

0 comments on commit 5698638

Please sign in to comment.