Struct sql_query_builder::Values

source ·
pub struct Values { /* private fields */ }
Expand description

Builder to contruct a Values command

Implementations§

source§

impl Values

source

pub fn as_string(&self) -> String

Gets the current state of the Values and returns it as string

§Example
let values_query = sql::Values::new()
  .values("('foo', 'Foo')")
  .as_string();

Output

VALUES ('foo', 'Foo')
source

pub fn debug(self) -> Self

Prints the current state of the Values to the standard output in a more ease to read version. This method is useful to debug complex queries or just print the generated SQL while you type

§Example
let values = sql::Values::new()
  .values("(1, 'one'), (2, 'two')")
  .values("(3, 'three')")
  .debug();

Prints to the standard output

-- ------------------------------------------------------------------------------
VALUES (1, 'one'), (2, 'two'), (3, 'three')
-- ------------------------------------------------------------------------------
source

pub fn new() -> Self

Creates instance of the Values command

source

pub fn print(self) -> Self

Prints the current state of the Values to the standard output similar to debug method, the difference is that this method prints in one line.

source

pub fn raw(self, raw_sql: &str) -> Self

Adds at the beginning a raw SQL query.

§Example
let raw_query = "insert into my_table(num, txt)";

let values_query = sql::Values::new()
  .raw(raw_query)
  .values("(1, 'one'), (2, 'two')")
  .as_string();

Output

insert into my_table(num, txt)
VALUES (1, 'one'), (2, 'two')
source

pub fn raw_after(self, clause: ValuesClause, raw_sql: &str) -> Self

Adds a raw SQL query after a specified clause.

§Example
let raw_query = ", (3, 'three')";

let values_query = sql::Values::new()
  .values("(1, 'one'), (2, 'two')")
  .raw_after(sql::ValuesClause::Values, raw_query)
  .as_string();

Output

VALUES (1, 'one'), (2, 'two') , (3, 'three')
source

pub fn raw_before(self, clause: ValuesClause, raw_sql: &str) -> Self

Adds a raw SQL query before a specified clause.

§Example
let raw_query = "/* the values command */";

let values_query = sql::Values::new()
  .raw_before(sql::ValuesClause::Values, raw_query)
  .values("(1, 'one'), (2, 'two')")
  .as_string();

Output

/* the values command */
VALUES (1, 'one'), (2, 'two')
source

pub fn values(self, expression: &str) -> Self

The values clause

§Example
let values_query = sql::Values::new()
  .values("(1, 'one'), (2, 'two')")
  .values("(3, 'three')")
  .as_string();

Output

VALUES (1, 'one'), (2, 'two'), (3, 'three')

Trait Implementations§

source§

impl Clone for Values

source§

fn clone(&self) -> Values

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 Debug for Values

source§

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

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

impl Default for Values

source§

fn default() -> Values

Returns the “default value” for a type. Read more
source§

impl Display for Values

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Values

§

impl RefUnwindSafe for Values

§

impl Send for Values

§

impl Sync for Values

§

impl Unpin for Values

§

impl UnwindSafe for Values

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where 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 T
where 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 T
where 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 T
where 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.