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

Refactoring #3

Merged
merged 2 commits into from
Sep 21, 2022
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
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