Skip to content

Commit

Permalink
fix: set transaction mode in single command
Browse files Browse the repository at this point in the history
  • Loading branch information
jreppnow committed Dec 13, 2024
1 parent 5d0efaa commit 2f9b392
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/driver/sqlx_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,19 @@ pub(crate) async fn set_transaction_config(
isolation_level: Option<IsolationLevel>,
access_mode: Option<AccessMode>,
) -> Result<(), DbErr> {
let mut settings = Vec::new();

if let Some(isolation_level) = isolation_level {
let stmt = Statement {
sql: format!("SET TRANSACTION ISOLATION LEVEL {isolation_level}"),
values: None,
db_backend: DbBackend::MySql,
};
let query = sqlx_query(&stmt);
conn.execute(query).await.map_err(sqlx_error_to_exec_err)?;
settings.push(format!("ISOLATION LEVEL {isolation_level}"));
}

if let Some(access_mode) = access_mode {
settings.push(access_mode.to_string());
}

if !settings.is_empty() {
let stmt = Statement {
sql: format!("SET TRANSACTION {access_mode}"),
sql: format!("SET TRANSACTION {}", settings.join(", ")),
values: None,
db_backend: DbBackend::MySql,
};
Expand Down

0 comments on commit 2f9b392

Please sign in to comment.