psqlpy-python / psqlpy

Asynchronous Python PostgreSQL driver written in Rust
https://psqlpy-python.github.io/
MIT License
227 stars 3 forks source link

Add a `row_factory` argument #47

Closed IvanKirpichnikov closed 4 months ago

IvanKirpichnikov commented 5 months ago

Add a row_factory argument to the ResultQuery.result and SingleQueryResult.result methods

You pass your function there, to which strings will fly. The function will process them. In turn, the result will be collected in a list and returned.

Example code

def my_row_factory(rows: list[str], data: list[Any]):
    return tuple(data)

data = query_result.result(row_factory=my_row_factory)
assert data == [(1, 'aaa', 34.13)]
chandr-andr commented 5 months ago

Thanks for the new feature request! We'll look into it as soon as possible

chandr-andr commented 4 months ago

@IvanKirpichnikov You can find row_factory as a method in QueryResult.

chandr-andr commented 4 months ago

As requested feature was developed, closing this issue. If there are any problems, don't hesitate to reopen it.