Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 59 additions & 54 deletions src/drop_index/drop_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl DropIndex {
/// ### Example 1
///
///```
/// # #[cfg(not(feature = "postgresql"))]
/// # #[cfg(any(feature = "sqlite", feature = "mysql"))]
/// # {
/// # use sql_query_builder as sql;
/// let query = sql::DropIndex::new()
Expand Down Expand Up @@ -85,59 +85,6 @@ impl DropIndex {
self
}

/// Defines a drop index parameter with the `if exists` modifier, this method overrides the previous value
///
/// ### Example 1
///
/// ```
/// # #[cfg(not(feature = "postgresql"))]
/// # {
/// # use sql_query_builder as sql;
/// let query = sql::DropIndex::new()
/// .drop_index("users_name_idx")
/// .drop_index_if_exists("orders_product_name_idx")
/// .to_string();
///
/// # let expected = "DROP INDEX IF EXISTS orders_product_name_idx";
/// # assert_eq!(expected, query);
/// # }
/// ```
///
/// Outputs
///
/// ```sql
/// DROP INDEX IF EXISTS orders_product_name_idx
/// ```
///
/// ### Example 2 `crate features postgresql only`
///
/// Multiples call will concatenates all values
///
/// ```
/// # #[cfg(feature = "postgresql")]
/// # {
/// # use sql_query_builder as sql;
/// let query = sql::DropIndex::new()
/// .drop_index("users_name_idx")
/// .drop_index_if_exists("orders_product_name_idx")
/// .to_string();
///
/// # let expected = "DROP INDEX IF EXISTS users_name_idx, orders_product_name_idx";
/// # assert_eq!(expected, query);
/// # }
/// ```
///
/// Outputs
///
/// ```sql
/// DROP INDEX IF EXISTS users_name_idx, orders_product_name_idx
/// ```
pub fn drop_index_if_exists(mut self, index_name: &str) -> Self {
push_unique(&mut self._drop_index, index_name.trim().to_string());
self._if_exists = true;
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
///
Expand Down Expand Up @@ -259,6 +206,64 @@ impl DropIndex {
}
}

#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
impl DropIndex {
/// Defines a drop index parameter with the `if exists` modifier, this method overrides the previous value
///
/// ### Example 1
///
/// ```
/// # #[cfg(feature = "sqlite")]
/// # {
/// # use sql_query_builder as sql;
/// let query = sql::DropIndex::new()
/// .drop_index("users_name_idx")
/// .drop_index_if_exists("orders_product_name_idx")
/// .to_string();
///
/// # let expected = "DROP INDEX IF EXISTS orders_product_name_idx";
/// # assert_eq!(expected, query);
/// # }
/// ```
///
/// Outputs
///
/// ```sql
/// DROP INDEX IF EXISTS orders_product_name_idx
/// ```
///
/// ### Example 2 `crate features postgresql only`
///
/// Multiples call will concatenates all values
///
/// ```
/// # #[cfg(feature = "postgresql")]
/// # {
/// # use sql_query_builder as sql;
/// let query = sql::DropIndex::new()
/// .drop_index("users_name_idx")
/// .drop_index_if_exists("orders_product_name_idx")
/// .to_string();
///
/// # let expected = "DROP INDEX IF EXISTS users_name_idx, orders_product_name_idx";
/// # assert_eq!(expected, query);
/// # }
/// ```
///
/// Outputs
///
/// ```sql
/// DROP INDEX IF EXISTS users_name_idx, orders_product_name_idx
/// ```
pub fn drop_index_if_exists(mut self, index_name: &str) -> Self {
push_unique(&mut self._drop_index, index_name.trim().to_string());
self._if_exists = true;
self
}
}

impl std::fmt::Display for DropIndex {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.as_string())
Expand Down
6 changes: 2 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ pub use crate::structure::{

#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
mod create_index;
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
mod drop_index;

#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
pub use crate::structure::{CreateIndex, CreateIndexParams};
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
pub use crate::structure::{DropIndex, DropIndexParams};
pub use crate::structure::{CreateIndex, CreateIndexParams, DropIndex, DropIndexParams};
8 changes: 4 additions & 4 deletions src/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,12 @@ pub enum DeleteClause {
Partition,
}

/// Builder to contruct a [DropIndex] command. Available only for the crate features `postgresql` and `sqlite`.
/// Builder to contruct a [DropIndex] command. Available only for the crate features `postgresql` and `sqlite` and `mysql`.
///
/// Basic API
///
/// ```
/// # #[cfg(any(feature = "postgresql", feature = "sqlite"))]
/// # #[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
/// # {
/// use sql_query_builder as sql;
///
Expand All @@ -354,7 +354,7 @@ pub enum DeleteClause {
/// ```sql
/// DROP INDEX users_name_idx
/// ```
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
#[derive(Default, Clone)]
pub struct DropIndex {
pub(crate) _drop_index: Vec<String>,
Expand All @@ -365,7 +365,7 @@ pub struct DropIndex {
}

/// All available params to be used in [DropIndex::raw_before] and [DropIndex::raw_after] methods on [DropIndex] builder
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
#[derive(PartialEq, Clone)]
pub enum DropIndexParams {
DropIndex,
Expand Down
Loading