Skip to content

Commit 50855b5

Browse files
committed
Full value converter refactor
1 parent d29bd6b commit 50855b5

34 files changed

+890
-603
lines changed

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/driver/connection.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{collections::HashSet, net::IpAddr, sync::Arc};
66
use tokio_postgres::{binary_copy::BinaryCopyInWriter, config::Host, Config};
77

88
use crate::{
9-
exceptions::rust_errors::{RustPSQLDriverError, RustPSQLDriverPyResult},
9+
exceptions::rust_errors::{PSQLPyResult, RustPSQLDriverError},
1010
format_helpers::quote_ident,
1111
query_result::{PSQLDriverPyQueryResult, PSQLDriverSinglePyQueryResult},
1212
runtime::tokio_runtime,
@@ -137,7 +137,7 @@ impl Connection {
137137
return self.pg_config.get_options();
138138
}
139139

140-
async fn __aenter__<'a>(self_: Py<Self>) -> RustPSQLDriverPyResult<Py<Self>> {
140+
async fn __aenter__<'a>(self_: Py<Self>) -> PSQLPyResult<Py<Self>> {
141141
let (db_client, db_pool) = pyo3::Python::with_gil(|gil| {
142142
let self_ = self_.borrow(gil);
143143
(self_.db_client.clone(), self_.db_pool.clone())
@@ -169,7 +169,7 @@ impl Connection {
169169
_exception_type: Py<PyAny>,
170170
exception: Py<PyAny>,
171171
_traceback: Py<PyAny>,
172-
) -> RustPSQLDriverPyResult<()> {
172+
) -> PSQLPyResult<()> {
173173
let (is_exception_none, py_err) = pyo3::Python::with_gil(|gil| {
174174
(
175175
exception.is_none(gil),
@@ -205,7 +205,7 @@ impl Connection {
205205
querystring: String,
206206
parameters: Option<pyo3::Py<PyAny>>,
207207
prepared: Option<bool>,
208-
) -> RustPSQLDriverPyResult<PSQLDriverPyQueryResult> {
208+
) -> PSQLPyResult<PSQLDriverPyQueryResult> {
209209
let db_client = pyo3::Python::with_gil(|gil| self_.borrow(gil).db_client.clone());
210210

211211
if let Some(db_client) = db_client {
@@ -227,10 +227,7 @@ impl Connection {
227227
/// May return Err Result if:
228228
/// 1) Connection is closed.
229229
/// 2) Cannot execute querystring.
230-
pub async fn execute_batch(
231-
self_: pyo3::Py<Self>,
232-
querystring: String,
233-
) -> RustPSQLDriverPyResult<()> {
230+
pub async fn execute_batch(self_: pyo3::Py<Self>, querystring: String) -> PSQLPyResult<()> {
234231
let db_client = pyo3::Python::with_gil(|gil| self_.borrow(gil).db_client.clone());
235232

236233
if let Some(db_client) = db_client {
@@ -256,7 +253,7 @@ impl Connection {
256253
querystring: String,
257254
parameters: Option<Vec<Py<PyAny>>>,
258255
prepared: Option<bool>,
259-
) -> RustPSQLDriverPyResult<()> {
256+
) -> PSQLPyResult<()> {
260257
let db_client = pyo3::Python::with_gil(|gil| self_.borrow(gil).db_client.clone());
261258

262259
if let Some(db_client) = db_client {
@@ -282,7 +279,7 @@ impl Connection {
282279
querystring: String,
283280
parameters: Option<pyo3::Py<PyAny>>,
284281
prepared: Option<bool>,
285-
) -> RustPSQLDriverPyResult<PSQLDriverPyQueryResult> {
282+
) -> PSQLPyResult<PSQLDriverPyQueryResult> {
286283
let db_client = pyo3::Python::with_gil(|gil| self_.borrow(gil).db_client.clone());
287284

288285
if let Some(db_client) = db_client {
@@ -312,7 +309,7 @@ impl Connection {
312309
querystring: String,
313310
parameters: Option<pyo3::Py<PyAny>>,
314311
prepared: Option<bool>,
315-
) -> RustPSQLDriverPyResult<PSQLDriverSinglePyQueryResult> {
312+
) -> PSQLPyResult<PSQLDriverSinglePyQueryResult> {
316313
let db_client = pyo3::Python::with_gil(|gil| self_.borrow(gil).db_client.clone());
317314

318315
if let Some(db_client) = db_client {
@@ -339,7 +336,7 @@ impl Connection {
339336
querystring: String,
340337
parameters: Option<pyo3::Py<PyAny>>,
341338
prepared: Option<bool>,
342-
) -> RustPSQLDriverPyResult<Py<PyAny>> {
339+
) -> PSQLPyResult<Py<PyAny>> {
343340
let db_client = pyo3::Python::with_gil(|gil| self_.borrow(gil).db_client.clone());
344341

345342
if let Some(db_client) = db_client {
@@ -365,7 +362,7 @@ impl Connection {
365362
read_variant: Option<ReadVariant>,
366363
deferrable: Option<bool>,
367364
synchronous_commit: Option<SynchronousCommit>,
368-
) -> RustPSQLDriverPyResult<Transaction> {
365+
) -> PSQLPyResult<Transaction> {
369366
if let Some(db_client) = &self.db_client {
370367
return Ok(Transaction::new(
371368
db_client.clone(),
@@ -401,7 +398,7 @@ impl Connection {
401398
fetch_number: Option<usize>,
402399
scroll: Option<bool>,
403400
prepared: Option<bool>,
404-
) -> RustPSQLDriverPyResult<Cursor> {
401+
) -> PSQLPyResult<Cursor> {
405402
if let Some(db_client) = &self.db_client {
406403
return Ok(Cursor::new(
407404
db_client.clone(),
@@ -446,7 +443,7 @@ impl Connection {
446443
table_name: String,
447444
columns: Option<Vec<String>>,
448445
schema_name: Option<String>,
449-
) -> RustPSQLDriverPyResult<u64> {
446+
) -> PSQLPyResult<u64> {
450447
let db_client = pyo3::Python::with_gil(|gil| self_.borrow(gil).db_client.clone());
451448
let mut table_name = quote_ident(&table_name);
452449
if let Some(schema_name) = schema_name {

src/driver/connection_pool.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use pyo3::{pyclass, pyfunction, pymethods, Py, PyAny};
44
use std::sync::Arc;
55
use tokio_postgres::Config;
66

7-
use crate::exceptions::rust_errors::{RustPSQLDriverError, RustPSQLDriverPyResult};
7+
use crate::exceptions::rust_errors::{PSQLPyResult, RustPSQLDriverError};
88

99
use super::{
1010
common_options::{ConnRecyclingMethod, LoadBalanceHosts, SslMode, TargetSessionAttrs},
@@ -75,7 +75,7 @@ pub fn connect(
7575
ca_file: Option<String>,
7676
max_db_pool_size: Option<usize>,
7777
conn_recycling_method: Option<ConnRecyclingMethod>,
78-
) -> RustPSQLDriverPyResult<ConnectionPool> {
78+
) -> PSQLPyResult<ConnectionPool> {
7979
if let Some(max_db_pool_size) = max_db_pool_size {
8080
if max_db_pool_size < 2 {
8181
return Err(RustPSQLDriverError::ConnectionPoolConfigurationError(
@@ -289,7 +289,7 @@ impl ConnectionPool {
289289
conn_recycling_method: Option<ConnRecyclingMethod>,
290290
ssl_mode: Option<SslMode>,
291291
ca_file: Option<String>,
292-
) -> RustPSQLDriverPyResult<Self> {
292+
) -> PSQLPyResult<Self> {
293293
connect(
294294
dsn,
295295
username,
@@ -382,7 +382,7 @@ impl ConnectionPool {
382382
///
383383
/// # Errors
384384
/// May return Err Result if cannot get new connection from the pool.
385-
pub async fn connection(self_: pyo3::Py<Self>) -> RustPSQLDriverPyResult<Connection> {
385+
pub async fn connection(self_: pyo3::Py<Self>) -> PSQLPyResult<Connection> {
386386
let (db_pool, pg_config) = pyo3::Python::with_gil(|gil| {
387387
let slf = self_.borrow(gil);
388388
(slf.pool.clone(), slf.pg_config.clone())

src/driver/connection_pool_builder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{net::IpAddr, time::Duration};
33
use deadpool_postgres::{Manager, ManagerConfig, Pool, RecyclingMethod};
44
use pyo3::{pyclass, pymethods, Py, Python};
55

6-
use crate::exceptions::rust_errors::{RustPSQLDriverError, RustPSQLDriverPyResult};
6+
use crate::exceptions::rust_errors::{PSQLPyResult, RustPSQLDriverError};
77

88
use super::{
99
common_options,
@@ -38,7 +38,7 @@ impl ConnectionPoolBuilder {
3838
///
3939
/// # Errors
4040
/// May return error if cannot build new connection pool.
41-
fn build(&self) -> RustPSQLDriverPyResult<ConnectionPool> {
41+
fn build(&self) -> PSQLPyResult<ConnectionPool> {
4242
let mgr_config: ManagerConfig;
4343
if let Some(conn_recycling_method) = self.conn_recycling_method.as_ref() {
4444
mgr_config = ManagerConfig {
@@ -84,7 +84,7 @@ impl ConnectionPoolBuilder {
8484
///
8585
/// # Error
8686
/// If size more than 2.
87-
fn max_pool_size(self_: Py<Self>, pool_size: usize) -> RustPSQLDriverPyResult<Py<Self>> {
87+
fn max_pool_size(self_: Py<Self>, pool_size: usize) -> PSQLPyResult<Py<Self>> {
8888
if pool_size < 2 {
8989
return Err(RustPSQLDriverError::ConnectionPoolConfigurationError(
9090
"Maximum database pool size must be more than 1".into(),

src/driver/cursor.rs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use pyo3::{
66
use tokio_postgres::{config::Host, Config};
77

88
use crate::{
9-
exceptions::rust_errors::{RustPSQLDriverError, RustPSQLDriverPyResult},
9+
exceptions::rust_errors::{PSQLPyResult, RustPSQLDriverError},
1010
query_result::PSQLDriverPyQueryResult,
1111
runtime::rustdriver_future,
1212
};
@@ -23,9 +23,9 @@ trait CursorObjectTrait {
2323
querystring: &str,
2424
prepared: &Option<bool>,
2525
parameters: &Option<Py<PyAny>>,
26-
) -> RustPSQLDriverPyResult<()>;
26+
) -> PSQLPyResult<()>;
2727

28-
async fn cursor_close(&self, closed: &bool, cursor_name: &str) -> RustPSQLDriverPyResult<()>;
28+
async fn cursor_close(&self, closed: &bool, cursor_name: &str) -> PSQLPyResult<()>;
2929
}
3030

3131
impl CursorObjectTrait for PsqlpyConnection {
@@ -43,7 +43,7 @@ impl CursorObjectTrait for PsqlpyConnection {
4343
querystring: &str,
4444
prepared: &Option<bool>,
4545
parameters: &Option<Py<PyAny>>,
46-
) -> RustPSQLDriverPyResult<()> {
46+
) -> PSQLPyResult<()> {
4747
let mut cursor_init_query = format!("DECLARE {cursor_name}");
4848
if let Some(scroll) = scroll {
4949
if *scroll {
@@ -70,7 +70,7 @@ impl CursorObjectTrait for PsqlpyConnection {
7070
///
7171
/// # Errors
7272
/// May return Err Result if cannot execute querystring.
73-
async fn cursor_close(&self, closed: &bool, cursor_name: &str) -> RustPSQLDriverPyResult<()> {
73+
async fn cursor_close(&self, closed: &bool, cursor_name: &str) -> PSQLPyResult<()> {
7474
if *closed {
7575
return Err(RustPSQLDriverError::CursorCloseError(
7676
"Cursor is already closed".into(),
@@ -232,7 +232,7 @@ impl Cursor {
232232
slf
233233
}
234234

235-
async fn __aenter__<'a>(slf: Py<Self>) -> RustPSQLDriverPyResult<Py<Self>> {
235+
async fn __aenter__<'a>(slf: Py<Self>) -> PSQLPyResult<Py<Self>> {
236236
let (db_transaction, cursor_name, scroll, querystring, prepared, parameters) =
237237
Python::with_gil(|gil| {
238238
let self_ = slf.borrow(gil);
@@ -265,7 +265,7 @@ impl Cursor {
265265
_exception_type: Py<PyAny>,
266266
exception: Py<PyAny>,
267267
_traceback: Py<PyAny>,
268-
) -> RustPSQLDriverPyResult<()> {
268+
) -> PSQLPyResult<()> {
269269
let (db_transaction, closed, cursor_name, is_exception_none, py_err) =
270270
pyo3::Python::with_gil(|gil| {
271271
let self_ = slf.borrow(gil);
@@ -307,7 +307,7 @@ impl Cursor {
307307
/// we didn't find any solution how to implement it without
308308
/// # Errors
309309
/// May return Err Result if can't execute querystring.
310-
fn __anext__(&self) -> RustPSQLDriverPyResult<Option<PyObject>> {
310+
fn __anext__(&self) -> PSQLPyResult<Option<PyObject>> {
311311
let db_transaction = self.db_transaction.clone();
312312
let fetch_number = self.fetch_number;
313313
let cursor_name = self.cursor_name.clone();
@@ -343,7 +343,7 @@ impl Cursor {
343343
/// # Errors
344344
/// May return Err Result
345345
/// if cannot execute querystring for cursor declaration.
346-
pub async fn start(&mut self) -> RustPSQLDriverPyResult<()> {
346+
pub async fn start(&mut self) -> PSQLPyResult<()> {
347347
let db_transaction_arc = self.db_transaction.clone();
348348

349349
if let Some(db_transaction) = db_transaction_arc {
@@ -370,7 +370,7 @@ impl Cursor {
370370
///
371371
/// # Errors
372372
/// May return Err Result if cannot execute query.
373-
pub async fn close(&mut self) -> RustPSQLDriverPyResult<()> {
373+
pub async fn close(&mut self) -> PSQLPyResult<()> {
374374
let db_transaction_arc = self.db_transaction.clone();
375375

376376
if let Some(db_transaction) = db_transaction_arc {
@@ -396,7 +396,7 @@ impl Cursor {
396396
pub async fn fetch<'a>(
397397
slf: Py<Self>,
398398
fetch_number: Option<usize>,
399-
) -> RustPSQLDriverPyResult<PSQLDriverPyQueryResult> {
399+
) -> PSQLPyResult<PSQLDriverPyQueryResult> {
400400
let (db_transaction, inner_fetch_number, cursor_name) = Python::with_gil(|gil| {
401401
let self_ = slf.borrow(gil);
402402
(
@@ -437,7 +437,7 @@ impl Cursor {
437437
///
438438
/// # Errors
439439
/// May return Err Result if cannot execute query.
440-
pub async fn fetch_next<'a>(slf: Py<Self>) -> RustPSQLDriverPyResult<PSQLDriverPyQueryResult> {
440+
pub async fn fetch_next<'a>(slf: Py<Self>) -> PSQLPyResult<PSQLDriverPyQueryResult> {
441441
let (db_transaction, cursor_name) = Python::with_gil(|gil| {
442442
let self_ = slf.borrow(gil);
443443
(self_.db_transaction.clone(), self_.cursor_name.clone())
@@ -464,7 +464,7 @@ impl Cursor {
464464
///
465465
/// # Errors
466466
/// May return Err Result if cannot execute query.
467-
pub async fn fetch_prior<'a>(slf: Py<Self>) -> RustPSQLDriverPyResult<PSQLDriverPyQueryResult> {
467+
pub async fn fetch_prior<'a>(slf: Py<Self>) -> PSQLPyResult<PSQLDriverPyQueryResult> {
468468
let (db_transaction, cursor_name) = Python::with_gil(|gil| {
469469
let self_ = slf.borrow(gil);
470470
(self_.db_transaction.clone(), self_.cursor_name.clone())
@@ -491,7 +491,7 @@ impl Cursor {
491491
///
492492
/// # Errors
493493
/// May return Err Result if cannot execute query.
494-
pub async fn fetch_first<'a>(slf: Py<Self>) -> RustPSQLDriverPyResult<PSQLDriverPyQueryResult> {
494+
pub async fn fetch_first<'a>(slf: Py<Self>) -> PSQLPyResult<PSQLDriverPyQueryResult> {
495495
let (db_transaction, cursor_name) = Python::with_gil(|gil| {
496496
let self_ = slf.borrow(gil);
497497
(self_.db_transaction.clone(), self_.cursor_name.clone())
@@ -518,7 +518,7 @@ impl Cursor {
518518
///
519519
/// # Errors
520520
/// May return Err Result if cannot execute query.
521-
pub async fn fetch_last<'a>(slf: Py<Self>) -> RustPSQLDriverPyResult<PSQLDriverPyQueryResult> {
521+
pub async fn fetch_last<'a>(slf: Py<Self>) -> PSQLPyResult<PSQLDriverPyQueryResult> {
522522
let (db_transaction, cursor_name) = Python::with_gil(|gil| {
523523
let self_ = slf.borrow(gil);
524524
(self_.db_transaction.clone(), self_.cursor_name.clone())
@@ -548,7 +548,7 @@ impl Cursor {
548548
pub async fn fetch_absolute<'a>(
549549
slf: Py<Self>,
550550
absolute_number: i64,
551-
) -> RustPSQLDriverPyResult<PSQLDriverPyQueryResult> {
551+
) -> PSQLPyResult<PSQLDriverPyQueryResult> {
552552
let (db_transaction, cursor_name) = Python::with_gil(|gil| {
553553
let self_ = slf.borrow(gil);
554554
(self_.db_transaction.clone(), self_.cursor_name.clone())
@@ -582,7 +582,7 @@ impl Cursor {
582582
pub async fn fetch_relative<'a>(
583583
slf: Py<Self>,
584584
relative_number: i64,
585-
) -> RustPSQLDriverPyResult<PSQLDriverPyQueryResult> {
585+
) -> PSQLPyResult<PSQLDriverPyQueryResult> {
586586
let (db_transaction, cursor_name) = Python::with_gil(|gil| {
587587
let self_ = slf.borrow(gil);
588588
(self_.db_transaction.clone(), self_.cursor_name.clone())
@@ -613,9 +613,7 @@ impl Cursor {
613613
///
614614
/// # Errors
615615
/// May return Err Result if cannot execute query.
616-
pub async fn fetch_forward_all<'a>(
617-
slf: Py<Self>,
618-
) -> RustPSQLDriverPyResult<PSQLDriverPyQueryResult> {
616+
pub async fn fetch_forward_all<'a>(slf: Py<Self>) -> PSQLPyResult<PSQLDriverPyQueryResult> {
619617
let (db_transaction, cursor_name) = Python::with_gil(|gil| {
620618
let self_ = slf.borrow(gil);
621619
(self_.db_transaction.clone(), self_.cursor_name.clone())
@@ -649,7 +647,7 @@ impl Cursor {
649647
pub async fn fetch_backward<'a>(
650648
slf: Py<Self>,
651649
backward_count: i64,
652-
) -> RustPSQLDriverPyResult<PSQLDriverPyQueryResult> {
650+
) -> PSQLPyResult<PSQLDriverPyQueryResult> {
653651
let (db_transaction, cursor_name) = Python::with_gil(|gil| {
654652
let self_ = slf.borrow(gil);
655653
(self_.db_transaction.clone(), self_.cursor_name.clone())
@@ -680,9 +678,7 @@ impl Cursor {
680678
///
681679
/// # Errors
682680
/// May return Err Result if cannot execute query.
683-
pub async fn fetch_backward_all<'a>(
684-
slf: Py<Self>,
685-
) -> RustPSQLDriverPyResult<PSQLDriverPyQueryResult> {
681+
pub async fn fetch_backward_all<'a>(slf: Py<Self>) -> PSQLPyResult<PSQLDriverPyQueryResult> {
686682
let (db_transaction, cursor_name) = Python::with_gil(|gil| {
687683
let self_ = slf.borrow(gil);
688684
(self_.db_transaction.clone(), self_.cursor_name.clone())

0 commit comments

Comments
 (0)