Struct scooby::postgres::statements::InsertInto
source · pub struct InsertInto<V: Values> { /* private fields */ }
Expand description
INSERT INTO
statement with a VALUES
clause, and possibly additional clauses.
Finalize and turn into String
by calling to_string
.
See insert_into
docs for more details and examples.
Implementations§
source§impl<V: Values> InsertInto<V>
impl<V: Values> InsertInto<V>
sourcepub fn returning(
self,
expressions: impl IntoIteratorOfSameType<OutputExpression>
) -> Self
pub fn returning( self, expressions: impl IntoIteratorOfSameType<OutputExpression> ) -> Self
Add one or more RETURNING
expressions.
use scooby::postgres::insert_into;
let sql = insert_into("Dummy")
.default_values()
.returning("id")
.returning(("width", "height"))
.to_string();
assert_eq!(sql, "INSERT INTO Dummy DEFAULT VALUES RETURNING id, width, height");
sourcepub fn on_conflict(self) -> OnConflictClauseBuilder<V>
pub fn on_conflict(self) -> OnConflictClauseBuilder<V>
Add an ON CONFLICT
clause to this statement.
Returns a OnConflictClauseBuilder
structure which requires you to specify
an action to do when a conflict happens using follow up methods.
use scooby::postgres::insert_into;
let sql = insert_into("Dummy")
.values(["a"])
.on_conflict()
.do_nothing()
.to_string();
assert_eq!(sql, "INSERT INTO Dummy VALUES (a) ON CONFLICT DO NOTHING");
source§impl<const N: usize> InsertInto<WithColumns<N>>
impl<const N: usize> InsertInto<WithColumns<N>>
sourcepub fn values<T: IntoNonZeroArray<Expression, N>>(
self,
new_values: impl IntoIterator<Item = T>
) -> Self
pub fn values<T: IntoNonZeroArray<Expression, N>>( self, new_values: impl IntoIterator<Item = T> ) -> Self
Add one or more sets of values.
use scooby::postgres::insert_into;
let sql = insert_into("Dummy")
.columns(("col1", "col2"))
.values([("$1", "$2")])
.values([("$3", "$4"), ("$5", "$6")])
.to_string();
assert_eq!(sql, "INSERT INTO Dummy (col1, col2) VALUES ($1, $2), ($3, $4), ($5, $6)");
source§impl<const N: usize> InsertInto<WithoutColumns<N>>
impl<const N: usize> InsertInto<WithoutColumns<N>>
sourcepub fn values<T: IntoNonZeroArray<Expression, N>>(
self,
new_values: impl IntoIterator<Item = T>
) -> Self
pub fn values<T: IntoNonZeroArray<Expression, N>>( self, new_values: impl IntoIterator<Item = T> ) -> Self
Add one or more sets of values.
use scooby::postgres::insert_into;
let sql = insert_into("Dummy")
.values([("$1", "$2")])
.values([("$3", "$4"), ("$5", "$6")])
.to_string();
assert_eq!(sql, "INSERT INTO Dummy VALUES ($1, $2), ($3, $4), ($5, $6)");
Trait Implementations§
source§impl<V: Clone + Values> Clone for InsertInto<V>
impl<V: Clone + Values> Clone for InsertInto<V>
source§fn clone(&self) -> InsertInto<V>
fn clone(&self) -> InsertInto<V>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl<V> RefUnwindSafe for InsertInto<V>where V: RefUnwindSafe,
impl<V> Send for InsertInto<V>where V: Send,
impl<V> Sync for InsertInto<V>where V: Sync,
impl<V> Unpin for InsertInto<V>where V: Unpin,
impl<V> UnwindSafe for InsertInto<V>where V: UnwindSafe,
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