pub struct CreateMany<M>where
M: Model,{ /* private fields */ }Expand description
A builder for inserting multiple records of the same model in a single statement.
Records are accumulated with item or
with_item, then executed with
exec. Alternatively, call
into_expr to embed the batch insert as an
expression inside another statement (e.g., a has-many association insert).
§Examples
use toasty::stmt::CreateMany;
let users = CreateMany::<User>::new()
.with_item(|u| u.name("Alice"))
.with_item(|u| u.name("Bob"))
.exec(&mut db)
.await
.unwrap();
assert_eq!(users.len(), 2);Implementations§
Source§impl<M> CreateMany<M>where
M: Model,
impl<M> CreateMany<M>where
M: Model,
Sourcepub fn new() -> CreateMany<M>
pub fn new() -> CreateMany<M>
Create an empty CreateMany builder with no records queued.
Sourcepub fn item(self, item: impl IntoInsert<Model = M>) -> CreateMany<M>
pub fn item(self, item: impl IntoInsert<Model = M>) -> CreateMany<M>
Append a record from any value that implements IntoInsert
for model M.
Returns self for method chaining.
Sourcepub fn with_item(
self,
f: impl FnOnce(<M as Model>::Create) -> <M as Model>::Create,
) -> CreateMany<M>
pub fn with_item( self, f: impl FnOnce(<M as Model>::Create) -> <M as Model>::Create, ) -> CreateMany<M>
Append a record using a closure that configures the model’s generated create builder.
f receives a default create builder and must return it after setting
the desired fields.
Returns self for method chaining.
Trait Implementations§
Source§impl<M> Default for CreateMany<M>where
M: Model,
impl<M> Default for CreateMany<M>where
M: Model,
Source§fn default() -> CreateMany<M>
fn default() -> CreateMany<M>
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl<M> Freeze for CreateMany<M>
impl<M> RefUnwindSafe for CreateMany<M>
impl<M> Send for CreateMany<M>
impl<M> Sync for CreateMany<M>
impl<M> Unpin for CreateMany<M>
impl<M> UnsafeUnpin for CreateMany<M>
impl<M> UnwindSafe for CreateMany<M>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more