Skip to main content

ModelInsert

Trait ModelInsert 

Source
pub trait ModelInsert: Sized {
    type Model: Model;

    // Required method
    fn insert(self, conn: &mut SqliteConnection) -> QueryResult<Self::Model>;

    // Provided method
    fn insert_all(
        conn: &mut SqliteConnection,
        items: Vec<Self>,
    ) -> QueryResult<Vec<Self::Model>> { ... }
}
Expand description

A trait for models that support insertion operations.

This trait provides methods for inserting individual and multiple records into the database.

§Type Parameters

  • Model: The associated model type that implements the Model trait.

§Methods

  • insert: Inserts a new record into the database table.
  • insert_all: Inserts multiple records into the database table.

Required Associated Types§

Source

type Model: Model

The associated model type that implements the Model trait.

Required Methods§

Source

fn insert(self, conn: &mut SqliteConnection) -> QueryResult<Self::Model>

Inserts a new record into the database table.

§Arguments
  • conn: A mutable reference to the database connection.
§Returns

A QueryResult containing the inserted Model record.

Provided Methods§

Source

fn insert_all( conn: &mut SqliteConnection, items: Vec<Self>, ) -> QueryResult<Vec<Self::Model>>

Inserts multiple records into the database table.

Insert in input order within one transaction. A failure rolls back the entire batch.

§Arguments
  • conn: A mutable reference to the database connection.
  • items: A vector of records to insert.
§Returns

A QueryResult containing a vector of the inserted Model records.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§