Skip to content

Commit 72f992a

Browse files
committed
Fixed problem with recursive call
1 parent 32e534e commit 72f992a

19 files changed

+181
-276
lines changed

.pre-commit-config.yaml

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

6264
- id: check
6365
types:

python/psqlpy/_internal/__init__.pyi

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -815,16 +815,6 @@ class Connection:
815815
816816
Return representation of prepared statement.
817817
"""
818-
async def commit(self: Self) -> None:
819-
"""Commit the transaction.
820-
821-
Do nothing if there is no active transaction.
822-
"""
823-
async def rollback(self: Self) -> None:
824-
"""Rollback the transaction.
825-
826-
Do nothing if there is no active transaction.
827-
"""
828818
async def execute(
829819
self: Self,
830820
querystring: str,

src/connection/impls.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ where
3131
) -> PSQLPyResult<()> {
3232
let start_qs = self.build_start_qs(isolation_level, read_variant, deferrable);
3333
self.batch_execute(start_qs.as_str()).await.map_err(|err| {
34-
RustPSQLDriverError::TransactionBeginError(
35-
format!("Cannot start transaction due to - {err}").into(),
36-
)
34+
RustPSQLDriverError::TransactionBeginError(format!(
35+
"Cannot start transaction due to - {err}"
36+
))
3737
})?;
3838

3939
Ok(())
@@ -65,7 +65,7 @@ impl Connection for SingleConnection {
6565
if !prepared {
6666
self.drop_prepared(&prepared_stmt).await?;
6767
}
68-
return Ok(prepared_stmt);
68+
Ok(prepared_stmt)
6969
}
7070

7171
async fn drop_prepared(&self, stmt: &Statement) -> PSQLPyResult<()> {
@@ -116,28 +116,27 @@ impl StartTransaction for SingleConnection {
116116
read_variant: Option<ReadVariant>,
117117
deferrable: Option<bool>,
118118
) -> PSQLPyResult<()> {
119-
let res = self
120-
._start_transaction(isolation_level, read_variant, deferrable)
119+
self._start_transaction(isolation_level, read_variant, deferrable)
121120
.await?;
122121
self.in_transaction = true;
123122

124-
Ok(res)
123+
Ok(())
125124
}
126125
}
127126

128127
impl CloseTransaction for SingleConnection {
129128
async fn commit(&mut self) -> PSQLPyResult<()> {
130-
let res = self._commit().await?;
129+
self._commit().await?;
131130
self.in_transaction = false;
132131

133-
Ok(res)
132+
Ok(())
134133
}
135134

136135
async fn rollback(&mut self) -> PSQLPyResult<()> {
137-
let res = self._rollback().await?;
136+
self._rollback().await?;
138137
self.in_transaction = false;
139138

140-
Ok(res)
139+
Ok(())
141140
}
142141
}
143142

@@ -149,7 +148,7 @@ impl Connection for PoolConnection {
149148

150149
let prepared = self.connection.prepare(query).await?;
151150
self.drop_prepared(&prepared).await?;
152-
return Ok(prepared);
151+
Ok(prepared)
153152
}
154153

155154
async fn drop_prepared(&self, stmt: &Statement) -> PSQLPyResult<()> {
@@ -208,17 +207,17 @@ impl StartTransaction for PoolConnection {
208207

209208
impl CloseTransaction for PoolConnection {
210209
async fn commit(&mut self) -> PSQLPyResult<()> {
211-
let res = self._commit().await?;
210+
self._commit().await?;
212211
self.in_transaction = false;
213212

214-
Ok(res)
213+
Ok(())
215214
}
216215

217216
async fn rollback(&mut self) -> PSQLPyResult<()> {
218-
let res = self._rollback().await?;
217+
self._rollback().await?;
219218
self.in_transaction = false;
220219

221-
Ok(res)
220+
Ok(())
222221
}
223222
}
224223

@@ -407,14 +406,14 @@ impl PSQLPyConnection {
407406

408407
for statement in statements {
409408
let querystring_result = if prepared {
410-
let prepared_stmt = &self.prepare(&statement.raw_query(), true).await;
409+
let prepared_stmt = &self.prepare(statement.raw_query(), true).await;
411410
if let Err(error) = prepared_stmt {
412411
return Err(RustPSQLDriverError::ConnectionExecuteError(format!(
413412
"Cannot prepare statement in execute_many, operation rolled back {error}",
414413
)));
415414
}
416415
self.query(
417-
&self.prepare(&statement.raw_query(), true).await?,
416+
&self.prepare(statement.raw_query(), true).await?,
418417
&statement.params(),
419418
)
420419
.await
@@ -429,7 +428,7 @@ impl PSQLPyConnection {
429428
}
430429
}
431430

432-
return Ok(());
431+
Ok(())
433432
}
434433

435434
pub async fn fetch_row_raw(
@@ -447,7 +446,7 @@ impl PSQLPyConnection {
447446
let result = if prepared {
448447
self.query_one(
449448
&self
450-
.prepare(&statement.raw_query(), true)
449+
.prepare(statement.raw_query(), true)
451450
.await
452451
.map_err(|err| {
453452
RustPSQLDriverError::ConnectionExecuteError(format!(
@@ -464,7 +463,7 @@ impl PSQLPyConnection {
464463
.map_err(|err| RustPSQLDriverError::ConnectionExecuteError(format!("{err}")))?
465464
};
466465

467-
return Ok(result);
466+
Ok(result)
468467
}
469468

470469
pub async fn fetch_row(
@@ -477,7 +476,7 @@ impl PSQLPyConnection {
477476
.fetch_row_raw(querystring, parameters, prepared)
478477
.await?;
479478

480-
return Ok(PSQLDriverSinglePyQueryResult::new(result));
479+
Ok(PSQLDriverSinglePyQueryResult::new(result))
481480
}
482481

483482
pub async fn fetch_val(
@@ -490,10 +489,10 @@ impl PSQLPyConnection {
490489
.fetch_row_raw(querystring, parameters, prepared)
491490
.await?;
492491

493-
return Python::with_gil(|gil| match result.columns().first() {
492+
Python::with_gil(|gil| match result.columns().first() {
494493
Some(first_column) => postgres_to_py(gil, &result, first_column, 0, &None),
495494
None => Ok(gil.None()),
496-
});
495+
})
497496
}
498497

499498
pub async fn copy_in<T, U>(&self, statement: &T) -> PSQLPyResult<CopyInSink<U>>

src/driver/connection_pool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl ConnectionPool {
238238
prepare: Option<bool>,
239239
) -> Self {
240240
ConnectionPool {
241-
pool: pool,
241+
pool,
242242
pg_config: Arc::new(pg_config),
243243
pool_conf: ConnectionPoolConf::new(ca_file, ssl_mode, prepare.unwrap_or(true)),
244244
}

src/driver/cursor.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl Cursor {
5959
let Some(portal) = &self.inner else {
6060
return Err(RustPSQLDriverError::TransactionClosedError);
6161
};
62-
transaction.query_portal(&portal, size).await
62+
transaction.query_portal(portal, size).await
6363
}
6464
}
6565

@@ -157,7 +157,7 @@ impl Cursor {
157157
fn __anext__(&self) -> PSQLPyResult<Option<PyObject>> {
158158
let txid = self.transaction.clone();
159159
let portal = self.inner.clone();
160-
let size = self.array_size.clone();
160+
let size = self.array_size;
161161

162162
let py_future = Python::with_gil(move |gil| {
163163
rustdriver_future(gil, async move {
@@ -167,7 +167,7 @@ impl Cursor {
167167
let Some(portal) = &portal else {
168168
return Err(RustPSQLDriverError::TransactionClosedError);
169169
};
170-
let result = txid.query_portal(&portal, size).await?;
170+
let result = txid.query_portal(portal, size).await?;
171171

172172
if result.is_empty() {
173173
return Err(PyStopAsyncIteration::new_err(
@@ -192,7 +192,7 @@ impl Cursor {
192192
let (txid, inner_portal) = match &self.querystring {
193193
Some(querystring) => {
194194
write_conn_g
195-
.portal(Some(&querystring), &self.parameters, None)
195+
.portal(Some(querystring), &self.parameters, None)
196196
.await?
197197
}
198198
None => {
@@ -201,7 +201,7 @@ impl Cursor {
201201
"Cannot start cursor".into(),
202202
));
203203
};
204-
write_conn_g.portal(None, &None, Some(&statement)).await?
204+
write_conn_g.portal(None, &None, Some(statement)).await?
205205
}
206206
};
207207

src/driver/transaction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl Transaction {
7878
.start_transaction(isolation_level, read_variant, deferrable)
7979
.await?;
8080

81-
return Ok(self_);
81+
Ok(self_)
8282
}
8383

8484
#[allow(clippy::needless_pass_by_value)]
@@ -114,7 +114,7 @@ impl Transaction {
114114
let mut self_ = self_.borrow_mut(gil);
115115
self_.conn = None;
116116
});
117-
return Err(RustPSQLDriverError::RustPyError(py_err));
117+
Err(RustPSQLDriverError::RustPyError(py_err))
118118
}
119119
}
120120

src/query_result.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
use pyo3::{prelude::*, pyclass, pymethods, types::PyDict, Py, PyAny, Python};
1+
use pyo3::{prelude::*, pyclass, pymethods, types::PyDict, IntoPyObjectExt, Py, PyAny, Python};
22
use tokio_postgres::Row;
33

4-
use crate::{
5-
exceptions::rust_errors::PSQLPyResult,
6-
value_converter::to_python::{postgres_to_py, InnerIntoPyObject},
7-
};
4+
use crate::{exceptions::rust_errors::PSQLPyResult, value_converter::to_python::postgres_to_py};
85

96
/// Convert postgres `Row` into Python Dict.
107
///
@@ -22,7 +19,7 @@ fn row_to_dict<'a>(
2219
let python_dict = PyDict::new(py);
2320
for (column_idx, column) in postgres_row.columns().iter().enumerate() {
2421
let python_type = postgres_to_py(py, postgres_row, column, column_idx, custom_decoders)?;
25-
python_dict.set_item(column.name().internal_into_py_object(py)?, python_type)?;
22+
python_dict.set_item(column.name().into_py_any(py)?, python_type)?;
2623
}
2724
Ok(python_dict)
2825
}
@@ -70,7 +67,7 @@ impl PSQLDriverPyQueryResult {
7067
for row in &self.inner {
7168
result.push(row_to_dict(py, row, &custom_decoders)?);
7269
}
73-
result.internal_into_py_object(py)
70+
Ok(result.into_py_any(py)?)
7471
}
7572

7673
/// Convert result from database to any class passed from Python.
@@ -81,14 +78,14 @@ impl PSQLDriverPyQueryResult {
8178
/// postgres type to python or create new Python class.
8279
#[allow(clippy::needless_pass_by_value)]
8380
pub fn as_class<'a>(&'a self, py: Python<'a>, as_class: Py<PyAny>) -> PSQLPyResult<Py<PyAny>> {
84-
let mut res: Vec<Py<PyAny>> = vec![];
81+
let mut result: Vec<Py<PyAny>> = vec![];
8582
for row in &self.inner {
8683
let pydict: pyo3::Bound<'_, PyDict> = row_to_dict(py, row, &None)?;
8784
let convert_class_inst = as_class.call(py, (), Some(&pydict))?;
88-
res.push(convert_class_inst);
85+
result.push(convert_class_inst);
8986
}
9087

91-
res.internal_into_py_object(py)
88+
Ok(result.into_py_any(py)?)
9289
}
9390

9491
/// Convert result from database with function passed from Python.
@@ -105,13 +102,13 @@ impl PSQLDriverPyQueryResult {
105102
row_factory: Py<PyAny>,
106103
custom_decoders: Option<Py<PyDict>>,
107104
) -> PSQLPyResult<Py<PyAny>> {
108-
let mut res: Vec<Py<PyAny>> = vec![];
105+
let mut result: Vec<Py<PyAny>> = vec![];
109106
for row in &self.inner {
110107
let pydict: pyo3::Bound<'_, PyDict> = row_to_dict(py, row, &custom_decoders)?;
111108
let row_factory_class = row_factory.call(py, (pydict,), None)?;
112-
res.push(row_factory_class);
109+
result.push(row_factory_class);
113110
}
114-
res.internal_into_py_object(py)
111+
Ok(result.into_py_any(py)?)
115112
}
116113
}
117114

@@ -151,8 +148,8 @@ impl PSQLDriverSinglePyQueryResult {
151148
&self,
152149
py: Python<'_>,
153150
custom_decoders: Option<Py<PyDict>>,
154-
) -> PSQLPyResult<Py<PyDict>> {
155-
row_to_dict(py, &self.inner, &custom_decoders)?.internal_into_py_object(py)
151+
) -> PSQLPyResult<Py<PyAny>> {
152+
Ok(row_to_dict(py, &self.inner, &custom_decoders)?.into_py_any(py)?)
156153
}
157154

158155
/// Convert result from database to any class passed from Python.
@@ -182,7 +179,7 @@ impl PSQLDriverSinglePyQueryResult {
182179
row_factory: Py<PyAny>,
183180
custom_decoders: Option<Py<PyDict>>,
184181
) -> PSQLPyResult<Py<PyAny>> {
185-
let pydict = row_to_dict(py, &self.inner, &custom_decoders)?.internal_into_py_object(py)?;
182+
let pydict = row_to_dict(py, &self.inner, &custom_decoders)?.into_py_any(py)?;
186183
Ok(row_factory.call(py, (pydict,), None)?)
187184
}
188185
}

src/statement/cache.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl StatementsCache {
1717
}
1818

1919
pub fn get_cache(&self, querystring: &String) -> Option<StatementCacheInfo> {
20-
let qs_hash = hash_str(&querystring);
20+
let qs_hash = hash_str(querystring);
2121

2222
if let Some(cache_info) = self.0.get(&qs_hash) {
2323
return Some(cache_info.clone());
@@ -35,10 +35,10 @@ pub(crate) struct StatementCacheInfo {
3535

3636
impl StatementCacheInfo {
3737
fn new(query: &QueryString, inner_stmt: &Statement) -> Self {
38-
return Self {
38+
Self {
3939
query: query.clone(),
4040
inner_stmt: inner_stmt.clone(),
41-
};
41+
}
4242
}
4343

4444
pub(crate) fn types(&self) -> Vec<Type> {
@@ -49,7 +49,7 @@ impl StatementCacheInfo {
4949
self.inner_stmt
5050
.columns()
5151
.iter()
52-
.map(|column| Column::new(column.name().to_string(), column.table_oid().clone()))
52+
.map(|column| Column::new(column.name().to_string(), column.table_oid()))
5353
.collect::<Vec<Column>>()
5454
}
5555
}

0 commit comments

Comments
 (0)