Struct diesel::query_builder::insert_statement::BatchInsertStatement
[−]
[src]
pub struct BatchInsertStatement<T, U, Op = Insert, Ret = NoReturningClause> { /* fields omitted */ }
The result of calling insert(records).into(some_table)
when records
is
a slice or a Vec
. When calling methods from ExecuteDsl
or LoadDsl
.
When the given slice is empty, this struct will not execute any queries.
When the given slice is not empty, this will execute a single bulk insert
on backends which support the DEFAULT
keyword, and one query per record
on backends which do not (SQLite).
Methods
impl<T, U, Op> BatchInsertStatement<T, U, Op>
[src]
fn returning<E>(self,
returns: E)
-> BatchInsertStatement<T, U, Op, ReturningClause<E>>
returns: E)
-> BatchInsertStatement<T, U, Op, ReturningClause<E>>
Specify what expression is returned after execution of the insert
.
Examples
Inserting records:
let new_users = vec![ NewUser { name: "Timmy".to_string(), }, NewUser { name: "Jimmy".to_string(), }, ]; let inserted_names = diesel::insert(&new_users) .into(users) .returning(name) .get_results(&connection); assert_eq!(Ok(vec!["Timmy".to_string(), "Jimmy".to_string()]), inserted_names);
Trait Implementations
impl<T: Copy, U: Copy, Op: Copy, Ret: Copy> Copy for BatchInsertStatement<T, U, Op, Ret>
[src]
impl<T: Clone, U: Clone, Op: Clone, Ret: Clone> Clone for BatchInsertStatement<T, U, Op, Ret>
[src]
fn clone(&self) -> BatchInsertStatement<T, U, Op, Ret>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<T: Debug, U: Debug, Op: Debug, Ret: Debug> Debug for BatchInsertStatement<T, U, Op, Ret>
[src]
impl<'a, T, U, Op, Ret, Conn, DB> ExecuteDsl<Conn, DB> for BatchInsertStatement<T, &'a [U], Op, Ret> where Conn: Connection<Backend=DB>,
DB: Backend + SupportsDefaultKeyword,
InsertStatement<T, &'a [U], Op, Ret>: ExecuteDsl<Conn>
[src]
DB: Backend + SupportsDefaultKeyword,
InsertStatement<T, &'a [U], Op, Ret>: ExecuteDsl<Conn>
fn execute(self, conn: &Conn) -> QueryResult<usize>
Executes the given command, returning the number of rows affected. Used in conjunction with update
and delete
Read more
impl<'a, T, U, Op, Ret> ExecuteDsl<SqliteConnection> for BatchInsertStatement<T, &'a [U], Op, Ret> where InsertStatement<T, &'a U, Op, Ret>: ExecuteDsl<SqliteConnection>,
T: Copy,
Op: Copy,
Ret: Copy
[src]
T: Copy,
Op: Copy,
Ret: Copy
fn execute(self, conn: &SqliteConnection) -> QueryResult<usize>
Executes the given command, returning the number of rows affected. Used in conjunction with update
and delete
Read more
impl<'a, T, U, Op, Ret, Conn, ST> LoadDsl<Conn> for BatchInsertStatement<T, &'a [U], Op, Ret> where Conn: Connection,
Conn::Backend: HasSqlType<ST>,
InsertStatement<T, &'a [U], Op, Ret>: LoadDsl<Conn, SqlType=ST>
[src]
Conn::Backend: HasSqlType<ST>,
InsertStatement<T, &'a [U], Op, Ret>: LoadDsl<Conn, SqlType=ST>
type SqlType = ST
fn load<V>(self, conn: &Conn) -> QueryResult<Vec<V>> where V: Queryable<Self::SqlType, Conn::Backend>
Executes the given query, returning an Iterator
over the returned rows. Read more
fn get_result<V>(self, conn: &Conn) -> QueryResult<V> where V: Queryable<Self::SqlType, Conn::Backend>
Runs the command, and returns the affected row. Err(NotFound)
will be returned if the query affected 0 rows. You can call .optional()
on the result of this if the command was optional to get back a Result<Option<U>>
Read more
fn first<U>(self, conn: &Conn) -> QueryResult<U> where Self: LimitDsl,
Limit<Self>: LoadDsl<Conn, SqlType=Self::SqlType>,
U: Queryable<Self::SqlType, Conn::Backend>
Limit<Self>: LoadDsl<Conn, SqlType=Self::SqlType>,
U: Queryable<Self::SqlType, Conn::Backend>
Attempts to load a single record. Returns Ok(record)
if found, and Err(NotFound)
if no results are returned. If the query truly is optional, you can call .optional()
on the result of this to get a Result<Option<U>>
. Read more
fn get_results<U>(self, conn: &Conn) -> QueryResult<Vec<U>> where U: Queryable<Self::SqlType, Conn::Backend>
Runs the command, returning an Iterator
over the affected rows.