Skip to content

Commit

Permalink
fix: set transaction mode in single command (#2450)
Browse files Browse the repository at this point in the history
  • Loading branch information
jreppnow authored Dec 23, 2024
1 parent 7dffaf1 commit 525ec30
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 525ec30

Please sign in to comment.