From c514caf011b5d3e0006edece42309f5c477db91b Mon Sep 17 00:00:00 2001 From: Daniil Babin Date: Thu, 9 Oct 2025 14:10:12 +0500 Subject: [PATCH 1/6] Fixed code example of type usage docs --- docs/usage/types/advanced_type_usage.md | 28 +++++++++-------- docs/usage/types/array_types.md | 5 ++-- docs/usage/types/extra_types.md | 40 ++++++++++++++----------- docs/usage/types/supported_types.md | 14 +++++---- 4 files changed, 49 insertions(+), 38 deletions(-) diff --git a/docs/usage/types/advanced_type_usage.md b/docs/usage/types/advanced_type_usage.md index 2b562ff0..1624e335 100644 --- a/docs/usage/types/advanced_type_usage.md +++ b/docs/usage/types/advanced_type_usage.md @@ -6,7 +6,7 @@ Due to an unavailability to support all possible types in PostgreSQL, we have a This section has `Advanced` in the name because you'll need to work with raw bytes which can be difficult for some developers. ## Pass unsupported type into PostgreSQL -If you are using some type that we don't support and want to insert it into PostgreSQL from PSQLPy, you must use `PyCustomType` class. +If you are using some type that we don't support and want to insert it into PostgreSQL from PSQLPy, you must use `CustomType` class. Let's assume we have table `for_test` in the database and `PSQLPy` doesn't support (only for demonstration) `VARCHAR` type: | database type | database column name | @@ -15,25 +15,26 @@ Let's assume we have table `for_test` in the database and `PSQLPy` doesn't suppo ```python from typing import Final -from psqlpy import ConnectionPool -from psqlpy.extra_types import PyCustomType +from psqlpy import Connection, ConnectionPool +from psqlpy.extra_types import CustomType async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() + connection: Connection = await db_pool.connection() - await db_pool.execute( + await connection.execute( "INSERT INTO for_test (nickname) VALUES ($1)", - [PyCustomType(b"SomeDataInBytes")], + [CustomType(b"SomeDataInBytes")], ) - db_pool.close() + connection.close() ``` -Here we pass `PyCustomType` into the parameters. It accepts only bytes. +Here we pass `CustomType` into the parameters. It accepts only bytes. ::: important -You must make bytes passed into `PyCustomType` readable for `PostgreSQL`. +You must make bytes passed into `CustomType` readable for `PostgreSQL`. If bytes will be wrong, you will get an exception. ::: @@ -48,8 +49,8 @@ Let's assume we have table `for_test` in the database and `PSQLPy` doesn't suppo ```python from typing import Final, Any -from psqlpy import ConnectionPool, QueryResult -from psqlpy.extra_types import PyCustomType +from psqlpy import Connection, ConnectionPool, QueryResult +from psqlpy.extra_types import CustomType def nickname_decoder(bytes_from_psql: bytes | None) -> str: @@ -59,10 +60,11 @@ def nickname_decoder(bytes_from_psql: bytes | None) -> str: async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() + connection: Connection = await db_pool.connection() - result: QueryResult = await db_pool.execute( + result: QueryResult = await connection.execute( "SELECT * FROM for_test", - [PyCustomType(b"SomeDataInBytes")], + [CustomType(b"SomeDataInBytes")], ) parsed_result: list[dict[str, Any]] = result.result( @@ -70,7 +72,7 @@ async def main() -> None: "nickname": nickname_decoder, }, ) - db_pool.close() + connection.close() ``` ::: important diff --git a/docs/usage/types/array_types.md b/docs/usage/types/array_types.md index 312b4bb1..7defc239 100644 --- a/docs/usage/types/array_types.md +++ b/docs/usage/types/array_types.md @@ -36,13 +36,14 @@ For type safety and better performance we have predefined array types. ### Example: ```python -from psqlpy import ConnectionPool +from psqlpy import Connection, ConnectionPool from psqlpy.extra_types import TextArray async def main() -> None: pool = ConnectionPool() - result = await pool.execute( + connection: Connection = await pool.connection() + result = await connection.execute( querystring="SELECT * FROM users WHERE name = ANY($1)", parameters=[ TextArray(["Alex", "Dev", "Who"]), diff --git a/docs/usage/types/extra_types.md b/docs/usage/types/extra_types.md index 52431843..1ee8c163 100644 --- a/docs/usage/types/extra_types.md +++ b/docs/usage/types/extra_types.md @@ -48,19 +48,20 @@ And we want to INSERT new data to this table: ```python from typing import Final -from psqlpy import ConnectionPool, QueryResult +from psqlpy import Connection, ConnectionPool, QueryResult from psqlpy.extra_types import SmallInt, Integer, BigInt, Float32, Float64 async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() + connection: Connection = await db_pool.connection() - await db_pool.execute( + 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)], ) - db_pool.close() + connection.close() ``` ::: important @@ -81,24 +82,25 @@ Let's assume we have table `banners` in the database: ```python from typing import Final -from psqlpy import ConnectionPool, QueryResult +from psqlpy import Connection, ConnectionPool, QueryResult from psqlpy.extra_types import PyText async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() + connection: Connection = await db_pool.connection() - await db_pool.execute( + await connection.execute( "INSERT INTO banners (title, description) VALUES ($1, $2)", ["SomeTitle", PyText("Very long description")], ) # Alternatively, you can do this: - await db_pool.execute( + await connection.execute( "INSERT INTO banners (title, description) VALUES ($1, $2)", [PyVarChar("SomeTitle"), PyText("Very long description")], ) - db_pool.close() + connection.close() ``` ## PyJSON & PyJSONB @@ -126,13 +128,15 @@ Let's assume we have table `users` in the database, and field `additional_user_i ```python from typing import Final -from psqlpy import ConnectionPool, QueryResult +from psqlpy import Connection, ConnectionPool, QueryResult from psqlpy.extra_types import PyJSON async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() + connection: Connection = await db_pool.connection() + list_for_jsonb_field = [ {"some": "dict"}, [ @@ -147,16 +151,16 @@ async def main() -> None: ] } - await db_pool.execute( + await connection.execute( "INSERT INTO users (additional_user_info) VALUES ($1)", [PyJSONB(list_for_jsonb_field)], ) - await db_pool.execute( + await connection.execute( "INSERT INTO users (additional_user_info) VALUES ($1)", [dict_for_jsonb_field,], ) - db_pool.close() + connection.close() ``` ## PyMacAddr6 & PyMacAddr8 @@ -171,15 +175,16 @@ Let's assume we have table `devices` in the database: ```python from typing import Final -from psqlpy import ConnectionPool, QueryResult +from psqlpy import Connection, ConnectionPool, QueryResult from psqlpy.extra_types import PyMacAddr6, PyMacAddr8 async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() + connection: Connection = await db_pool.connection() - await db_pool.execute( + await connection.execute( "INSERT INTO devices (device_macaddr6, device_macaddr8) VALUES ($1, $2)", [ PyMacAddr6("08:00:2b:01:02:03"), @@ -187,7 +192,7 @@ async def main() -> None: ], ) - db_pool.close() + connection.close() ``` ## Geo Types @@ -207,15 +212,16 @@ Let's assume we have table `geo_info` with all PostgreSQL geo types in the datab ```python from typing import Final -from psqlpy import ConnectionPool, QueryResult +from psqlpy import Connection, ConnectionPool, QueryResult from psqlpy.extra_types import Point, Box, Path, Line, LineSegment, Circle async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() + connection: Connection = await db_pool.connection() - await db_pool.execute( + await connection.execute( "INSERT INTO geo_info VALUES ($1, $2, $3, $4, $5, $6)", [ Point([1.5, 2]), @@ -227,5 +233,5 @@ async def main() -> None: ], ) - db_pool.close() + connection.close() ``` diff --git a/docs/usage/types/supported_types.md b/docs/usage/types/supported_types.md index 70ecb803..bd5e71e8 100644 --- a/docs/usage/types/supported_types.md +++ b/docs/usage/types/supported_types.md @@ -79,15 +79,16 @@ Now we can see what result will be returned. ```python from typing import Final -from psqlpy import ConnectionPool, QueryResult +from psqlpy import Connection, ConnectionPool, QueryResult from psqlpy.extra_types import SmallInt, Integer, BigInt async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() + connection: Connection = await db_pool.connection() - result = await db_pool.execute( + result = await connection.execute( "SELECT user_info FROM custom_table", ) print(result.result()[0]) @@ -121,7 +122,7 @@ Let's see how we can INSERT and SELECT such data. from enum import Enum from typing import Final -from psqlpy import ConnectionPool, QueryResult +from psqlpy import Connection, ConnectionPool, QueryResult class Weather(str, Enum): @@ -132,20 +133,21 @@ class Weather(str, Enum): async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() + connection: Connection = await db_pool.connection() # Insert new data - await db_pool.execute( + await connection.execute( querystring="INSERT INTO weather_plus VALUES($1)", parameters=[Weather.SUN], ) # Or you can pass string directly - await db_pool.execute( + await connection.execute( querystring="INSERT INTO weather_plus VALUES($1)", parameters=["sun"], ) - result = await db_pool.execute( + result = await connection.execute( querystring="SELECT * FROM weather_plus", ) print(result.result()[0]) From 7ae6d2700fb182931d5ea4141e599493f5f4c12d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 9 Oct 2025 17:05:25 +0000 Subject: [PATCH 2/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/usage/types/extra_types.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/usage/types/extra_types.md b/docs/usage/types/extra_types.md index 1ee8c163..55655116 100644 --- a/docs/usage/types/extra_types.md +++ b/docs/usage/types/extra_types.md @@ -136,7 +136,7 @@ async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() connection: Connection = await db_pool.connection() - + list_for_jsonb_field = [ {"some": "dict"}, [ From 06d164e4e695e8ccd7252ce24ef38b4c0e562064 Mon Sep 17 00:00:00 2001 From: Daniil Babin Date: Fri, 10 Oct 2025 08:58:34 +0500 Subject: [PATCH 3/6] Fixed using connections in type usage docs --- docs/usage/types/advanced_type_usage.md | 28 +++--- docs/usage/types/array_types.md | 16 ++-- docs/usage/types/extra_types.md | 115 +++++++++++------------- docs/usage/types/supported_types.md | 49 +++++----- 4 files changed, 98 insertions(+), 110 deletions(-) diff --git a/docs/usage/types/advanced_type_usage.md b/docs/usage/types/advanced_type_usage.md index 1624e335..9569a05d 100644 --- a/docs/usage/types/advanced_type_usage.md +++ b/docs/usage/types/advanced_type_usage.md @@ -15,20 +15,19 @@ Let's assume we have table `for_test` in the database and `PSQLPy` doesn't suppo ```python from typing import Final -from psqlpy import Connection, ConnectionPool +from psqlpy import ConnectionPool from psqlpy.extra_types import CustomType async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() - connection: Connection = await db_pool.connection() - - await connection.execute( - "INSERT INTO for_test (nickname) VALUES ($1)", - [CustomType(b"SomeDataInBytes")], - ) - connection.close() + + async with db_pool.acquire() as connection: + await connection.execute( + "INSERT INTO for_test (nickname) VALUES ($1)", + [CustomType(b"SomeDataInBytes")], + ) ``` Here we pass `CustomType` into the parameters. It accepts only bytes. @@ -49,7 +48,7 @@ Let's assume we have table `for_test` in the database and `PSQLPy` doesn't suppo ```python from typing import Final, Any -from psqlpy import Connection, ConnectionPool, QueryResult +from psqlpy import ConnectionPool, QueryResult from psqlpy.extra_types import CustomType @@ -60,19 +59,18 @@ def nickname_decoder(bytes_from_psql: bytes | None) -> str: async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() - connection: Connection = await db_pool.connection() - result: QueryResult = await connection.execute( - "SELECT * FROM for_test", - [CustomType(b"SomeDataInBytes")], - ) + async with db_pool.acquire() as connection: + result: QueryResult = await connection.execute( + "SELECT * FROM for_test", + [CustomType(b"SomeDataInBytes")], + ) parsed_result: list[dict[str, Any]] = result.result( custom_decoders={ "nickname": nickname_decoder, }, ) - connection.close() ``` ::: important diff --git a/docs/usage/types/array_types.md b/docs/usage/types/array_types.md index 7defc239..b1f98336 100644 --- a/docs/usage/types/array_types.md +++ b/docs/usage/types/array_types.md @@ -36,17 +36,17 @@ For type safety and better performance we have predefined array types. ### Example: ```python -from psqlpy import Connection, ConnectionPool +from psqlpy import ConnectionPool from psqlpy.extra_types import TextArray async def main() -> None: pool = ConnectionPool() - connection: Connection = await pool.connection() - result = await connection.execute( - querystring="SELECT * FROM users WHERE name = ANY($1)", - parameters=[ - TextArray(["Alex", "Dev", "Who"]), - ] - ) + async with db_pool.acquire() as connection: + result = await connection.execute( + querystring="SELECT * FROM users WHERE name = ANY($1)", + parameters=[ + TextArray(["Alex", "Dev", "Who"]), + ] + ) ``` diff --git a/docs/usage/types/extra_types.md b/docs/usage/types/extra_types.md index 55655116..367cfff7 100644 --- a/docs/usage/types/extra_types.md +++ b/docs/usage/types/extra_types.md @@ -48,20 +48,18 @@ And we want to INSERT new data to this table: ```python from typing import Final -from psqlpy import Connection, ConnectionPool, QueryResult +from psqlpy import ConnectionPool, QueryResult from psqlpy.extra_types import SmallInt, Integer, BigInt, Float32, Float64 async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() - connection: Connection = await db_pool.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)], - ) - connection.close() + 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)], + ) ``` ::: important @@ -82,25 +80,24 @@ Let's assume we have table `banners` in the database: ```python from typing import Final -from psqlpy import Connection, ConnectionPool, QueryResult +from psqlpy import ConnectionPool, QueryResult from psqlpy.extra_types import PyText async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() - connection: Connection = await db_pool.connection() - - await connection.execute( - "INSERT INTO banners (title, description) VALUES ($1, $2)", - ["SomeTitle", PyText("Very long description")], - ) - # Alternatively, you can do this: - await connection.execute( - "INSERT INTO banners (title, description) VALUES ($1, $2)", - [PyVarChar("SomeTitle"), PyText("Very long description")], - ) - connection.close() + + async with db_pool.acquire() as connection: + await connection.execute( + "INSERT INTO banners (title, description) VALUES ($1, $2)", + ["SomeTitle", PyText("Very long description")], + ) + # Alternatively, you can do this: + await connection.execute( + "INSERT INTO banners (title, description) VALUES ($1, $2)", + [PyVarChar("SomeTitle"), PyText("Very long description")], + ) ``` ## PyJSON & PyJSONB @@ -128,15 +125,14 @@ Let's assume we have table `users` in the database, and field `additional_user_i ```python from typing import Final -from psqlpy import Connection, ConnectionPool, QueryResult +from psqlpy import ConnectionPool, QueryResult from psqlpy.extra_types import PyJSON async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() - connection: Connection = await db_pool.connection() - + list_for_jsonb_field = [ {"some": "dict"}, [ @@ -151,16 +147,15 @@ async def main() -> None: ] } - await connection.execute( - "INSERT INTO users (additional_user_info) VALUES ($1)", - [PyJSONB(list_for_jsonb_field)], - ) - await connection.execute( - "INSERT INTO users (additional_user_info) VALUES ($1)", - [dict_for_jsonb_field,], - ) - - connection.close() + async with db_pool.acquire() as connection: + await connection.execute( + "INSERT INTO users (additional_user_info) VALUES ($1)", + [PyJSONB(list_for_jsonb_field)], + ) + await connection.execute( + "INSERT INTO users (additional_user_info) VALUES ($1)", + [dict_for_jsonb_field,], + ) ``` ## PyMacAddr6 & PyMacAddr8 @@ -175,24 +170,22 @@ Let's assume we have table `devices` in the database: ```python from typing import Final -from psqlpy import Connection, ConnectionPool, QueryResult +from psqlpy import ConnectionPool, QueryResult from psqlpy.extra_types import PyMacAddr6, PyMacAddr8 async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() - connection: Connection = await db_pool.connection() - - await connection.execute( - "INSERT INTO devices (device_macaddr6, device_macaddr8) VALUES ($1, $2)", - [ - PyMacAddr6("08:00:2b:01:02:03"), - PyMacAddr8("08:00:2b:01:02:03:04:05"), - ], - ) - - connection.close() + + async with db_pool.acquire() as connection: + await connection.execute( + "INSERT INTO devices (device_macaddr6, device_macaddr8) VALUES ($1, $2)", + [ + PyMacAddr6("08:00:2b:01:02:03"), + PyMacAddr8("08:00:2b:01:02:03:04:05"), + ], + ) ``` ## Geo Types @@ -212,26 +205,24 @@ Let's assume we have table `geo_info` with all PostgreSQL geo types in the datab ```python from typing import Final -from psqlpy import Connection, ConnectionPool, QueryResult +from psqlpy import ConnectionPool, QueryResult from psqlpy.extra_types import Point, Box, Path, Line, LineSegment, Circle async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() - connection: Connection = await db_pool.connection() - - await connection.execute( - "INSERT INTO geo_info VALUES ($1, $2, $3, $4, $5, $6)", - [ - Point([1.5, 2]), - Box([(1.7, 2.8), (9, 9)]), - Path([(3.5, 3), (9, 9), (8, 8)]), - Line([1, -2, 3]), - LineSegment([(5.6, 3.1), (4, 5)]), - Circle([5, 1.8, 10]), - ], - ) - - connection.close() + + async with db_pool.acquire() as connection: + await connection.execute( + "INSERT INTO geo_info VALUES ($1, $2, $3, $4, $5, $6)", + [ + Point([1.5, 2]), + Box([(1.7, 2.8), (9, 9)]), + Path([(3.5, 3), (9, 9), (8, 8)]), + Line([1, -2, 3]), + LineSegment([(5.6, 3.1), (4, 5)]), + Circle([5, 1.8, 10]), + ], + ) ``` diff --git a/docs/usage/types/supported_types.md b/docs/usage/types/supported_types.md index bd5e71e8..1a48ca3f 100644 --- a/docs/usage/types/supported_types.md +++ b/docs/usage/types/supported_types.md @@ -79,19 +79,19 @@ Now we can see what result will be returned. ```python from typing import Final -from psqlpy import Connection, ConnectionPool, QueryResult +from psqlpy import ConnectionPool, QueryResult from psqlpy.extra_types import SmallInt, Integer, BigInt async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() - connection: Connection = await db_pool.connection() - - result = await connection.execute( - "SELECT user_info FROM custom_table", - ) - print(result.result()[0]) + + async with db_pool.acquire() as connection: + result = await connection.execute( + "SELECT user_info FROM custom_table", + ) + print(result.result()[0]) ``` It will return: ```json @@ -122,7 +122,7 @@ Let's see how we can INSERT and SELECT such data. from enum import Enum from typing import Final -from psqlpy import Connection, ConnectionPool, QueryResult +from psqlpy import ConnectionPool, QueryResult class Weather(str, Enum): @@ -133,23 +133,22 @@ class Weather(str, Enum): async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() - connection: Connection = await db_pool.connection() - - # Insert new data - await connection.execute( - querystring="INSERT INTO weather_plus VALUES($1)", - parameters=[Weather.SUN], - ) - - # Or you can pass string directly - await connection.execute( - querystring="INSERT INTO weather_plus VALUES($1)", - parameters=["sun"], - ) - - result = await connection.execute( - querystring="SELECT * FROM weather_plus", - ) + async with db_pool.acquire() as connection: + # Insert new data + await connection.execute( + querystring="INSERT INTO weather_plus VALUES($1)", + parameters=[Weather.SUN], + ) + + # Or you can pass string directly + await connection.execute( + querystring="INSERT INTO weather_plus VALUES($1)", + parameters=["sun"], + ) + + result = await connection.execute( + querystring="SELECT * FROM weather_plus", + ) print(result.result()[0]) ``` You will receive: From 0671b65f3c91e37a7f7cdf03a8b23fc8c6929aa0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 10 Oct 2025 04:04:39 +0000 Subject: [PATCH 4/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/usage/types/advanced_type_usage.md | 2 +- docs/usage/types/extra_types.md | 6 +++--- docs/usage/types/supported_types.md | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/usage/types/advanced_type_usage.md b/docs/usage/types/advanced_type_usage.md index 9569a05d..8ab3482e 100644 --- a/docs/usage/types/advanced_type_usage.md +++ b/docs/usage/types/advanced_type_usage.md @@ -22,7 +22,7 @@ from psqlpy.extra_types import CustomType async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() - + async with db_pool.acquire() as connection: await connection.execute( "INSERT INTO for_test (nickname) VALUES ($1)", diff --git a/docs/usage/types/extra_types.md b/docs/usage/types/extra_types.md index a52d9e71..a97e8560 100644 --- a/docs/usage/types/extra_types.md +++ b/docs/usage/types/extra_types.md @@ -139,7 +139,7 @@ from psqlpy.extra_types import PyJSON async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() - + list_for_jsonb_field = [ {"some": "dict"}, [ @@ -184,7 +184,7 @@ from psqlpy.extra_types import PyMacAddr6, PyMacAddr8 async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() - + async with db_pool.acquire() as connection: await connection.execute( "INSERT INTO devices (device_macaddr6, device_macaddr8) VALUES ($1, $2)", @@ -219,7 +219,7 @@ from psqlpy.extra_types import Point, Box, Path, Line, LineSegment, Circle async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() - + async with db_pool.acquire() as connection: await connection.execute( "INSERT INTO geo_info VALUES ($1, $2, $3, $4, $5, $6)", diff --git a/docs/usage/types/supported_types.md b/docs/usage/types/supported_types.md index 1a48ca3f..2ff5d822 100644 --- a/docs/usage/types/supported_types.md +++ b/docs/usage/types/supported_types.md @@ -86,7 +86,7 @@ from psqlpy.extra_types import SmallInt, Integer, BigInt async def main() -> None: # It uses default connection parameters db_pool: Final = ConnectionPool() - + async with db_pool.acquire() as connection: result = await connection.execute( "SELECT user_info FROM custom_table", From 708f7533d69c0e56b5c924e5a0d78a100401bdd4 Mon Sep 17 00:00:00 2001 From: Daniil Babin Date: Fri, 10 Oct 2025 09:40:25 +0500 Subject: [PATCH 5/6] Fixed clippy errors --- src/statement/parameters.rs | 2 +- src/value_converter/dto/impls.rs | 10 +++------- src/value_converter/to_python.rs | 27 +++++++-------------------- 3 files changed, 11 insertions(+), 28 deletions(-) diff --git a/src/statement/parameters.rs b/src/statement/parameters.rs index ac3f433f..52417497 100644 --- a/src/statement/parameters.rs +++ b/src/statement/parameters.rs @@ -16,7 +16,7 @@ use crate::{ }, }; -pub type QueryParameter = (dyn ToSql + Sync); +pub type QueryParameter = dyn ToSql + Sync; #[pyclass] #[derive(Default, Clone, Debug)] diff --git a/src/value_converter/dto/impls.rs b/src/value_converter/dto/impls.rs index 3450dfd0..ccb06243 100644 --- a/src/value_converter/dto/impls.rs +++ b/src/value_converter/dto/impls.rs @@ -177,18 +177,14 @@ impl ToSql for PythonDTO { as ToSql>::to_sql(pybytes, ty, out)?; } PythonDTO::PyBool(boolean) => types::bool_to_sql(*boolean, out), - PythonDTO::PyVarChar(string) => { - <&str as ToSql>::to_sql(&string.as_str(), ty, out)?; - } - PythonDTO::PyText(string) => { + PythonDTO::PyVarChar(string) + | PythonDTO::PyText(string) + | PythonDTO::PyString(string) => { <&str as ToSql>::to_sql(&string.as_str(), ty, out)?; } PythonDTO::PyUUID(pyuuid) => { ::to_sql(pyuuid, ty, out)?; } - PythonDTO::PyString(string) => { - <&str as ToSql>::to_sql(&string.as_str(), ty, out)?; - } PythonDTO::PyIntI16(int) => out.put_i16(*int), PythonDTO::PyIntI32(int) => out.put_i32(*int), PythonDTO::PyIntI64(int) | PythonDTO::PyMoney(int) => out.put_i64(*int), diff --git a/src/value_converter/to_python.rs b/src/value_converter/to_python.rs index cf0f6d35..288ea06f 100644 --- a/src/value_converter/to_python.rs +++ b/src/value_converter/to_python.rs @@ -180,14 +180,11 @@ fn postgres_bytes_to_py( } Ok(py.None()) } - Type::OID => Ok( - composite_field_postgres_to_py::>(type_, buf, is_simple)? - .into_py_any(py)?, - ), - Type::NAME => Ok( - composite_field_postgres_to_py::>(type_, buf, is_simple)? - .into_py_any(py)?, - ), + // Convert Integer into i32, then into int + Type::OID | Type::INT4 => Ok(composite_field_postgres_to_py::>( + type_, buf, is_simple, + )? + .into_py_any(py)?), // // ---------- String Types ---------- // // Convert TEXT and VARCHAR type into String, then into str Type::TEXT | Type::VARCHAR | Type::XML => Ok(composite_field_postgres_to_py::< @@ -206,11 +203,6 @@ fn postgres_bytes_to_py( composite_field_postgres_to_py::>(type_, buf, is_simple)? .into_py_any(py)?, ), - // Convert Integer into i32, then into int - Type::INT4 => Ok( - composite_field_postgres_to_py::>(type_, buf, is_simple)? - .into_py_any(py)?, - ), // Convert BigInt into i64, then into int Type::INT8 | Type::MONEY => Ok(composite_field_postgres_to_py::>( type_, buf, is_simple, @@ -363,7 +355,8 @@ fn postgres_bytes_to_py( composite_field_postgres_to_py::>>(type_, buf, is_simple)?, ) .into_py_any(py)?), - Type::OID_ARRAY => Ok(postgres_array_to_py( + // Convert ARRAY of Integer into Vec, then into list[int] + Type::OID_ARRAY | Type::INT4_ARRAY => Ok(postgres_array_to_py( py, composite_field_postgres_to_py::>>(type_, buf, is_simple)?, ) @@ -381,12 +374,6 @@ fn postgres_bytes_to_py( composite_field_postgres_to_py::>>(type_, buf, is_simple)?, ) .into_py_any(py)?), - // Convert ARRAY of Integer into Vec, then into list[int] - Type::INT4_ARRAY => Ok(postgres_array_to_py( - py, - composite_field_postgres_to_py::>>(type_, buf, is_simple)?, - ) - .into_py_any(py)?), // Convert ARRAY of BigInt into Vec, then into list[int] Type::INT8_ARRAY | Type::MONEY_ARRAY => Ok(postgres_array_to_py( py, From 5779b18bb1ff93dafc1e86fb1e5ab0ad38c0c4ed Mon Sep 17 00:00:00 2001 From: Daniil Babin Date: Fri, 10 Oct 2025 09:42:01 +0500 Subject: [PATCH 6/6] Added package names for installing to running tests --- docs/contribute.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/contribute.md b/docs/contribute.md index 4c654600..f3444435 100644 --- a/docs/contribute.md +++ b/docs/contribute.md @@ -22,7 +22,7 @@ One of the best ways is follow [maturin offical documentation](https://www.matur ```bash > python3 -m venv .venv > source .venv/bin/activate -> pip install -U pip maturin +> pip install -U pip maturin pre-commit pytest pytest-anyio pydantic pgpq ``` Then you need to build `PSQLPy` project.