Struct sea_orm::query::Insert [−][src]
pub struct Insert<A> where
A: ActiveModelTrait, { /* fields omitted */ }
Implementations
pub fn exec(
self,
db: &DatabaseConnection
) -> impl Future<Output = Result<InsertResult, DbErr>> + '_
Insert one Model or ActiveModel
Model
use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
assert_eq!(
Insert::one(cake::Model {
id: 1,
name: "Apple Pie".to_owned(),
})
.build(DbBackend::Postgres)
.to_string(),
r#"INSERT INTO "cake" ("id", "name") VALUES (1, 'Apple Pie')"#,
);
ActiveModel
use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
assert_eq!(
Insert::one(cake::ActiveModel {
id: Unset(None),
name: Set("Apple Pie".to_owned()),
})
.build(DbBackend::Postgres)
.to_string(),
r#"INSERT INTO "cake" ("name") VALUES ('Apple Pie')"#,
);
Insert many Model or ActiveModel
use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
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(),
r#"INSERT INTO "cake" ("id", "name") VALUES (1, 'Apple Pie'), (2, 'Orange Scone')"#,
);
pub fn add_many<M, I>(self, models: I) -> Self where
M: IntoActiveModel<A>,
I: IntoIterator<Item = M>,
Trait Implementations
type QueryStatement = InsertStatement
Get a mutable ref to the query builder
Get an immutable ref to the query builder
Take ownership of the query builder
Auto Trait Implementations
impl<A> !RefUnwindSafe for Insert<A>
impl<A> !UnwindSafe for Insert<A>
Blanket Implementations
Mutably borrows from an owned value. Read more
type Output = T
type Output = T
Should always be Self