Skip to content

Added more documentation #140

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
May 27, 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
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ crate-type = ["cdylib"]

[dependencies]
deadpool-postgres = { git = "https://github.com/chandr-andr/deadpool.git", branch = "psqlpy" }
pyo3 = { version = "0.23.4", features = ["chrono", "experimental-async", "rust_decimal", "py-clone", "macros", "multiple-pymethods"] }
pyo3 = { version = "0.23.4", features = [
"chrono",
"experimental-async",
"rust_decimal",
"py-clone",
"macros",
"multiple-pymethods",
] }
pyo3-async-runtimes = { git = "https://github.com/chandr-andr/pyo3-async-runtimes.git", branch = "psqlpy", features = [
"tokio-runtime",
] }
Expand Down
18 changes: 9 additions & 9 deletions docs/.vuepress/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ export default sidebar({
"advanced_type_usage",
]
},
{
text: "Row Factories Usage",
prefix: "row_factories/",
collapsible: true,
children: [
"row_factories",
"predefined_row_factories",
]
},
{
text: "Frameworks Usage",
prefix: "frameworks/",
Expand All @@ -58,15 +67,6 @@ export default sidebar({
"robyn",
]
},
{
text: "Row Factories Usage",
prefix: "row_factories/",
collapsible: true,
children: [
"row_factories",
"predefined_row_factories",
]
},
],
},
{
Expand Down
8 changes: 4 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ highlights:
details: PSQLPy is under active development.
---
## What is PSQLPy
`PSQLPy` is a new Python driver for `PostgreSQL` fully written in Rust. It was inspired by `Psycopg3` and `AsyncPG`.
`PSQLPy` is a Python driver for `PostgreSQL` fully written in Rust. It was inspired by `Psycopg3` and `AsyncPG`.
This project has two main goals:
Make a interaction with the database as fast as possible and now `PSQLPy` shows itself to be times faster than the above drivers.
Don't make useless abstractions and make it like a mirror to `PostgreSQL`.
We found that communication with the database can be faster and safer, so we tried to implement a new PostgreSQL driver in Rust for Python.

It has all necessary components to create high-load and fault tolerance applications.

Expand Down Expand Up @@ -59,4 +58,5 @@ pip install git+https://github.com/psqlpy-python/psqlpy

## Join community!
You can get support from the creators and users of `PSQLPy` in some social media:
- [Telegram](https://t.me/+f3Y8mYKgXxhmYThi)
- [Telegram](https://t.me/+f3Y8mYKgXxhmYThi)
- [Discord](https://discord.gg/ugNhzmhZ)
7 changes: 3 additions & 4 deletions docs/components/connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ async def main() -> None:
```python
from psqlpy import connect

db_connection: Final = connect(
dsn="postgres://postgres:postgres@localhost:5432/postgres",
)

async def main() -> None:
db_connection: Final = await connect(
dsn="postgres://postgres:postgres@localhost:5432/postgres",
)
await db_connection.execute(...)
```

Expand Down
132 changes: 110 additions & 22 deletions docs/components/cursor.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,93 @@ title: Cursor
---

`Cursor` objects represents server-side `Cursor` in the `PostgreSQL`. [PostgreSQL docs](https://www.postgresql.org/docs/current/plpgsql-cursors.html).
::: important
Cursor always lives inside a transaction. If you don't begin transaction explicitly, it will be opened anyway.
:::

## Cursor Parameters

- `querystring`: specify query for cursor.
- `parameters`: parameters for the querystring. Default `None`
- `fetch_number`: default fetch number. It is used in `fetch()` method and in async iterator. Default 10
- `scroll`: is cursor scrollable or not. Default as in `PostgreSQL`.
- `fetch_number`: default fetch number. It is used in `fetch()` method and in async iterator.

## Cursor as async iterator
## Usage

The most common situation is using `Cursor` as async iterator.
Cursor can be used in different ways.

::: tabs
@tab Pre-Initialization
```python
from psqlpy import ConnectionPool, QueryResult

async def main() -> None:
db_pool = ConnectionPool()
connection = await db_pool.connection()

cursor = connection.cursor(
querystring="SELECT * FROM users WHERE id > $1",
parameters=[100],
fetch_number=10,
)
await cursor.start()
```

@tab Post-Initialization
```python
from psqlpy import ConnectionPool, QueryResult

async def main() -> None:
db_pool = ConnectionPool()
connection = await db_pool.connection()

cursor = connection.cursor()
await cursor.execute(
querystring="SELECT * FROM users WHERE id > $1",
parameters=[100],
)
result: QueryResult = await cursor.fetchone()
```

@tab Async Context Manager
```python
from psqlpy import ConnectionPool, QueryResult

async def main() -> None:
db_pool = ConnectionPool()
connection = await db_pool.connection()
transaction = await connection.transaction()

# Here we fetch 5 results in each iteration.
async with cursor in transaction.cursor(
querystring="SELECT * FROM users WHERE username = $1",
parameters=["Some_Username"],
fetch_number=5,
):
async for fetched_result in cursor:
dict_result: List[Dict[Any, Any]] = fetched_result.result()
... # do something with this result.

async with connection.cursor(
querystring="SELECT * FROM users WHERE id > $1",
parameters=[100],
array_size=10,
) as cursor:
result: QueryResult = await cursor.fetchone()
```

## Cursor methods
@tab Async Iterator
```python
from psqlpy import ConnectionPool, QueryResult

There are a lot of methods to work with cursor.
async def main() -> None:
db_pool = ConnectionPool()
connection = await db_pool.connection()

cursor = connection.cursor(
querystring="SELECT * FROM users WHERE id > $1",
parameters=[100],
fetch_number=10,
)
await cursor.start()

async for result in cursor:
print(result)
```
:::

## Cursor attributes
- `array_size`: get and set attribute. Used in async iterator and `fetch_many` method.

## Cursor methods
### Start
Declare (create) cursor.

Expand All @@ -58,14 +107,53 @@ async def main() -> None:
await cursor.close()
```

### Fetch
### Execute

You can fetch next `N` records from the cursor.
It's possible to specify `N` fetch record with parameter `fetch_number`, otherwise will be used `fetch_number` from the `Cursor` initialization.
Initialize cursor and make it ready for fetching.

::: important
If you initialized cursor with `start` method or via context manager, you don't have to use this method.
:::

#### Parameters:
- `querystring`: specify query for cursor.
- `parameters`: parameters for the querystring. Default `None`

```python
async def main() -> None:
result: QueryResult = await cursor.fetch(
fetch_number=100,
await cursor.execute(
querystring="SELECT * FROM users WHERE id > $1",
parameters=[100],
)
result: QueryResult = await cursor.fetchone()
```

### Fetchone

Fetch one result from the cursor.

```python
async def main() -> None:
result: QueryResult = await cursor.fetchone()
```

### Fetchmany

Fetch N results from the cursor. Default is `array_size`.

#### Parameters:
- `size`: number of records to fetch.

```python
async def main() -> None:
result: QueryResult = await cursor.fetchmany(size=10)
```

### Fetchall

Fetch all results from the cursor.

```python
async def main() -> None:
result: QueryResult = await cursor.fetchall()
```
2 changes: 0 additions & 2 deletions docs/components/transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,6 @@ async def main() -> None:
- `querystring`: Statement string.
- `parameters`: List of list of parameters for the statement string.
- `fetch_number`: rewrite default fetch_number. Default is 10.
- `scroll`: make cursor scrollable or not. Default is like in `PostgreSQL`.
- `prepared`: prepare querystring or not.

From `Transaction` you can create new `Cursor` object which represents cursor in the `PostgreSQL`. [PostgreSQL Docs](https://www.postgresql.org/docs/current/plpgsql-cursors.html)

Expand Down
10 changes: 5 additions & 5 deletions docs/introduction/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ title: What is PSQLPy?
`PSQLPy` is a new Python driver for PostgreSQL fully written in Rust. It was inspired by `Psycopg3` and `AsyncPG`.

With `PSQLPy` you can:
- Make an interaction with the PostgeSQL in your application much faster (2-3 times).
- Make an interaction with the PostgeSQL in your application faster.
- Be sure that there won't be any unexpected errors.
- Don't usually go to the documentation to search every question - we have awesome docstrings for every component.
- Don't usually go to the documentation to search every question - we have docstrings for every component.
- Use `MyPy` (or any other Python type checker) with confidence that exactly the types specified in the typing will be returned.
- Concentrate on writing your code, not understanding new abstractions in this library, we only have classes which represents PostgreSQL object (transaction, cursor, etc).

::: info
It is extremely important to understand that the library will provide a noticeable acceleration in working with the database only if your queries are optimized.
Otherwise, there will be acceleration, but not so significant
The library will provide a noticeable acceleration in working with the database only if your queries are optimized.
:::

## Important notes
Expand All @@ -22,4 +21,5 @@ But in some situations this behavior can break you application. As an example, i

## Join community!
You can get support from the creators of `PSQLPy` in some social media:
- [Telegram](https://t.me/+f3Y8mYKgXxhmYThi)
- [Telegram](https://t.me/+f3Y8mYKgXxhmYThi)
- [Discord](https://discord.gg/ugNhzmhZ)
16 changes: 16 additions & 0 deletions python/tests/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ async def test_cursor_as_async_context_manager(
assert len(results.result()) == number_database_records


async def test_cursor_as_async_iterator(
psql_pool: ConnectionPool,
table_name: str,
number_database_records: int,
) -> None:
connection = await psql_pool.connection()
all_results = []
async with connection.cursor(
querystring=f"SELECT * FROM {table_name}",
) as cursor:
async for results in cursor:
all_results.extend(results.result())

assert len(all_results) == number_database_records


async def test_cursor_send_underlying_connection_to_pool(
psql_pool: ConnectionPool,
table_name: str,
Expand Down
36 changes: 0 additions & 36 deletions src/connection/traits.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use postgres_types::{ToSql, Type};
use pyo3::PyAny;

Check warning on line 2 in src/connection/traits.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `pyo3::PyAny`

warning: unused import: `pyo3::PyAny` --> src/connection/traits.rs:2:5 | 2 | use pyo3::PyAny; | ^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
use tokio_postgres::{Row, Statement, ToStatement};

use crate::exceptions::rust_errors::PSQLPyResult;
Expand Down Expand Up @@ -58,7 +58,7 @@
if let Some(level) = isolation_level {
let level = &level.to_str_level();
querystring.push_str(format!(" ISOLATION LEVEL {level}").as_str());
};

Check warning on line 61 in src/connection/traits.rs

View workflow job for this annotation

GitHub Actions / clippy

unnecessary semicolon

warning: unnecessary semicolon --> src/connection/traits.rs:61:10 | 61 | }; | ^ help: remove | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_semicolon = note: `-W clippy::unnecessary-semicolon` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::unnecessary_semicolon)]`

querystring.push_str(match read_variant {
Some(ReadVariant::ReadOnly) => " READ ONLY",
Expand Down Expand Up @@ -101,39 +101,3 @@

fn rollback(&mut self) -> impl std::future::Future<Output = PSQLPyResult<()>>;
}

// pub trait Cursor {
// fn build_cursor_start_qs(
// &self,
// cursor_name: &str,
// scroll: &Option<bool>,
// querystring: &str,
// ) -> String {
// let mut cursor_init_query = format!("DECLARE {cursor_name}");
// if let Some(scroll) = scroll {
// if *scroll {
// cursor_init_query.push_str(" SCROLL");
// } else {
// cursor_init_query.push_str(" NO SCROLL");
// }
// }

// cursor_init_query.push_str(format!(" CURSOR FOR {querystring}").as_str());

// cursor_init_query
// }

// fn start_cursor(
// &mut self,
// cursor_name: &str,
// scroll: &Option<bool>,
// querystring: String,
// prepared: &Option<bool>,
// parameters: Option<pyo3::Py<PyAny>>,
// ) -> impl std::future::Future<Output = PSQLPyResult<()>>;

// fn close_cursor(
// &mut self,
// cursor_name: &str,
// ) -> impl std::future::Future<Output = PSQLPyResult<()>>;
// }
6 changes: 3 additions & 3 deletions src/driver/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,18 @@
($name:ident) => {
#[pymethods]
impl $name {
#[pyo3(signature = (querystring=None, parameters=None, fetch_number=None))]
#[pyo3(signature = (querystring=None, parameters=None, array_size=None))]
pub fn cursor(
&self,
querystring: Option<String>,
parameters: Option<Py<PyAny>>,
fetch_number: Option<i32>,
array_size: Option<i32>,
) -> PSQLPyResult<Cursor> {

Check warning on line 141 in src/driver/common.rs

View workflow job for this annotation

GitHub Actions / clippy

docs for function returning `Result` missing `# Errors` section

warning: docs for function returning `Result` missing `# Errors` section --> src/driver/common.rs:136:13 | 136 | / pub fn cursor( 137 | | &self, 138 | | querystring: Option<String>, 139 | | parameters: Option<Py<PyAny>>, 140 | | array_size: Option<i32>, 141 | | ) -> PSQLPyResult<Cursor> { | |_____________________________________^ ... 156 | impl_cursor_method!(Connection); | ------------------------------- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc = note: this warning originates in the macro `impl_cursor_method` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 141 in src/driver/common.rs

View workflow job for this annotation

GitHub Actions / clippy

docs for function returning `Result` missing `# Errors` section

warning: docs for function returning `Result` missing `# Errors` section --> src/driver/common.rs:136:13 | 136 | / pub fn cursor( 137 | | &self, 138 | | querystring: Option<String>, 139 | | parameters: Option<Py<PyAny>>, 140 | | array_size: Option<i32>, 141 | | ) -> PSQLPyResult<Cursor> { | |_____________________________________^ ... 155 | impl_cursor_method!(Transaction); | -------------------------------- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc = note: this warning originates in the macro `impl_cursor_method` (in Nightly builds, run with -Z macro-backtrace for more info)
Ok(Cursor::new(
self.conn.clone(),
querystring,
parameters,
fetch_number,
array_size,
self.pg_config.clone(),
None,
))
Expand All @@ -160,11 +160,11 @@
#[pymethods]
impl $name {
#[pyo3(signature = (querystring, parameters=None))]
pub async fn prepare(
&self,
querystring: String,
parameters: Option<pyo3::Py<PyAny>>,
) -> PSQLPyResult<PreparedStatement> {

Check warning on line 167 in src/driver/common.rs

View workflow job for this annotation

GitHub Actions / clippy

docs for function returning `Result` missing `# Errors` section

warning: docs for function returning `Result` missing `# Errors` section --> src/driver/common.rs:163:13 | 163 | / pub async fn prepare( 164 | | &self, 165 | | querystring: String, 166 | | parameters: Option<pyo3::Py<PyAny>>, 167 | | ) -> PSQLPyResult<PreparedStatement> { | |________________________________________________^ ... 188 | impl_prepare_method!(Connection); | -------------------------------- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc = note: this warning originates in the macro `impl_prepare_method` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 167 in src/driver/common.rs

View workflow job for this annotation

GitHub Actions / clippy

docs for function returning `Result` missing `# Errors` section

warning: docs for function returning `Result` missing `# Errors` section --> src/driver/common.rs:163:13 | 163 | / pub async fn prepare( 164 | | &self, 165 | | querystring: String, 166 | | parameters: Option<pyo3::Py<PyAny>>, 167 | | ) -> PSQLPyResult<PreparedStatement> { | |________________________________________________^ ... 187 | impl_prepare_method!(Transaction); | --------------------------------- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc = note: this warning originates in the macro `impl_prepare_method` (in Nightly builds, run with -Z macro-backtrace for more info)
let Some(conn) = &self.conn else {
return Err(RustPSQLDriverError::ConnectionClosedError);
};
Expand All @@ -191,7 +191,7 @@
($name:ident, $val:expr $(,)?) => {
#[pymethods]
impl $name {
pub async fn commit(&mut self) -> PSQLPyResult<()> {

Check warning on line 194 in src/driver/common.rs

View workflow job for this annotation

GitHub Actions / clippy

docs for function returning `Result` missing `# Errors` section

warning: docs for function returning `Result` missing `# Errors` section --> src/driver/common.rs:194:13 | 194 | pub async fn commit(&mut self) -> PSQLPyResult<()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... 227 | impl_transaction_methods!(Transaction, true); | -------------------------------------------- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc = note: this warning originates in the macro `impl_transaction_methods` (in Nightly builds, run with -Z macro-backtrace for more info)
let conn = self.conn.clone();
let Some(conn) = conn else {
return Err(RustPSQLDriverError::TransactionClosedError("1".into()));
Expand All @@ -206,7 +206,7 @@
Ok(())
}

pub async fn rollback(&mut self) -> PSQLPyResult<()> {

Check warning on line 209 in src/driver/common.rs

View workflow job for this annotation

GitHub Actions / clippy

docs for function returning `Result` missing `# Errors` section

warning: docs for function returning `Result` missing `# Errors` section --> src/driver/common.rs:209:13 | 209 | pub async fn rollback(&mut self) -> PSQLPyResult<()> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... 227 | impl_transaction_methods!(Transaction, true); | -------------------------------------------- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc = note: this warning originates in the macro `impl_transaction_methods` (in Nightly builds, run with -Z macro-backtrace for more info)
let conn = self.conn.clone();
let Some(conn) = conn else {
return Err(RustPSQLDriverError::TransactionClosedError("2".into()));
Expand All @@ -231,13 +231,13 @@
#[pymethods]
impl $name {
#[pyo3(signature = (source, table_name, columns=None, schema_name=None))]
pub async fn binary_copy_to_table(
self_: pyo3::Py<Self>,
source: Py<PyAny>,
table_name: String,
columns: Option<Vec<String>>,
schema_name: Option<String>,
) -> PSQLPyResult<u64> {

Check warning on line 240 in src/driver/common.rs

View workflow job for this annotation

GitHub Actions / clippy

docs for function returning `Result` missing `# Errors` section

warning: docs for function returning `Result` missing `# Errors` section --> src/driver/common.rs:234:13 | 234 | / pub async fn binary_copy_to_table( 235 | | self_: pyo3::Py<Self>, 236 | | source: Py<PyAny>, 237 | | table_name: String, 238 | | columns: Option<Vec<String>>, 239 | | schema_name: Option<String>, 240 | | ) -> PSQLPyResult<u64> { | |__________________________________^ ... 291 | impl_binary_copy_method!(Transaction); | ------------------------------------- in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc = note: this warning originates in the macro `impl_binary_copy_method` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 240 in src/driver/common.rs

View workflow job for this annotation

GitHub Actions / clippy

docs for function returning `Result` missing `# Errors` section

warning: docs for function returning `Result` missing `# Errors` section --> src/driver/common.rs:234:13 | 234 | / pub async fn binary_copy_to_table( 235 | | self_: pyo3::Py<Self>, 236 | | source: Py<PyAny>, 237 | | table_name: String, 238 | | columns: Option<Vec<String>>, 239 | | schema_name: Option<String>, 240 | | ) -> PSQLPyResult<u64> { | |__________________________________^ ... 290 | impl_binary_copy_method!(Connection); | ------------------------------------ in this macro invocation | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc = note: this warning originates in the macro `impl_binary_copy_method` (in Nightly builds, run with -Z macro-backtrace for more info)
let db_client = pyo3::Python::with_gil(|gil| self_.borrow(gil).conn.clone());
let mut table_name = quote_ident(&table_name);
if let Some(schema_name) = schema_name {
Expand Down
2 changes: 1 addition & 1 deletion src/driver/connection.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use deadpool_postgres::Pool;
use pyo3::{ffi::PyObject, pyclass, pyfunction, pymethods, Py, PyAny, PyErr};
use pyo3::{pyclass, pyfunction, pymethods, Py, PyAny, PyErr};
use std::sync::Arc;
use tokio::sync::RwLock;
use tokio_postgres::Config;
Expand Down Expand Up @@ -158,7 +158,7 @@
read_conn_g.in_transaction()
}

async fn __aenter__<'a>(self_: Py<Self>) -> PSQLPyResult<Py<Self>> {

Check warning on line 161 in src/driver/connection.rs

View workflow job for this annotation

GitHub Actions / clippy

this lifetime isn't used in the function definition

warning: this lifetime isn't used in the function definition --> src/driver/connection.rs:161:25 | 161 | async fn __aenter__<'a>(self_: Py<Self>) -> PSQLPyResult<Py<Self>> { | ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes = note: `-W clippy::extra-unused-lifetimes` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::extra_unused_lifetimes)]`
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 @@
}

#[allow(clippy::unused_async)]
async fn __aexit__<'a>(

Check warning on line 194 in src/driver/connection.rs

View workflow job for this annotation

GitHub Actions / clippy

this lifetime isn't used in the function definition

warning: this lifetime isn't used in the function definition --> src/driver/connection.rs:194:24 | 194 | async fn __aexit__<'a>( | ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes
self_: Py<Self>,
_exception_type: Py<PyAny>,
exception: Py<PyAny>,
Expand Down Expand Up @@ -278,7 +278,7 @@
/// 1) Cannot convert python parameters
/// 2) Cannot execute querystring.
#[pyo3(signature = (querystring, parameters=None, prepared=None))]
pub async fn execute_many<'a>(

Check warning on line 281 in src/driver/connection.rs

View workflow job for this annotation

GitHub Actions / clippy

this lifetime isn't used in the function definition

warning: this lifetime isn't used in the function definition --> src/driver/connection.rs:281:31 | 281 | pub async fn execute_many<'a>( | ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes
self_: pyo3::Py<Self>,
querystring: String,
parameters: Option<Vec<Py<PyAny>>>,
Expand Down Expand Up @@ -369,7 +369,7 @@
/// 2) Cannot execute querystring.
/// 3) Query returns more than one row
#[pyo3(signature = (querystring, parameters=None, prepared=None))]
pub async fn fetch_val<'a>(

Check warning on line 372 in src/driver/connection.rs

View workflow job for this annotation

GitHub Actions / clippy

this lifetime isn't used in the function definition

warning: this lifetime isn't used in the function definition --> src/driver/connection.rs:372:28 | 372 | pub async fn fetch_val<'a>( | ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes
self_: pyo3::Py<Self>,
querystring: String,
parameters: Option<pyo3::Py<PyAny>>,
Expand Down
3 changes: 1 addition & 2 deletions src/driver/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::sync::Arc;

use pyo3::{
exceptions::PyStopAsyncIteration, pyclass, pymethods, types::PyNone, Py, PyAny, PyErr,
PyObject, Python,
exceptions::PyStopAsyncIteration, pyclass, pymethods, Py, PyAny, PyErr, PyObject, Python,
};
use tokio::sync::RwLock;
use tokio_postgres::{Config, Portal as tp_Portal};
Expand Down Expand Up @@ -33,14 +32,14 @@
}

impl Cursor {
pub fn new(
conn: Option<Arc<RwLock<PSQLPyConnection>>>,
querystring: Option<String>,
parameters: Option<Py<PyAny>>,
array_size: Option<i32>,
pg_config: Arc<Config>,
statement: Option<PsqlpyStatement>,
) -> Self {

Check warning on line 42 in src/driver/cursor.rs

View workflow job for this annotation

GitHub Actions / clippy

this method could have a `#[must_use]` attribute

warning: this method could have a `#[must_use]` attribute --> src/driver/cursor.rs:35:5 | 35 | / pub fn new( 36 | | conn: Option<Arc<RwLock<PSQLPyConnection>>>, 37 | | querystring: Option<String>, 38 | | parameters: Option<Py<PyAny>>, ... | 41 | | statement: Option<PsqlpyStatement>, 42 | | ) -> Self { | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate help: add the attribute | 35 | #[must_use] pub fn new( | +++++++++++
Self {
conn,
transaction: None,
Expand All @@ -60,7 +59,7 @@
let Some(portal) = &self.inner else {
return Err(RustPSQLDriverError::TransactionClosedError("4".into()));
};
transaction.query_portal(&portal, size).await

Check warning on line 62 in src/driver/cursor.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> src/driver/cursor.rs:62:34 | 62 | transaction.query_portal(&portal, size).await | ^^^^^^^ help: change this to: `portal` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
}
}

Expand Down Expand Up @@ -91,7 +90,7 @@
slf
}

async fn __aenter__<'a>(slf: Py<Self>) -> PSQLPyResult<Py<Self>> {

Check warning on line 93 in src/driver/cursor.rs

View workflow job for this annotation

GitHub Actions / clippy

this lifetime isn't used in the function definition

warning: this lifetime isn't used in the function definition --> src/driver/cursor.rs:93:25 | 93 | async fn __aenter__<'a>(slf: Py<Self>) -> PSQLPyResult<Py<Self>> { | ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes
let (conn, querystring, parameters, statement) = Python::with_gil(|gil| {
let self_ = slf.borrow(gil);
(
Expand All @@ -107,21 +106,21 @@
};
let mut write_conn_g = conn.write().await;

let (txid, inner_portal) = match querystring {
Some(querystring) => {
write_conn_g
.portal(Some(&querystring), &parameters, None)
.await?
}
None => {
let Some(statement) = statement else {
return Err(RustPSQLDriverError::CursorStartError(
"Cannot start cursor".into(),
));
};
write_conn_g.portal(None, &None, Some(&statement)).await?
}
};

Check warning on line 123 in src/driver/cursor.rs

View workflow job for this annotation

GitHub Actions / clippy

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`

warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/driver/cursor.rs:109:36 | 109 | let (txid, inner_portal) = match querystring { | ____________________________________^ 110 | | Some(querystring) => { 111 | | write_conn_g 112 | | .portal(Some(&querystring), &parameters, None) ... | 123 | | }; | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else help: try | 109 ~ let (txid, inner_portal) = if let Some(querystring) = querystring { 110 + write_conn_g 111 + .portal(Some(&querystring), &parameters, None) 112 + .await? 113 + } else { 114 + let Some(statement) = statement else { 115 + return Err(RustPSQLDriverError::CursorStartError( 116 + "Cannot start cursor".into(), 117 + )); 118 + }; 119 + write_conn_g.portal(None, &None, Some(&statement)).await? 120 ~ }; |

Python::with_gil(|gil| {
let mut self_ = slf.borrow_mut(gil);
Expand All @@ -134,7 +133,7 @@
}

#[allow(clippy::needless_pass_by_value)]
async fn __aexit__<'a>(

Check warning on line 136 in src/driver/cursor.rs

View workflow job for this annotation

GitHub Actions / clippy

this lifetime isn't used in the function definition

warning: this lifetime isn't used in the function definition --> src/driver/cursor.rs:136:24 | 136 | async fn __aexit__<'a>( | ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes
&mut self,
_exception_type: Py<PyAny>,
exception: Py<PyAny>,
Expand All @@ -158,7 +157,7 @@
fn __anext__(&self) -> PSQLPyResult<Option<PyObject>> {
let txid = self.transaction.clone();
let portal = self.inner.clone();
let size = self.array_size.clone();

Check warning on line 160 in src/driver/cursor.rs

View workflow job for this annotation

GitHub Actions / clippy

using `clone` on type `i32` which implements the `Copy` trait

warning: using `clone` on type `i32` which implements the `Copy` trait --> src/driver/cursor.rs:160:20 | 160 | let size = self.array_size.clone(); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try removing the `clone` call: `self.array_size` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy = note: `-W clippy::clone-on-copy` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::clone_on_copy)]`

let py_future = Python::with_gil(move |gil| {
rustdriver_future(gil, async move {
Expand All @@ -168,14 +167,14 @@
let Some(portal) = &portal else {
return Err(RustPSQLDriverError::TransactionClosedError("6".into()));
};
let result = txid.query_portal(&portal, size).await?;

Check warning on line 170 in src/driver/cursor.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> src/driver/cursor.rs:170:48 | 170 | let result = txid.query_portal(&portal, size).await?; | ^^^^^^^ help: change this to: `portal` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

if result.is_empty() {
return Err(PyStopAsyncIteration::new_err(
"Iteration is over, no more results in portal",
)
.into());
};

Check warning on line 177 in src/driver/cursor.rs

View workflow job for this annotation

GitHub Actions / clippy

unnecessary semicolon

warning: unnecessary semicolon --> src/driver/cursor.rs:177:18 | 177 | }; | ^ help: remove | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_semicolon

Ok(result)
})
Expand All @@ -190,10 +189,10 @@
};
let mut write_conn_g = conn.write().await;

let (txid, inner_portal) = match &self.querystring {
Some(querystring) => {
write_conn_g
.portal(Some(&querystring), &self.parameters, None)

Check warning on line 195 in src/driver/cursor.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> src/driver/cursor.rs:195:34 | 195 | .portal(Some(&querystring), &self.parameters, None) | ^^^^^^^^^^^^ help: change this to: `querystring` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
.await?
}
None => {
Expand All @@ -202,7 +201,7 @@
"Cannot start cursor".into(),
));
};
write_conn_g.portal(None, &None, Some(&statement)).await?

Check warning on line 204 in src/driver/cursor.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> src/driver/cursor.rs:204:55 | 204 | write_conn_g.portal(None, &None, Some(&statement)).await? | ^^^^^^^^^^ help: change this to: `statement` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
}
};

Check warning on line 206 in src/driver/cursor.rs

View workflow job for this annotation

GitHub Actions / clippy

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`

warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/driver/cursor.rs:192:36 | 192 | let (txid, inner_portal) = match &self.querystring { | ____________________________________^ 193 | | Some(querystring) => { 194 | | write_conn_g 195 | | .portal(Some(&querystring), &self.parameters, None) ... | 206 | | }; | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else help: try | 192 ~ let (txid, inner_portal) = if let Some(querystring) = &self.querystring { 193 + write_conn_g 194 + .portal(Some(&querystring), &self.parameters, None) 195 + .await? 196 + } else { 197 + let Some(statement) = &self.statement else { 198 + return Err(RustPSQLDriverError::CursorStartError( 199 + "Cannot start cursor".into(), 200 + )); 201 + }; 202 + write_conn_g.portal(None, &None, Some(&statement)).await? 203 ~ }; |

Expand Down
Loading