Struct DropIndex

Source
pub struct DropIndex { /* private fields */ }
Expand description

Builder to contruct a DropIndex command. Available only for the crate features postgresql and sqlite.

Basic API

use sql_query_builder as sql;

let query = sql::DropIndex::new()
  .drop_index("users_name_idx")
  .as_string();

Output

DROP INDEX users_name_idx

Implementations§

Source§

impl DropIndex

Source

pub fn as_string(&self) -> String

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

§Example
let query = sql::DropIndex::new()
  .drop_index("users_name_idx")
  .as_string();

Output

DROP INDEX users_name_idx
Source

pub fn drop_index(self, index_name: &str) -> Self

Defines a drop index parameter, this method overrides the previous value

§Example 1
 let query = sql::DropIndex::new()
   .drop_index("users_name_idx")
   .drop_index("orders_product_name_idx")
   .as_string();

Outputs

DROP INDEX orders_product_name_idx
§Example 2 crate features postgresql only

Multiples call will concatenates all values

 let query = sql::DropIndex::new()
   .drop_index("users_name_idx")
   .drop_index("orders_product_name_idx")
   .as_string();

Outputs

DROP INDEX users_name_idx, orders_product_name_idx
Source

pub fn drop_index_if_exists(self, index_name: &str) -> Self

Defines a drop index parameter with the if exists modifier, this method overrides the previous value

§Example 1
let query = sql::DropIndex::new()
  .drop_index("users_name_idx")
  .drop_index_if_exists("orders_product_name_idx")
  .to_string();

Outputs

DROP INDEX IF EXISTS orders_product_name_idx
§Example 2 crate features postgresql only

Multiples call will concatenates all values

let query = sql::DropIndex::new()
  .drop_index("users_name_idx")
  .drop_index_if_exists("orders_product_name_idx")
  .to_string();

Outputs

DROP INDEX IF EXISTS users_name_idx, orders_product_name_idx
Source

pub fn debug(self) -> Self

Prints the current state of the DropIndex 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 query = sql::DropIndex::new()
  .drop_index("users_name_idx")
  .debug()
  .as_string();

Prints to the standard output

-- ------------------------------------------------------------------------------
DROP INDEX users_name_idx
-- ------------------------------------------------------------------------------
Source

pub fn new() -> Self

Creates instance of the DropIndex command

Source

pub fn print(self) -> Self

Prints the current state of the DropIndex 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. Is useful to create a more complex drop index command.

§Example
let drop_index_query = sql::DropIndex::new()
  .raw("/* drop index command */")
  .drop_index("users_name_idx")
  .as_string();

Output

/* drop index command */ DROP INDEX users_name_idx
Source

pub fn raw_after(self, param: DropIndexParams, raw_sql: &str) -> Self

Adds a raw SQL query after a specified parameter.

The DropIndexParams::DropIndex works both to .drop_index and .drop_index_if_exist methods

§Example
let query = sql::DropIndex::new()
  .drop_index("users_name_idx")
  .raw_after(sql::DropIndexParams::DropIndex, "/* end drop index */")
  .as_string();

Output

DROP INDEX users_name_idx /* end drop index */
Source

pub fn raw_before(self, param: DropIndexParams, raw_sql: &str) -> Self

Adds a raw SQL query before a specified parameter.

The DropIndexParams::DropIndex works both to .drop_index and .drop_index_if_exist methods

§Example
let raw = "/* drop index command */";

let query = sql::DropIndex::new()
  .raw_before(sql::DropIndexParams::DropIndex, raw)
  .drop_index("users_name_idx")
  .as_string();

Output

/* drop index command */ DROP INDEX users_name_idx

Trait Implementations§

Source§

impl Clone for DropIndex

Source§

fn clone(&self) -> DropIndex

Returns a duplicate 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 DropIndex

Source§

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

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

impl Default for DropIndex

Source§

fn default() -> DropIndex

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

impl Display for DropIndex

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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§

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

Source§

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

Source§

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.