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 theModeltrait.
§Methods
insert: Inserts a new record into the database table.insert_all: Inserts multiple records into the database table.
Required Associated Types§
Required Methods§
Sourcefn insert(self, conn: &mut SqliteConnection) -> QueryResult<Self::Model>
fn insert(self, conn: &mut SqliteConnection) -> QueryResult<Self::Model>
Provided Methods§
Sourcefn insert_all(
conn: &mut SqliteConnection,
items: Vec<Self>,
) -> QueryResult<Vec<Self::Model>>
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".