pub struct CreateIndex { /* private fields */ }Expand description
Builder to contruct a CreateIndex command. Available only for the crate features postgresql and sqlite
Basic API
use sql_query_builder as sql;
let query = sql::CreateIndex::new()
.create_index("users_name_idx")
.on("users")
.column("name")
.as_string();
Output
CREATE INDEX users_name_idx ON users (name)Implementations§
source§impl CreateIndex
impl CreateIndex
sourcepub fn as_string(&self) -> String
pub fn as_string(&self) -> String
Gets the current state of the CreateIndex and returns it as string
§Example
let query = sql::CreateIndex::new()
.create_index("users_name_idx")
.as_string();
Output
CREATE INDEX users_name_idxsourcepub fn column(self, column_name: &str) -> Self
pub fn column(self, column_name: &str) -> Self
Defines the column of the table used to create the index
§Example
let query = sql::CreateIndex::new()
.on("users")
.column("login")
.column("name")
.as_string();
Outputs
ON users (login, name)sourcepub fn create_index(self, index_name: &str) -> Self
pub fn create_index(self, index_name: &str) -> Self
Defines a create index parameter, this method overrides the previous value
§Example
let query = sql::CreateIndex::new()
.create_index("users_name_idx")
.create_index("orders_product_name_idx")
.as_string();
Outputs
CREATE INDEX orders_product_name_idxsourcepub fn create_index_if_not_exists(self, index_name: &str) -> Self
pub fn create_index_if_not_exists(self, index_name: &str) -> Self
Defines a create index parameter with the if not exists modifier, this method overrides the previous value
§Example
let query = sql::CreateIndex::new()
.create_index("users_name_idx")
.create_index_if_not_exists("orders_product_name_idx")
.to_string();
Outputs
CREATE INDEX IF NOT EXISTS orders_product_name_idxsourcepub fn debug(self) -> Self
pub fn debug(self) -> Self
Prints the current state of the CreateIndex 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::CreateIndex::new()
.create_index("users_name_idx")
.on("users")
.column("name")
.debug()
.as_string();
Prints to the standard output
-- ------------------------------------------------------------------------------
CREATE INDEX users_name_idx
ON users (name)
-- ------------------------------------------------------------------------------sourcepub fn new() -> Self
pub fn new() -> Self
Creates instance of the CreateIndex command
sourcepub fn on(self, table_name: &str) -> Self
pub fn on(self, table_name: &str) -> Self
Defines the on table_name clause, this method overrides the previous value
§Example
let query = sql::CreateIndex::new()
.on("users")
.on("orders")
.as_string();
Outputs
ON orderssourcepub fn print(self) -> Self
pub fn print(self) -> Self
Prints the current state of the CreateIndex to the standard output similar to debug method, the difference is that this method prints in one line.
sourcepub fn raw(self, raw_sql: &str) -> Self
pub fn raw(self, raw_sql: &str) -> Self
Adds at the beginning a raw SQL query. Is useful to create a more complex create index command.
§Example
let create_index_query = sql::CreateIndex::new()
.raw("/* start index command */")
.create_index("users_name_idx")
.as_string();
Output
/* start index command */ CREATE INDEX users_name_idxsourcepub fn raw_after(self, param: CreateIndexParams, raw_sql: &str) -> Self
pub fn raw_after(self, param: CreateIndexParams, raw_sql: &str) -> Self
Adds a raw SQL query after a specified parameter.
The CreateIndexParams::CreateIndex works both to .create_index and .create_index_if_not_exists methods.
§Example
let raw = "/* after create index */";
let query = sql::CreateIndex::new()
.create_index("users_name_idx")
.raw_after(sql::CreateIndexParams::CreateIndex, raw)
.on("users")
.column("name")
.as_string();
Output
CREATE INDEX users_name_idx
/* after create index */
ON users (name)sourcepub fn raw_before(self, param: CreateIndexParams, raw_sql: &str) -> Self
pub fn raw_before(self, param: CreateIndexParams, raw_sql: &str) -> Self
Adds a raw SQL query before a specified parameter.
The CreateIndexParams::CreateIndex works both to .create_index and .create_index_if_not_exists methods.
§Example
let raw = "/* before create index */";
let query = sql::CreateIndex::new()
.raw_before(sql::CreateIndexParams::CreateIndex, raw)
.create_index("users_name_idx")
.on("users")
.column("name")
.as_string();
Output
/* before create index */
CREATE INDEX users_name_idx
ON users (name)sourcepub fn unique(self) -> Self
pub fn unique(self) -> Self
Defines the unique parameter
§Example
let query = sql::CreateIndex::new()
.create_index("users_name_idx")
.unique()
.to_string();
Outputs
CREATE UNIQUE INDEX users_name_idxsourcepub fn where_and(self, condition: &str) -> Self
pub fn where_and(self, condition: &str) -> Self
The method will concatenate multiples calls using the and operator. This method is un alias of where_clause.
§Example
let select_query = sql::CreateIndex::new()
.create_index("users_name_idx")
.on("users")
.column("name")
.where_and("created_at >= $1")
.as_string();
Outputs
CREATE INDEX users_name_idx
ON users (name)
WHERE created_at >= $1sourcepub fn where_clause(self, condition: &str) -> Self
pub fn where_clause(self, condition: &str) -> Self
The where clause, this method will concatenate multiples calls using the and operator.
If you intended to use the or operator you should use the where_or method
§Example
let select_query = sql::CreateIndex::new()
.create_index("users_name_idx")
.on("users")
.column("name")
.where_clause("status = 'active'")
.as_string();
Outputs
CREATE INDEX users_name_idx
ON users (name)
WHERE status = 'active'sourcepub fn where_or(self, condition: &str) -> Self
pub fn where_or(self, condition: &str) -> Self
The where clause that concatenate multiples calls using the OR operator.
If you intended to use the and operator you should use the where_clause method
§Example
let select_query = sql::CreateIndex::new()
.create_index("users_name_idx")
.on("users")
.column("name")
.where_clause("created_at >= $1")
.where_or("status = 'active'")
.as_string();
Outputs
CREATE INDEX users_name_idx
ON users (name)
WHERE
created_at >= $1
OR status = 'active'source§impl CreateIndex
impl CreateIndex
sourcepub fn concurrently(self) -> Self
Available on crate feature postgresql only.
pub fn concurrently(self) -> Self
postgresql only.Defines the concurrently parameter
§Example
let query = sql::CreateIndex::new()
.create_index("users_name_idx")
.concurrently()
.to_string();
Outputs
CREATE INDEX CONCURRENTLY users_name_idxsourcepub fn include(self, column_name: &str) -> Self
Available on crate feature postgresql only.
pub fn include(self, column_name: &str) -> Self
postgresql only.Defines the include parameter
§Example
let query = sql::CreateIndex::new()
.include("login")
.include("name")
.as_string();
Outputs
INCLUDE (login, name)sourcepub fn only(self) -> Self
Available on crate feature postgresql only.
pub fn only(self) -> Self
postgresql only.Defines the only parameter
§Example
let query = sql::CreateIndex::new()
.on("users")
.only()
.to_string();
Outputs
ON ONLY userssourcepub fn using(self, index_method: &str) -> Self
Available on crate feature postgresql only.
pub fn using(self, index_method: &str) -> Self
postgresql only.Defines the index method to be used to create the index, this method overrides the previous value
§Example
let query = sql::CreateIndex::new()
.using("btree")
.using("gist")
.as_string();
Outputs
USING gistTrait Implementations§
source§impl Clone for CreateIndex
impl Clone for CreateIndex
source§fn clone(&self) -> CreateIndex
fn clone(&self) -> CreateIndex
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for CreateIndex
impl Debug for CreateIndex
source§impl Default for CreateIndex
impl Default for CreateIndex
source§fn default() -> CreateIndex
fn default() -> CreateIndex
Auto Trait Implementations§
impl Freeze for CreateIndex
impl RefUnwindSafe for CreateIndex
impl Send for CreateIndex
impl Sync for CreateIndex
impl Unpin for CreateIndex
impl UnwindSafe for CreateIndex
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)