Struct sea_orm::query::Insert [−][src]
pub struct Insert<A> where
A: ActiveModelTrait, { /* fields omitted */ }
Expand description
Performs INSERT operations on a ActiveModel
Implementations
pub fn exec<'a, C>(
self,
db: &'a C
) -> impl Future<Output = Result<InsertResult<A>, DbErr>> + '_ where
C: ConnectionTrait<'a>,
A: 'a,
pub fn exec<'a, C>(
self,
db: &'a C
) -> impl Future<Output = Result<InsertResult<A>, DbErr>> + '_ where
C: ConnectionTrait<'a>,
A: 'a,
Execute an insert operation
pub fn exec_with_returning<'a, C>(
self,
db: &'a C
) -> impl Future<Output = Result<A, DbErr>> + '_ where
<A::Entity as EntityTrait>::Model: IntoActiveModel<A>,
C: ConnectionTrait<'a>,
A: 'a,
pub fn exec_with_returning<'a, C>(
self,
db: &'a C
) -> impl Future<Output = Result<A, DbErr>> + '_ where
<A::Entity as EntityTrait>::Model: IntoActiveModel<A>,
C: ConnectionTrait<'a>,
A: 'a,
Execute an insert operation and return the inserted model (use RETURNING
syntax if database supported)
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')"#,
);
Add a Model to Self
pub fn add_many<M, I>(self, models: I) -> Self where
M: IntoActiveModel<A>,
I: IntoIterator<Item = M>,
pub fn add_many<M, I>(self, models: I) -> Self where
M: IntoActiveModel<A>,
I: IntoIterator<Item = M>,
Add many Models to Self
Trait Implementations
type QueryStatement = InsertStatement
type QueryStatement = InsertStatement
Constrain the QueryStatement to QueryStatementBuilder trait
Get a mutable ref to the query builder
Get an immutable ref to the query builder
Take ownership of the query builder