Skip to content

Commit bb92d38

Browse files
authored
Merge pull request #52 from belchior/mysql-transaction
Adds MySQL syntax to Transaction builder
2 parents dbb97ff + 2c81c22 commit bb92d38

File tree

6 files changed

+346
-163
lines changed

6 files changed

+346
-163
lines changed

scripts/coverage_test.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ echo "\n-- ---------------------------------------------------------------------
2727
echo "-- Testing SQLite syntax"
2828
echo "-- ------------------------------------------------------------------------------\n"
2929
RUSTFLAGS="-C instrument-coverage" LLVM_PROFILE_FILE="$COVERAGE_TARGET/$PKG_NAME-%m.profraw" cargo test --target-dir $COVERAGE_TARGET --features sqlite;
30-
RUSTFLAGS="-C instrument-coverage" LLVM_PROFILE_FILE="$COVERAGE_TARGET/$PKG_NAME-%m.profraw" cargo test --target-dir $COVERAGE_TARGET --features mysql;
3130

3231
echo "\n-- ------------------------------------------------------------------------------"
3332
echo "-- Testing MySQL syntax"

src/structure.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ pub enum SelectClause {
695695
/// # }
696696
/// ```
697697
///
698-
/// Output (indented for readability)
698+
/// Output
699699
///
700700
/// ```sql
701701
/// START TRANSACTION isolation level serializable;
@@ -711,7 +711,7 @@ pub struct Transaction {
711711
pub(crate) _set_transaction: Option<TransactionCommand>,
712712
pub(crate) _start_transaction: Option<TransactionCommand>,
713713

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

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

729-
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
729+
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
730730
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
731731
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
732+
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
732733
Begin,
733734

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

739740
#[cfg(not(feature = "sqlite"))]
740741
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
742+
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
741743
SetTransaction,
742744

743745
#[cfg(not(feature = "sqlite"))]
744746
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
747+
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
745748
StartTransaction,
746749
}
747750

src/transaction/transaction.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
utils::push_unique,
88
};
99

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

1313
impl Transaction {
@@ -46,8 +46,6 @@ impl Transaction {
4646
/// # Example
4747
///
4848
/// ```
49-
/// # #[cfg(not(feature = "sqlite"))]
50-
/// # {
5149
/// # use sql_query_builder as sql;
5250
/// let transaction_query = sql::Transaction::new()
5351
/// .commit("WORK")
@@ -56,7 +54,6 @@ impl Transaction {
5654
///
5755
/// # let expected = "COMMIT TRANSACTION;";
5856
/// # assert_eq!(transaction_query, expected);
59-
/// # }
6057
/// ```
6158
///
6259
/// Output
@@ -596,9 +593,10 @@ impl Transaction {
596593
}
597594
}
598595

599-
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
596+
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
600597
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
601598
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
599+
#[cfg_attr(docsrs, doc(cfg(feature = "mysql")))]
602600
impl Transaction {
603601
/// The `begin` command, this method will be always added at the beginning of the transation and
604602
/// all consecutive call will override the previous value.
@@ -710,7 +708,12 @@ impl Transaction {
710708
self._ordered_commands.push(cmd);
711709
self
712710
}
711+
}
713712

713+
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
714+
#[cfg_attr(docsrs, doc(cfg(feature = "postgresql")))]
715+
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
716+
impl Transaction {
714717
/// The `end` command, this method will be always added at the end of the transation and
715718
/// all consecutive call will override the previous value.
716719
///

src/transaction/transaction_internal.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl Concat for Transaction {
1616

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

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

55-
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
55+
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
5656
Begin => format!("BEGIN{arg}"),
5757
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
5858
End => format!("END{arg}"),
@@ -117,7 +117,7 @@ impl TransactionCommand {
117117
}
118118
}
119119

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

129129
format!("{query}{sql}")
130130
}
131+
}
131132

133+
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
134+
impl Transaction {
132135
fn concat_end(&self, query: String, fmts: &fmt::Formatter) -> String {
133136
let fmt::Formatter { lb, space, .. } = fmts;
134137
let sql = match &self._end {

tests/command_begin_spec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg(any(feature = "postgresql", feature = "sqlite"))]
1+
#[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql"))]
22
mod begin_command {
33
use pretty_assertions::assert_eq;
44
use sql_query_builder as sql;

0 commit comments

Comments
 (0)