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
1 change: 0 additions & 1 deletion scripts/coverage_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ echo "\n-- ---------------------------------------------------------------------
echo "-- Testing SQLite syntax"
echo "-- ------------------------------------------------------------------------------\n"
RUSTFLAGS="-C instrument-coverage" LLVM_PROFILE_FILE="$COVERAGE_TARGET/$PKG_NAME-%m.profraw" cargo test --target-dir $COVERAGE_TARGET --features sqlite;
RUSTFLAGS="-C instrument-coverage" LLVM_PROFILE_FILE="$COVERAGE_TARGET/$PKG_NAME-%m.profraw" cargo test --target-dir $COVERAGE_TARGET --features mysql;

echo "\n-- ------------------------------------------------------------------------------"
echo "-- Testing MySQL syntax"
Expand Down
9 changes: 6 additions & 3 deletions src/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ pub enum SelectClause {
/// # }
/// ```
///
/// Output (indented for readability)
/// Output
///
/// ```sql
/// START TRANSACTION isolation level serializable;
Expand All @@ -711,7 +711,7 @@ pub struct Transaction {
pub(crate) _set_transaction: Option<TransactionCommand>,
pub(crate) _start_transaction: Option<TransactionCommand>,

#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
pub(crate) _begin: Option<TransactionCommand>,

#[cfg(any(feature = "postgresql", feature = "sqlite"))]
Expand All @@ -726,9 +726,10 @@ pub(crate) enum TrCmd {
Rollback,
Savepoint,

#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
Begin,

#[cfg(any(feature = "postgresql", feature = "sqlite"))]
Expand All @@ -738,10 +739,12 @@ pub(crate) enum TrCmd {

#[cfg(not(feature = "sqlite"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
SetTransaction,

#[cfg(not(feature = "sqlite"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
StartTransaction,
}

Expand Down
13 changes: 8 additions & 5 deletions src/transaction/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
utils::push_unique,
};

#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
use crate::structure::{CreateIndex, DropIndex};

impl Transaction {
Expand Down Expand Up @@ -46,8 +46,6 @@ impl Transaction {
/// # Example
///
/// ```
/// # #[cfg(not(feature = "sqlite"))]
/// # {
/// # use sql_query_builder as sql;
/// let transaction_query = sql::Transaction::new()
/// .commit("WORK")
Expand All @@ -56,7 +54,6 @@ impl Transaction {
///
/// # let expected = "COMMIT TRANSACTION;";
/// # assert_eq!(transaction_query, expected);
/// # }
/// ```
///
/// Output
Expand Down Expand Up @@ -596,9 +593,10 @@ impl Transaction {
}
}

#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
impl Transaction {
/// The `begin` command, this method will be always added at the beginning of the transation and
/// all consecutive call will override the previous value.
Expand Down Expand Up @@ -710,7 +708,12 @@ impl Transaction {
self._ordered_commands.push(cmd);
self
}
}

#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
impl Transaction {
/// The `end` command, this method will be always added at the end of the transation and
/// all consecutive call will override the previous value.
///
Expand Down
9 changes: 6 additions & 3 deletions src/transaction/transaction_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Concat for Transaction {

query = self.concat_raw(query, &fmts, &self._raw);

#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
{
query = self.concat_begin(query, &fmts);
}
Expand Down Expand Up @@ -52,7 +52,7 @@ impl Concat for TransactionCommand {
Rollback => format!("ROLLBACK{arg}"),
Savepoint => format!("SAVEPOINT{arg}"),

#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
Begin => format!("BEGIN{arg}"),
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
End => format!("END{arg}"),
Expand Down Expand Up @@ -117,7 +117,7 @@ impl TransactionCommand {
}
}

#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
impl Transaction {
fn concat_begin(&self, query: String, fmts: &fmt::Formatter) -> String {
let fmt::Formatter { lb, space, .. } = fmts;
Expand All @@ -128,7 +128,10 @@ impl Transaction {

format!("{query}{sql}")
}
}

#[cfg(any(feature = "postgresql", feature = "sqlite"))]
impl Transaction {
fn concat_end(&self, query: String, fmts: &fmt::Formatter) -> String {
let fmt::Formatter { lb, space, .. } = fmts;
let sql = match &self._end {
Expand Down
2 changes: 1 addition & 1 deletion tests/command_begin_spec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
mod begin_command {
use pretty_assertions::assert_eq;
use sql_query_builder as sql;
Expand Down
Loading
Loading