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>

source

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");
source

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>>

source

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>>

source

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>

source§

fn clone(&self) -> InsertInto<V>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<V: Debug + Values> Debug for InsertInto<V>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<V: Values> Display for InsertInto<V>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto 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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.