Skip to content
Open
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ repos:
hooks:
- id: trailing-whitespace
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v2.1.0
rev: v2.3.1
hooks:
- id: mypy
name: python mypy
always_run: true
pass_filenames: false
args: ["python"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.13
rev: v0.16.5
hooks:
# Run the linter.
- id: ruff-check
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ async def main() -> None:

print(res.result())
db_pool.close()

```

## Benchmarks
Expand Down
5 changes: 5 additions & 0 deletions docs/components/connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ db_pool: Final = ConnectionPool(
dsn="postgres://postgres:postgres@localhost:5432/postgres",
)


async def main() -> None:
connection = await db_pool.connection()
```
Expand All @@ -24,6 +25,7 @@ async def main() -> None:
```python
from psqlpy import connect


async def main() -> None:
db_connection: Final = await connect(
dsn="postgres://postgres:postgres@localhost:5432/postgres",
Expand All @@ -39,6 +41,7 @@ db_pool: Final = ConnectionPool(
dsn="postgres://postgres:postgres@localhost:5432/postgres",
)


async def main() -> None:
async with db_pool.acquire() as connection:
# connection is valid here
Expand Down Expand Up @@ -197,6 +200,7 @@ async def main() -> None:
```python
from psqlpy import IsolationLevel, ReadVariant


async def main() -> None:
...
connection = await db_pool.connection()
Expand Down Expand Up @@ -236,6 +240,7 @@ Prepare statement and return new instance.
```python
from psqlpy import IsolationLevel, ReadVariant


async def main() -> None:
...
connection = await db_pool.connection()
Expand Down
10 changes: 6 additions & 4 deletions docs/components/copy.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ This is the ergonomic alternative to `binary_copy_to_table` when you have Python
```python
from datetime import datetime, timezone


async def main() -> None:
...
connection = await db_pool.connection()
records = [
(1, "alpha", 1.5, datetime(2026, 1, 1, tzinfo=timezone.utc)),
(2, "beta", 2.25, datetime(2026, 1, 2, tzinfo=timezone.utc)),
(1, "alpha", 1.5, datetime(2026, 1, 1, tzinfo=timezone.utc)),
(2, "beta", 2.25, datetime(2026, 1, 2, tzinfo=timezone.utc)),
(3, "gamma", None, datetime(2026, 1, 3, tzinfo=timezone.utc)),
]
inserted = await connection.copy_records_to_table(
Expand All @@ -94,12 +95,13 @@ async def main() -> None:
```python
from datetime import datetime, timezone


async def main() -> None:
...
connection = await db_pool.connection()
records = [
(1, "alpha", 1.5, datetime(2026, 1, 1, tzinfo=timezone.utc)),
(2, "beta", 2.25, datetime(2026, 1, 2, tzinfo=timezone.utc)),
(1, "alpha", 1.5, datetime(2026, 1, 1, tzinfo=timezone.utc)),
(2, "beta", 2.25, datetime(2026, 1, 2, tzinfo=timezone.utc)),
(3, "gamma", None, datetime(2026, 1, 3, tzinfo=timezone.utc)),
]
async with connection.transaction() as transaction:
Expand Down
4 changes: 4 additions & 0 deletions docs/components/cursor.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Cursor can be used in different ways.
```python
from psqlpy import ConnectionPool, QueryResult


async def main() -> None:
db_pool = ConnectionPool()
connection = await db_pool.connection()
Expand All @@ -38,6 +39,7 @@ async def main() -> None:
```python
from psqlpy import ConnectionPool, QueryResult


async def main() -> None:
db_pool = ConnectionPool()
connection = await db_pool.connection()
Expand All @@ -54,6 +56,7 @@ async def main() -> None:
```python
from psqlpy import ConnectionPool, QueryResult


async def main() -> None:
db_pool = ConnectionPool()
connection = await db_pool.connection()
Expand All @@ -70,6 +73,7 @@ async def main() -> None:
```python
from psqlpy import ConnectionPool, QueryResult


async def main() -> None:
db_pool = ConnectionPool()
connection = await db_pool.connection()
Expand Down
14 changes: 8 additions & 6 deletions docs/components/listener.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ db_pool = ConnectionPool(
dsn="postgres://postgres:postgres@localhost:5432/postgres",
)


async def test_channel_callback(
connection: Connection,
payload: str,
Expand All @@ -30,6 +31,7 @@ async def test_channel_callback(
# do some important staff
...


async def main() -> None:
# Create listener object
listener: Listener = db_pool.listener()
Expand Down Expand Up @@ -66,6 +68,7 @@ db_pool = ConnectionPool(
dsn="postgres://postgres:postgres@localhost:5432/postgres",
)


async def main() -> None:
# Create listener object
listener: Listener = db_pool.listener()
Expand Down Expand Up @@ -127,22 +130,21 @@ Callback signature is like this:
```python
from psqlpy import Connection


async def callback(
connection: Connection,
payload: str,
channel: str,
process_id: int,
) -> None:
...
) -> None: ...
```

Parameters for callback are based like `args`, so this signature is correct to:
```python
async def callback(
connection: Connection,
*args,
) -> None:
...
) -> None: ...
```

**Example:**
Expand All @@ -152,8 +154,8 @@ async def test_channel_callback(
payload: str,
channel: str,
process_id: int,
) -> None:
...
) -> None: ...


async def main() -> None:
listener = db_pool.listener()
Expand Down
2 changes: 2 additions & 0 deletions docs/components/prepared_statement.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ db_pool: Final = ConnectionPool(
dsn="postgres://postgres:postgres@localhost:5432/postgres",
)


async def main() -> None:
connection = await db_pool.connection()
prepared_stmt = await connection.prepare(
Expand All @@ -34,6 +35,7 @@ db_pool: Final = ConnectionPool(
dsn="postgres://postgres:postgres@localhost:5432/postgres",
)


async def main() -> None:
connection = await db_pool.connection()
prepared_stmt: PreparedStatement = await connection.prepare(
Expand Down
3 changes: 1 addition & 2 deletions docs/components/transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ async def main() -> None:
),
]
)

```

