Skip to content

Commit

Permalink
fix: resolve linter issues from cargo fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Lucian Buzzo <[email protected]>
  • Loading branch information
LucianBuzzo committed Oct 29, 2023
1 parent ce52e1d commit adb2a13
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 52 deletions.
17 changes: 7 additions & 10 deletions quaint/src/connector/mssql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::{
use async_trait::async_trait;
use connection_string::JdbcString;
use futures::lock::Mutex;
use std::sync::Arc;
use std::{
convert::TryFrom,
fmt,
Expand All @@ -22,7 +23,6 @@ use std::{
use tiberius::*;
use tokio::net::TcpStream;
use tokio_util::compat::{Compat, TokioAsyncWriteCompatExt};
use std::sync::Arc;

/// The underlying SQL Server driver. Only available with the `expose-drivers` Cargo feature.
#[cfg(feature = "expose-drivers")]
Expand Down Expand Up @@ -116,17 +116,14 @@ impl TransactionCapable for Mssql {
let rollback_stmt = self.rollback_statement(st_depth).await;

let opts = TransactionOptions::new(
isolation,
isolation,
self.requires_isolation_first(),
self.transaction_depth.clone(),
commit_stmt,
rollback_stmt,
);


Ok(Box::new(
DefaultTransaction::new(self, &begin_statement, opts).await?,
))
Ok(Box::new(DefaultTransaction::new(self, &begin_statement, opts).await?))
}
}

Expand Down Expand Up @@ -470,20 +467,20 @@ impl Queryable for Mssql {
"BEGIN TRAN".to_string()
};

return ret
return ret;
}

/// Statement to commit a transaction
async fn commit_statement(&self, depth: i32) -> String {
// MSSQL doesn't have a "RELEASE SAVEPOINT" equivalent, so in a nested
// MSSQL doesn't have a "RELEASE SAVEPOINT" equivalent, so in a nested
// transaction we just continue onwards
let ret = if depth > 1 {
" ".to_string()
} else {
"COMMIT".to_string()
};

return ret
return ret;
}

/// Statement to rollback a transaction
Expand All @@ -495,7 +492,7 @@ impl Queryable for Mssql {
"ROLLBACK".to_string()
};

return ret
return ret;
}

fn requires_isolation_first(&self) -> bool {
Expand Down
14 changes: 5 additions & 9 deletions quaint/src/connector/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use mysql_async::{
prelude::{Query as _, Queryable as _},
};
use percent_encoding::percent_decode;
use std::sync::Arc;
use std::{
borrow::Cow,
future::Future,
Expand All @@ -23,7 +24,6 @@ use std::{
};
use tokio::sync::Mutex;
use url::{Host, Url};
use std::sync::Arc;

/// The underlying MySQL driver. Only available with the `expose-drivers`
/// Cargo feature.
Expand Down Expand Up @@ -588,13 +588,9 @@ impl Queryable for Mysql {
/// Statement to begin a transaction
async fn begin_statement(&self, depth: i32) -> String {
let savepoint_stmt = format!("SAVEPOINT savepoint{}", depth);
let ret = if depth > 1 {
savepoint_stmt
} else {
"BEGIN".to_string()
};
let ret = if depth > 1 { savepoint_stmt } else { "BEGIN".to_string() };

return ret
return ret;
}

/// Statement to commit a transaction
Expand All @@ -606,7 +602,7 @@ impl Queryable for Mysql {
"COMMIT".to_string()
};

return ret
return ret;
}

/// Statement to rollback a transaction
Expand All @@ -618,7 +614,7 @@ impl Queryable for Mysql {
"ROLLBACK".to_string()
};

return ret
return ret;
}
}

Expand Down
14 changes: 5 additions & 9 deletions quaint/src/connector/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use lru_cache::LruCache;
use native_tls::{Certificate, Identity, TlsConnector};
use percent_encoding::percent_decode;
use postgres_native_tls::MakeTlsConnector;
use std::sync::Arc;
use std::{
borrow::{Borrow, Cow},
fmt::{Debug, Display},
Expand All @@ -26,7 +27,6 @@ use tokio_postgres::{
Client, Config, Statement,
};
use url::{Host, Url};
use std::sync::Arc;

pub(crate) const DEFAULT_SCHEMA: &str = "public";

Expand Down Expand Up @@ -937,13 +937,9 @@ impl Queryable for PostgreSql {
/// Statement to begin a transaction
async fn begin_statement(&self, depth: i32) -> String {
let savepoint_stmt = format!("SAVEPOINT savepoint{}", depth);
let ret = if depth > 1 {
savepoint_stmt
} else {
"BEGIN".to_string()
};
let ret = if depth > 1 { savepoint_stmt } else { "BEGIN".to_string() };

return ret
return ret;
}

/// Statement to commit a transaction
Expand All @@ -955,7 +951,7 @@ impl Queryable for PostgreSql {
"COMMIT".to_string()
};

return ret
return ret;
}

/// Statement to rollback a transaction
Expand All @@ -967,7 +963,7 @@ impl Queryable for PostgreSql {
"ROLLBACK".to_string()
};

return ret
return ret;
}
}

