Skip to content

Resolved all warnings #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: -p psqlpy --all-features -- -W clippy::all -W clippy::pedantic
args: -p psqlpy --all-features -- -W clippy::all -W clippy::pedantic -D warnings
pytest:
name: ${{matrix.job.os}}-${{matrix.py_version}}-${{ matrix.postgres_version }}
strategy:
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ repos:
- clippy::all
- -W
- clippy::pedantic
# - -D
# - warnings
- -D
- warnings

- id: check
types:
Expand Down
102 changes: 75 additions & 27 deletions src/connection/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ impl Connection for SingleConnection {
}

impl StartTransaction for SingleConnection {
#[allow(clippy::used_underscore_items)]
async fn start_transaction(
&mut self,
isolation_level: Option<IsolationLevel>,
Expand All @@ -125,13 +126,15 @@ impl StartTransaction for SingleConnection {
}

impl CloseTransaction for SingleConnection {
#[allow(clippy::used_underscore_items)]
async fn commit(&mut self) -> PSQLPyResult<()> {
self._commit().await?;
self.in_transaction = false;

Ok(())
}

#[allow(clippy::used_underscore_items)]
async fn rollback(&mut self) -> PSQLPyResult<()> {
self._rollback().await?;
self.in_transaction = false;
Expand Down Expand Up @@ -193,6 +196,7 @@ impl Connection for PoolConnection {
}

impl StartTransaction for PoolConnection {
#[allow(clippy::used_underscore_items)]
async fn start_transaction(
&mut self,
isolation_level: Option<IsolationLevel>,
Expand All @@ -206,13 +210,15 @@ impl StartTransaction for PoolConnection {
}

impl CloseTransaction for PoolConnection {
#[allow(clippy::used_underscore_items)]
async fn commit(&mut self) -> PSQLPyResult<()> {
self._commit().await?;
self.in_transaction = false;

Ok(())
}

#[allow(clippy::used_underscore_items)]
async fn rollback(&mut self) -> PSQLPyResult<()> {
self._rollback().await?;
self.in_transaction = false;
Expand Down Expand Up @@ -324,13 +330,18 @@ impl CloseTransaction for PSQLPyConnection {
}

impl PSQLPyConnection {
#[must_use]
pub fn in_transaction(&self) -> bool {
match self {
PSQLPyConnection::PoolConn(conn) => conn.in_transaction,
PSQLPyConnection::SingleConnection(conn) => conn.in_transaction,
}
}

/// Prepare internal `PSQLPy` statement
///
/// # Errors
/// May return error if there is some problem with DB communication.
pub async fn prepare_statement(
&self,
querystring: String,
Expand All @@ -341,6 +352,10 @@ impl PSQLPyConnection {
.await
}

/// Execute prepared `PSQLPy` statement.
///
/// # Errors
/// May return error if there is some problem with DB communication.
pub async fn execute_statement(
&self,
statement: &PsqlpyStatement,
Expand All @@ -352,6 +367,10 @@ impl PSQLPyConnection {
Ok(PSQLDriverPyQueryResult::new(result))
}

/// Execute raw query with parameters.
///
/// # Errors
/// May return error if there is some problem with DB communication.
pub async fn execute(
&self,
querystring: String,
Expand All @@ -363,15 +382,12 @@ impl PSQLPyConnection {
.await?;

let prepared = prepared.unwrap_or(true);
let result = match prepared {
true => {
self.query(statement.statement_query()?, &statement.params())
.await
}
false => {
self.query_typed(statement.raw_query(), &statement.params_typed())
.await
}
let result = if prepared {
self.query(statement.statement_query()?, &statement.params())
.await
} else {
self.query_typed(statement.raw_query(), &statement.params_typed())
.await
};

let return_result = result.map_err(|err| {
Expand All @@ -383,6 +399,10 @@ impl PSQLPyConnection {
Ok(PSQLDriverPyQueryResult::new(return_result))
}

/// Execute many queries without return.
///
/// # Errors
/// May return error if there is some problem with DB communication.
pub async fn execute_many(
&self,
querystring: String,
Expand Down Expand Up @@ -431,6 +451,11 @@ impl PSQLPyConnection {
Ok(())
}

/// Execute raw query with parameters. Return one raw row
///
/// # Errors
/// May return error if there is some problem with DB communication.
/// Or if cannot build statement.
pub async fn fetch_row_raw(
&self,
querystring: String,
Expand Down Expand Up @@ -466,6 +491,11 @@ impl PSQLPyConnection {
Ok(result)
}

/// Execute raw query with parameters. Return one row
///
/// # Errors
/// May return error if there is some problem with DB communication.
/// Or if cannot build statement.
pub async fn fetch_row(
&self,
querystring: String,
Expand All @@ -479,6 +509,11 @@ impl PSQLPyConnection {
Ok(PSQLDriverSinglePyQueryResult::new(result))
}

/// Execute raw query with parameters. Return single python object
///
/// # Errors
/// May return error if there is some problem with DB communication.
/// Or if cannot build statement.
pub async fn fetch_val(
&self,
querystring: String,
Expand All @@ -495,6 +530,11 @@ impl PSQLPyConnection {
})
}

/// Create new sink for COPY operation.
///
/// # Errors
/// May return error if there is some problem with DB communication.
/// Or if cannot build statement.
pub async fn copy_in<T, U>(&self, statement: &T) -> PSQLPyResult<CopyInSink<U>>
where
T: ?Sized + ToStatement,
Expand All @@ -510,6 +550,14 @@ impl PSQLPyConnection {
}
}

/// Create and open new transaction.
///
/// Unsafe here isn't a problem cuz it is stored within
/// the struct with the connection created this transaction.
///
/// # Errors
/// May return error if there is some problem with DB communication.
/// Or if cannot build statement.
pub async fn transaction(&mut self) -> PSQLPyResult<PSQLPyTransaction> {
match self {
PSQLPyConnection::PoolConn(conn) => {
Expand All @@ -531,33 +579,33 @@ impl PSQLPyConnection {
}
}

/// Create new Portal (server-side byte cursor).
///
/// # Errors
/// May return error if there is some problem with DB communication.
/// Or if cannot build statement.
pub async fn portal(
&mut self,
querystring: Option<&String>,
parameters: &Option<pyo3::Py<PyAny>>,
statement: Option<&PsqlpyStatement>,
) -> PSQLPyResult<(PSQLPyTransaction, tp_Portal)> {
let statement = {
match statement {
Some(stmt) => stmt,
None => {
let Some(querystring) = querystring else {
return Err(RustPSQLDriverError::ConnectionExecuteError(
"Can't create cursor without querystring".into(),
));
};

&StatementBuilder::new(querystring, parameters, self, Some(false))
.build()
.await?
}
}
let stmt = if let Some(stmt) = statement {
stmt
} else {
let Some(querystring) = querystring else {
return Err(RustPSQLDriverError::ConnectionExecuteError(
"Can't create cursor without querystring".into(),
));
};

&StatementBuilder::new(querystring, parameters, self, Some(false))
.build()
.await?
};

let transaction = self.transaction().await?;
let inner_portal = transaction
.portal(statement.raw_query(), &statement.params())
.await?;
let inner_portal = transaction.portal(stmt.raw_query(), &stmt.params()).await?;

Ok((transaction, inner_portal))
}
Expand Down
2 changes: 2 additions & 0 deletions src/connection/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct PoolConnection {
}

impl PoolConnection {
#[must_use]
pub fn new(connection: Object, pg_config: Arc<Config>) -> Self {
Self {
connection,
Expand All @@ -31,6 +32,7 @@ pub struct SingleConnection {
}

impl SingleConnection {
#[must_use]
pub fn new(connection: Client, pg_config: Arc<Config>) -> Self {
Self {
connection,
Expand Down
2 changes: 1 addition & 1 deletion src/connection/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub trait Transaction {
if let Some(level) = isolation_level {
let level = &level.to_str_level();
querystring.push_str(format!(" ISOLATION LEVEL {level}").as_str());
};
}

querystring.push_str(match read_variant {
Some(ReadVariant::ReadOnly) => " READ ONLY",
Expand Down
23 changes: 20 additions & 3 deletions src/driver/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,21 @@ macro_rules! impl_cursor_method {
#[pymethods]
impl $name {
#[pyo3(signature = (querystring=None, parameters=None, array_size=None))]
#[must_use]
pub fn cursor(
&self,
querystring: Option<String>,
parameters: Option<Py<PyAny>>,
array_size: Option<i32>,
) -> PSQLPyResult<Cursor> {
Ok(Cursor::new(
) -> Cursor {
Cursor::new(
self.conn.clone(),
querystring,
parameters,
array_size,
self.pg_config.clone(),
None,
))
)
}
}
};
Expand All @@ -159,6 +160,10 @@ macro_rules! impl_prepare_method {
($name:ident) => {
#[pymethods]
impl $name {
/// Create new prepared statement.
///
/// # Errors
/// May return error if there is some problem with DB communication.
#[pyo3(signature = (querystring, parameters=None))]
pub async fn prepare(
&self,
Expand Down Expand Up @@ -191,6 +196,10 @@ macro_rules! impl_transaction_methods {
($name:ident, $val:expr $(,)?) => {
#[pymethods]
impl $name {
/// Commit existing transaction.
///
/// # Errors
/// May return error if there is some problem with DB communication.
pub async fn commit(&mut self) -> PSQLPyResult<()> {
let conn = self.conn.clone();
let Some(conn) = conn else {
Expand All @@ -206,6 +215,10 @@ macro_rules! impl_transaction_methods {
Ok(())
}

/// Rollback existing transaction.
///
/// # Errors
/// May return error if there is some problem with DB communication.
pub async fn rollback(&mut self) -> PSQLPyResult<()> {
let conn = self.conn.clone();
let Some(conn) = conn else {
Expand All @@ -230,6 +243,10 @@ macro_rules! impl_binary_copy_method {
($name:ident) => {
#[pymethods]
impl $name {
/// Perform binary copy to table.
///
/// # Errors
/// May return error if there is some problem with DB communication.
#[pyo3(signature = (source, table_name, columns=None, schema_name=None))]
pub async fn binary_copy_to_table(
self_: pyo3::Py<Self>,
Expand Down
8 changes: 4 additions & 4 deletions src/driver/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl Connection {
read_conn_g.in_transaction()
}

async fn __aenter__<'a>(self_: Py<Self>) -> PSQLPyResult<Py<Self>> {
async fn __aenter__(self_: Py<Self>) -> PSQLPyResult<Py<Self>> {
let (db_client, db_pool, pg_config) = pyo3::Python::with_gil(|gil| {
let self_ = self_.borrow(gil);
(
Expand Down Expand Up @@ -191,7 +191,7 @@ impl Connection {
}

#[allow(clippy::unused_async)]
async fn __aexit__<'a>(
async fn __aexit__(
self_: Py<Self>,
_exception_type: Py<PyAny>,
exception: Py<PyAny>,
Expand Down Expand Up @@ -278,7 +278,7 @@ impl Connection {
/// 1) Cannot convert python parameters
/// 2) Cannot execute querystring.
#[pyo3(signature = (querystring, parameters=None, prepared=None))]
pub async fn execute_many<'a>(
pub async fn execute_many(
self_: pyo3::Py<Self>,
querystring: String,
parameters: Option<Vec<Py<PyAny>>>,
Expand Down Expand Up @@ -369,7 +369,7 @@ impl Connection {
/// 2) Cannot execute querystring.
/// 3) Query returns more than one row
#[pyo3(signature = (querystring, parameters=None, prepared=None))]
pub async fn fetch_val<'a>(
pub async fn fetch_val(
self_: pyo3::Py<Self>,
querystring: String,
parameters: Option<pyo3::Py<PyAny>>,
Expand Down
Loading
Loading