### Create Savepoint
Expand Down Expand Up @@ -424,7 +423,7 @@ async def main() -> None:

async for fetched_result in cursor:
dict_result: List[Dict[Any, Any]] = fetched_result.result()
... # do something with the result.
... # do something with the result.
```

### COPY FROM STDIN
Expand Down
4 changes: 4 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The main problem is PostgreSQL expects `LIMIT` and `OFFSET` to be BIGINT type bu
from psqlpy import ConnectionPool
from psqlpy.extra_types import BigInt


# --- Incorrect ---
async def main() -> None:
pool = ConnectionPool()
Expand All @@ -37,6 +38,7 @@ Instead of using `WHERE <field> IN ()` clause you must use `WHERE <field> = ANY(
```python
from psqlpy import ConnectionPool


# --- Incorrect ---
async def main() -> None:
pool = ConnectionPool()
Expand Down Expand Up @@ -72,6 +74,7 @@ For example, when we want to make `WHERE` clause with `ANY` and string values, w
from psqlpy import ConnectionPool
from psqlpy.extra_types import TextArray


# --- Incorrect ---
async def main() -> None:
pool = ConnectionPool()
Expand Down Expand Up @@ -105,6 +108,7 @@ The main problem that we cannot determine the type of the empty sequence passed
from psqlpy import ConnectionPool
from psqlpy.extra_types import VarCharArray


# --- Incorrect ---
async def main() -> None:
pool = ConnectionPool()
Expand Down
3 changes: 1 addition & 2 deletions docs/usage/frameworks/aiohttp.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ async def pg_pool_example(request: web.Request):

application = web.Application()
application.on_startup.append(start_db_pool)
application.add_routes([web.get('/', pg_pool_example)])
application.add_routes([web.get("/", pg_pool_example)])


if __name__ == "__main__":
web.run_app(application)

```
1 change: 0 additions & 1 deletion docs/usage/frameworks/litestar.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,4 @@ if __name__ == "__main__":
uvicorn.run(
"start_example:app",
)

```
2 changes: 1 addition & 1 deletion docs/usage/frameworks/panther.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def pg_pool_example():
return Response(data=query_result.result())


app = Panther(__name__, configs=__name__, urls={'/': pg_pool_example})
app = Panther(__name__, configs=__name__, urls={"/": pg_pool_example})

if __name__ == "__main__":
uvicorn.run(app)
Expand Down
2 changes: 2 additions & 0 deletions docs/usage/row_factories/row_factories.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ValidationTestModel:
id: int
name: str


def to_class(
class_: Type[ValidationTestModel],
) -> Callable[[Dict[str, Any]], ValidationTestModel]:
Expand All @@ -26,6 +27,7 @@ def to_class(

return to_class_inner


async def main() -> None:
conn_result = await psql_pool.execute(
querystring=f"SELECT * FROM {table_name}",
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/types/array_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ async def main() -> None:
querystring="SELECT * FROM users WHERE name = ANY($1)",
parameters=[
TextArray(["Alex", "Dev", "Who"]),
]
],
)
```
21 changes: 16 additions & 5 deletions docs/usage/types/extra_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ async def main() -> None:
async with db_pool.acquire() as connection:
await connection.execute(
"INSERT INTO numbers (index, elf_life, elon_musk_money) VALUES ($1, $2, $3, $4, $5)",
[SmallInt(101), Integer(10500), BigInt(300000000000), Float32(123.11), Float64(222.12)],
[
SmallInt(101),
Integer(10500),
BigInt(300000000000),
Float32(123.11),
Float64(222.12),
],
)
```

Expand Down Expand Up @@ -119,7 +125,7 @@ my_dict = {
],
"with": {
"nested": "values",
}
},
}
```
On the other side, if you want to set list of values to JSON/JSONB field, you must wrap it in `PyJSON`/`PyJSONB` type, otherwise `PSQLPy` will assume that you passed an array (PostgreSQL `ARRAY`).
Expand Down Expand Up @@ -150,8 +156,11 @@ async def main() -> None:
dict_for_jsonb_field = {
"regular": "dict",
"with": [
"list", "of", "values", 100,
]
"list",
"of",
"values",
100,
],
}

async with db_pool.acquire() as connection:
Expand All @@ -161,7 +170,9 @@ async def main() -> None:
)
await connection.execute(
"INSERT INTO users (additional_user_info) VALUES ($1)",
[dict_for_jsonb_field,],
[
dict_for_jsonb_field,
],
)
```

Expand Down
4 changes: 0 additions & 4 deletions python/psqlpy/extra_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"JSONB",
"BigInt",
"BoolArray",
"BoolArray",
"Box",
"BoxArray",
"Circle",
Expand All @@ -73,8 +72,6 @@
"IntervalArray",
"IpAddressArray",
"JSONArray",
"JSONArray",
"JSONBArray",
"JSONBArray",
"Line",
"LineArray",
Expand All @@ -97,7 +94,6 @@
"TextArray",
"TimeArray",
"UUIDArray",
"UUIDArray",
"VarChar",
"VarCharArray",
]
Loading