logo
pub struct Insert<A> where
    A: ActiveModelTrait
{ /* private fields */ }
Expand description

Performs INSERT operations on a ActiveModel

Implementations

Execute an insert operation

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: NotSet,
        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

Add many Models to Self

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

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

Build the query as Statement

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more