8000 Resolved all warnings · psqlpy-python/psqlpy@b10dabc · GitHub
[go: up one dir, main page]

Skip to content

Commit b10dabc

Browse files
committed
Resolved all warnings
1 parent 36e96c7 commit b10dabc

24 files changed

+244
-78
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- uses: actions-rs/clippy-check@v1
3131
with:
3232
token: ${{ secrets.GITHUB_TOKEN }}
33-
args: -p psqlpy --all-features -- -W clippy::all -W clippy::pedantic
33+
args: -p psqlpy --all-features -- -W clippy::all -W clippy::pedantic -D warnings
3434
pytest:
3535
name: ${{matrix.job.os}}-${{matrix.py_version}}-${{ matrix.postgres_version }}
3636
strategy:

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ repos:
5858
- clippy::all
5959
- -W
6060
- clippy::pedantic
61-
# - -D
62-
# - warnings
61+
- -D
62+
- warnings
6363

6464
- id: check
6565
types:

src/connection/impls.rs

Lines changed: 75 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ impl Connection for SingleConnection {
110110
}
111111

112112
impl StartTransaction for SingleConnection {
113+
#[allow(clippy::used_underscore_items)]
113114
async fn start_transaction(
114115
&mut self,
115116
isolation_level: Option<IsolationLevel>,
@@ -125,13 +126,15 @@ impl StartTransaction for SingleConnection {
125126
}
126127

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

132134
Ok(())
133135
}
134136

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

195198
impl StartTransaction for PoolConnection {
199+
#[allow(clippy::used_underscore_items)]
196200
async fn start_transaction(
197201
&mut self,
198202
isolation_level: Option<IsolationLevel>,
@@ -206,13 +210,15 @@ impl StartTransaction for PoolConnection {
206210
}
207211

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

213218
Ok(())
214219
}
215220

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

326332
impl PSQLPyConnection {
333+
#[must_use]
327334
pub fn in_transaction(&self) -> bool {
328335
match self {
329336
PSQLPyConnection::PoolConn(conn) => conn.in_transaction,
330337
PSQLPyConnection::SingleConnection(conn) => conn.in_transaction,
331338
}
332339
}
333340

341+
/// Prepare internal `PSQLPy` statement
342+
///
343+
/// # Errors
344+
/// May return error if there is some problem with DB communication.
334345
pub async fn prepare_statement(
335346
&self,
336347
querystring: String,
@@ -341,6 +352,10 @@ impl PSQLPyConnection {
341352
.await
342353
}
343354

355+
/// Execute prepared `PSQLPy` statement.
356+
///
357+
/// # Errors
358+
/// May return error if there is some problem with DB communication.
344359
pub async fn execute_statement(
345360
&self,
346361
statement: &PsqlpyStatement,
@@ -352,6 +367,10 @@ impl PSQLPyConnection {
352367
Ok(PSQLDriverPyQueryResult::new(result))
353368
}
354369

370+
/// Execute raw query with parameters.
371+
///
372+
/// # Errors
373+
/// May return error if there is some problem with DB communication.
355374
pub async fn execute(
356375
&self,
357376
querystring: String,
@@ -363,15 +382,12 @@ impl PSQLPyConnection {
363382
.await?;
364383

365384
let prepared = prepared.unwrap_or(true);
366-
let result = match prepared {
367-
true => {
368-
self.query(statement.statement_query()?, &statement.params())
369-
.await
370-
}
371-
false => {
372-
self.query_typed(statement.raw_query(), &statement.params_typed())
373-
.await
374-
}
385+
let result = if prepared {
386+
self.query(statement.statement_query()?, &statement.params())
387+
.await
388+
} else {
389+
self.query_typed(statement.raw_query(), &statement.params_typed())
390+
.await
375391
};
376392

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

402+
/// Execute many queries without return.
403+
///
404+
/// # Errors
405+
/// May return error if there is some problem with DB communication.
386406
pub async fn execute_many(
387407
&self,
388408
querystring: String,
@@ -431,6 +451,11 @@ impl PSQLPyConnection {
431451
Ok(())
432452
}
433453

454+
/// Execute raw query with parameters. Return one raw row
455+
///
456+
/// # Errors
457+
/// May return error if there is some problem with DB communication.
458+
/// Or if cannot build statement.
434459
pub async fn fetch_row_raw(
435460
&self,
436461
querystring: String,
@@ -466,6 +491,11 @@ impl PSQLPyConnection {
466491
Ok(result)
467492
}
468493

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

512+
/// Execute raw query with parameters. Return single python object
513+
///
514+
/// # Errors
515+
/// May return error if there is some problem with DB communication.
516+
/// Or if cannot build statement.
482517
pub async fn fetch_val(
483518
&self,
484519
querystring: String,
@@ -495,6 +530,11 @@ impl PSQLPyConnection {
495530
})
496531
}
497532

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

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

582+
/// Create new Portal (server-side byte cursor).
583+
///
584+
/// # Errors
585+
/// May return error if there is some problem with DB communication.
586+
/// Or if cannot build statement.
534587
pub async fn portal(
535588
&mut self,
536589
querystring: Option<&String>,
537590
parameters: &Option<pyo3::Py<PyAny>>,
538591
statement: Option<&PsqlpyStatement>,
539592
) -> PSQLPyResult<(PSQLPyTransaction, tp_Portal)> {
540-
let statement = {
541-
match statement {
542-
Some(stmt) => stmt,
543-
None => {
544-
let Some(querystring) = querystring else {
545-
return Err(RustPSQLDriverError::ConnectionExecuteError(
546-
"Can't create cursor without querystring".into(),
547-
));
548-
};
549-
550-
&StatementBuilder::new(querystring, parameters, self, Some(false))
551-
.build()
552-
.await?
553-
}
554-
}
593+
let stmt = if let Some(stmt) = statement {
594+
stmt
595+
} else {
596+
let Some(querystring) = querystring else {
597+
return Err(RustPSQLDriverError::ConnectionExecuteError(
598+
"Can't create cursor without querystring".into(),
599+
));
600+
};
601+
602+
&StatementBuilder::new(querystring, parameters, self, Some(false))
603+
.build()
604+
.await?
555605
};
556606

557607
let transaction = self.transaction().await?;
558-
let inner_portal = transaction
559-
.portal(statement.raw_query(), &statement.params())
560-
.await?;
608+
let inner_portal = transaction.portal(stmt.raw_query(), &stmt.params()).await?;
561609

562610
Ok((transaction, inner_portal))
563611
}

src/connection/structs.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub struct PoolConnection {
1212
}
1313

1414
impl PoolConnection {
15+
#[must_use]
1516
pub fn new(connection: Object, pg_config: Arc<Config>) -> Self {
1617
Self {
1718
connection,
@@ -31,6 +32,7 @@ pub struct SingleConnection {
3132
}
3233

3334
impl SingleConnection {
35+
#[must_use]
3436
pub fn new(connection: Client, pg_config: Arc<Config>) -> Self {
3537
Self {
3638
connection,

src/driver/common.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,21 @@ macro_rules! impl_cursor_method {
133133
#[pymethods]
134134
impl $name {
135135
#[pyo3(signature = (querystring=None, parameters=None, array_size=None))]
136+
#[must_use]
136137
pub fn cursor(
137138
&self,
138139
querystring: Option<String>,
139140
parameters: Option<Py<PyAny>>,
140141
array_size: Option<i32>,
141-
) -> PSQLPyResult<Cursor> {
142-
Ok(Cursor::new(
142+
) -> Cursor {
143+
Cursor::new(
143144
self.conn.clone(),
144145
querystring,
145146
parameters,
146147
array_size,
147148
self.pg_config.clone(),
148149
None,
149-
))
150+
)
150151
}
151152
}
152153
};
@@ -159,6 +160,10 @@ macro_rules! impl_prepare_method {
159160
($name:ident) => {
160161
#[pymethods]
161162
impl $name {
163+
/// Create new prepared statement.
164+
///
165+
/// # Errors
166+
/// May return error if there is some problem with DB communication.
162167
#[pyo3(signature = (querystring, parameters=None))]
163168
pub async fn prepare(
164169
&self,
@@ -191,6 +196,10 @@ macro_rules! impl_transaction_methods {
191196
($name:ident, $val:expr $(,)?) => {
192197
#[pymethods]
193198
impl $name {
199+
/// Commit existing transaction.
200+
///
201+
/// # Errors
202+
/// May return error if there is some problem with DB communication.
194203
pub async fn commit(&mut self) -> PSQLPyResult<()> {
195204
let conn = self.conn.clone();
196205
let Some(conn) = conn else {
@@ -206,6 +215,10 @@ macro_rules! impl_transaction_methods {
206215
Ok(())
207216
}
208217

218+
/// Rollback existing transaction.
219+
///
220+
/// # Errors
221+
/// May return error if there is some problem with DB communication.
209222
pub async fn rollback(&mut self) -> PSQLPyResult<()> {
210223
let conn = self.conn.clone();
211224
let Some(conn) = conn else {
@@ -230,6 +243,10 @@ macro_rules! impl_binary_copy_method {
230243
($name:ident) => {
231244
#[pymethods]
232245
impl $name {
246+
/// Perform binary copy to table.
247+
///
248+
/// # Errors
249+
/// May return error if there is some problem with DB communication.
233250
#[pyo3(signature = (source, table_name, columns=None, schema_name=None))]
234251
pub async fn binary_copy_to_table(
235252
self_: pyo3::Py<Self>,

src/driver/connection.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl Connection {
158158
read_conn_g.in_transaction()
159159
}
160160

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

193193
#[allow(clippy::unused_async)]
194-
async fn __aexit__<'a>(
194+
async fn __aexit__(
195195
self_: Py<Self>,
196196
_exception_type: Py<PyAny>,
197197
exception: Py<PyAny>,
@@ -278,7 +278,7 @@ impl Connection {
278278
/// 1) Cannot convert python parameters
279279
/// 2) Cannot execute querystring.
280280
#[pyo3(signature = (querystring, parameters=None, prepared=None))]
281-
pub async fn execute_many<'a>(
281+
pub async fn execute_many(
282282
self_: pyo3::Py<Self>,
283283
querystring: String,
284284
parameters: Option<Vec<Py<PyAny>>>,
@@ -369,7 +369,7 @@ impl Connection {
369369
/// 2) Cannot execute querystring.
370370
/// 3) Query returns more than one row
371371
#[pyo3(signature = (querystring, parameters=None, prepared=None))]
372-
pub async fn fetch_val<'a>(
372+
pub async fn fetch_val(
373373
self_: pyo3::Py<Self>,
374374
querystring: String,
375375
parameters: Option<pyo3::Py<PyAny>>,

src/driver/connection_pool.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ impl ConnectionPool {
244244
}
245245
}
246246

247+
/// Retrieve new connection from the pool.
248+
///
249+
/// # Errors
250+
/// May return error if cannot get new connection.
247251
pub async fn retrieve_connection(&mut self) -> PSQLPyResult<Connection> {
248252
let connection = self.pool.get().await?;
249253

@@ -406,7 +410,7 @@ impl ConnectionPool {
406410
(b_gil.pg_config.clone(), b_gil.pool_conf.clone())
407411
});
408412

409-
Listener::new(pg_config, pool_conf.ca_file, pool_conf.ssl_mode)
413+
Listener::new(&pg_config, pool_conf.ca_file, pool_conf.ssl_mode)
410414
}
411415

412416
/// Return new single connection.

0 commit comments

Comments
 (0)
0