Skip to content

Commit

Permalink
Strict clippy mode fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chandr-andr committed Feb 21, 2024
1 parent c44ebb8 commit ba29978
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 67 deletions.
11 changes: 9 additions & 2 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use crate::exceptions::rust_errors::RustPSQLDriverPyResult;
/// Add new module to the parent one.
///
/// You can find out more information from this issue
/// https://github.com/PyO3/pyo3/issues/759
/// <https://github.com/PyO3/pyo3/issues/759>
///
/// # Error
/// # Errors
///
/// May return Err Result if can't build module or change modules.
pub fn add_module(
Expand All @@ -28,6 +28,13 @@ pub fn add_module(
Ok(())
}

/// Simple wrapper for pyo3 `pyo3_asyncio::tokio::future_into_py`.
///
/// It wraps incoming Future and return internal Result.
///
/// # Errors
///
/// May return Err Result if future acts incorrect.
pub fn rustengine_future<F, T>(py: Python<'_>, future: F) -> RustPSQLDriverPyResult<&PyAny>
where
F: Future<Output = RustPSQLDriverPyResult<T>> + Send + 'static,
Expand Down
14 changes: 12 additions & 2 deletions src/driver/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ pub struct Connection {

#[pymethods]
impl Connection {
/// Execute statement with or witout parameters.
///
/// # Errors
///
/// May return Err Result if
/// 1) Cannot convert incoming parameters
/// 2) Cannot prepare statement
/// 3) Cannot execute query
pub fn execute<'a>(
&'a self,
py: Python<'a>,
Expand All @@ -32,12 +40,12 @@ impl Connection {

let mut params: Vec<PythonDTO> = vec![];
if let Some(parameters) = parameters {
params = convert_parameters(parameters)?
params = convert_parameters(parameters)?;
}

rustengine_future(py, async move {
let mut vec_parameters: Vec<&(dyn ToSql + Sync)> = Vec::with_capacity(params.len());
for param in params.iter() {
for param in &params {
vec_parameters.push(param);
}
let db_client_guard = db_client_arc.read().await;
Expand All @@ -52,6 +60,8 @@ impl Connection {
})
}

/// Return new instance of transaction.
#[must_use]
pub fn transaction(
&self,
isolation_level: Option<IsolationLevel>,
Expand Down
22 changes: 12 additions & 10 deletions src/driver/connection_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{

use super::connection::Connection;

/// PSQLPool for internal use only.
/// `PSQLPool` for internal use only.
///
/// It is not exposed to python.
pub struct RustPSQLPool {
Expand All @@ -27,6 +27,7 @@ pub struct RustPSQLPool {

impl RustPSQLPool {
/// Create new `RustPSQLPool`.
#[must_use]
pub fn new(
username: Option<String>,
password: Option<String>,
Expand All @@ -50,7 +51,7 @@ impl RustPSQLPool {
impl RustPSQLPool {
/// Return new single connection.
///
/// # Errors:
/// # Errors
/// May return Err Result if cannot get new connection from the pool.
pub async fn inner_connection(&self) -> RustPSQLDriverPyResult<Connection> {
let db_pool_arc = self.db_pool.clone();
Expand All @@ -73,7 +74,7 @@ impl RustPSQLPool {
///
/// Prepare statement and cache it, then execute.
///
/// # Errors:
/// # Errors
/// May return Err Result if cannot retrieve new connection
/// or prepare statement or execute statement.
pub async fn inner_execute(
Expand All @@ -94,7 +95,7 @@ impl RustPSQLPool {
.await?;

let mut vec_parameters: Vec<&(dyn ToSql + Sync)> = Vec::with_capacity(parameters.len());
for param in parameters.iter() {
for param in &parameters {
vec_parameters.push(param);
}

Expand All @@ -109,9 +110,9 @@ impl RustPSQLPool {

/// Create new Database pool.
///
/// # Errors:
/// # Errors
/// May return Err Result if Database pool is already initialized,
/// max_db_pool_size is less than 2 or it's impossible to build db pool.
/// `max_db_pool_size` is less than 2 or it's impossible to build db pool.
pub async fn inner_startup(&self) -> RustPSQLDriverPyResult<()> {
let db_pool_arc = self.db_pool.clone();
let password = self.password.clone();
Expand Down Expand Up @@ -177,6 +178,7 @@ pub struct PSQLPool {
#[pymethods]
impl PSQLPool {
#[new]
#[must_use]
pub fn new(
username: Option<String>,
password: Option<String>,
Expand All @@ -200,7 +202,7 @@ impl PSQLPool {

/// Startup Database Pool.
///
/// # Errors:
/// # Errors
/// May return Err Result if `inner_startup` returns error.
pub fn startup<'a>(&'a self, py: Python<'a>) -> RustPSQLDriverPyResult<&'a PyAny> {
let psql_pool_arc = self.rust_psql_pool.clone();
Expand All @@ -213,7 +215,7 @@ impl PSQLPool {

/// Return single connection.
///
/// # Errors:
/// # Errors
/// May return Err Result if `inner_connection` returns error.
pub fn connection<'a>(&'a self, py: Python<'a>) -> RustPSQLDriverPyResult<&'a PyAny> {
let psql_pool_arc = self.rust_psql_pool.clone();
Expand All @@ -226,7 +228,7 @@ impl PSQLPool {

/// Execute querystring with parameters.
///
/// # Errors:
/// # Errors
/// May return Err Result if cannot convert parameters
/// or `inner_execute` returns Err.
pub fn execute<'a>(
Expand All @@ -238,7 +240,7 @@ impl PSQLPool {
let engine_arc = self.rust_psql_pool.clone();
let mut params: Vec<PythonDTO> = vec![];
if let Some(parameters) = parameters {
params = convert_parameters(parameters)?
params = convert_parameters(parameters)?;
}

rustengine_future(py, async move {
Expand Down
6 changes: 6 additions & 0 deletions src/driver/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ impl Cursor {
slf
}

/// Return next result from the SQL statement.
///
/// Execute FETCH <number> FROM <cursor name>
///
/// # Errors
/// May return Err Result if can't execute querystring.
pub fn __anext__(&self, py: Python<'_>) -> RustPSQLDriverPyResult<Option<PyObject>> {
let db_client_arc = self.db_client.clone();
let cursor_name = self.cursor_name.clone();
Expand Down
Loading

0 comments on commit ba29978

Please sign in to comment.