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 more