Expand Down
4 changes: 1 addition & 3 deletions quaint/src/connector/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,8 @@ macro_rules! impl_default_TransactionCapable {
let commit_stmt = self.commit_statement(st_depth).await;
let rollback_stmt = self.rollback_statement(st_depth).await;



let opts = crate::connector::TransactionOptions::new(
isolation,
isolation,
self.requires_isolation_first(),
depth,
commit_stmt,
Expand Down
16 changes: 6 additions & 10 deletions quaint/src/connector/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use crate::{
visitor::{self, Visitor},
};
use async_trait::async_trait;
use std::sync::Arc;
use std::{convert::TryFrom, path::Path, time::Duration};
use tokio::sync::Mutex;
use std::sync::Arc;

pub(crate) const DEFAULT_SQLITE_SCHEMA_NAME: &str = "main";

Expand Down Expand Up @@ -141,7 +141,7 @@ impl TryFrom<&str> for Sqlite {

let client = Mutex::new(conn);

Ok(Sqlite {
Ok(Sqlite {
client,
transaction_depth: Arc::new(futures::lock::Mutex::new(0)),
})
Expand Down Expand Up @@ -260,13 +260,9 @@ impl Queryable for Sqlite {
/// Statement to begin a transaction
async fn begin_statement(&self, depth: i32) -> String {
let savepoint_stmt = format!("SAVEPOINT savepoint{}", depth);
let ret = if depth > 1 {
savepoint_stmt
} else {
"BEGIN".to_string()
};
let ret = if depth > 1 { savepoint_stmt } else { "BEGIN".to_string() };

return ret
return ret;
}

/// Statement to commit a transaction
Expand All @@ -278,7 +274,7 @@ impl Queryable for Sqlite {
"COMMIT".to_string()
};

return ret
return ret;
}

/// Statement to rollback a transaction
Expand All @@ -290,7 +286,7 @@ impl Queryable for Sqlite {
"ROLLBACK".to_string()
};

return ret
return ret;
}
}

Expand Down
10 changes: 5 additions & 5 deletions quaint/src/connector/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use crate::{
error::{Error, ErrorKind},
};
use async_trait::async_trait;
use metrics::{decrement_gauge, increment_gauge};
use std::{fmt, str::FromStr};
use futures::lock::Mutex;
use metrics::{decrement_gauge, increment_gauge};
use std::sync::Arc;
use std::{fmt, str::FromStr};

extern crate metrics as metrics;

Expand Down Expand Up @@ -58,8 +58,8 @@ impl<'a> DefaultTransaction<'a> {
begin_stmt: &str,
tx_opts: TransactionOptions,
) -> crate::Result<DefaultTransaction<'a>> {
let this = Self {
inner,
let this = Self {
inner,
depth: tx_opts.depth,
commit_stmt: tx_opts.commit_stmt,
rollback_stmt: tx_opts.rollback_stmt,
Expand Down Expand Up @@ -222,7 +222,7 @@ impl FromStr for IsolationLevel {
}
impl TransactionOptions {
pub fn new(
isolation_level: Option<IsolationLevel>,
isolation_level: Option<IsolationLevel>,
isolation_first: bool,
depth: Arc<Mutex<i32>>,
commit_stmt: String,
Expand Down
6 changes: 3 additions & 3 deletions quaint/src/pooled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,9 @@ impl Quaint {
}
};

Ok(PooledConnection {
inner,
transaction_depth: Arc::new(futures::lock::Mutex::new(0))
Ok(PooledConnection {
inner,
transaction_depth: Arc::new(futures::lock::Mutex::new(0)),
})
}

Expand Down
2 changes: 1 addition & 1 deletion quaint/src/pooled/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::{
error::Error,
};
use async_trait::async_trait;
use mobc::{Connection as MobcPooled, Manager};
use futures::lock::Mutex;
use mobc::{Connection as MobcPooled, Manager};
use std::sync::Arc;

/// A connection from the pool. Implements
Expand Down
8 changes: 6 additions & 2 deletions quaint/src/single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::{
connector::{self, impl_default_TransactionCapable, ConnectionInfo, IsolationLevel, Queryable, TransactionCapable},
};
use async_trait::async_trait;
use std::{fmt, sync::Arc};
use futures::lock::Mutex;
use std::{fmt, sync::Arc};

#[cfg(feature = "sqlite")]
use std::convert::TryFrom;
Expand Down Expand Up @@ -165,7 +165,11 @@ impl Quaint {
let connection_info = Arc::new(ConnectionInfo::from_url(url_str)?);
Self::log_start(&connection_info);

Ok(Self { inner, connection_info, transaction_depth: Arc::new(Mutex::new(0)) })
Ok(Self {
inner,
connection_info,
transaction_depth: Arc::new(Mutex::new(0)),
})
}

#[cfg(feature = "sqlite")]
Expand Down

0 comments on commit adb2a13

Please sign in to comment.