ActiveModel.insert return ActiveModel instead of InsertResult? #215
Answered
by
tyt2y3
duskmoon314
asked this question in
Q&A
-
Hi, I'm new to sea-orm and trying to build a RESTful rocket app. In the doc, let pear = fruit::ActiveModel {
name: Set("Pear".to_owned()),
..Default::default() // all other attributes are `Unset`
};
let res: InsertResult = pear.insert(db).await?;
assert_eq!(res.last_insert_id, 28) I'm using sea-orm 0.2 and come across some problems sea-orm = { version = "0.2", features = [
"sqlx-postgres",
"runtime-tokio-rustls",
"macros",
], default-features = false } #[post("/", data = "<code>", format = "json")]
pub async fn create(
mut db: Connection<DB>,
code: Json<code::Model>,
) -> Result<Json<Uuid>, status::Conflict<DbErr>> {
let code = code.into_inner();
let code = code::ActiveModel {
language: Set(code.language.to_owned()),
content: Set(code.content.to_owned()),
..Default::default()
};
match code.insert(&db).await {
Ok(res) => { /* res is ActiveModel here */ }
Err(e) => status::Conflict(e),
}
} So I get an |
Beta Was this translation helpful? Give feedback.
Answered by
tyt2y3
Sep 29, 2021
Replies: 2 comments
-
The Entity::insert function is still there. https://docs.rs/sea-orm/0.2.3/sea_orm/entity/prelude/trait.EntityTrait.html#method.insert |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
tyt2y3
-
@tyt2y3 Thanks! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Entity::insert function is still there.
https://docs.rs/sea-orm/0.2.3/sea_orm/entity/prelude/trait.EntityTrait.html#method.insert