diff --git a/Cargo.lock b/Cargo.lock index 6dade3e3..ce6f31cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -997,7 +997,7 @@ dependencies = [ [[package]] name = "psqlpy" -version = "0.8.6" +version = "0.8.7" dependencies = [ "byteorder", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 35568614..0cdc86fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "psqlpy" -version = "0.8.6" +version = "0.8.7" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/docs/benchmarks.md b/docs/benchmarks.md index 5748a092..b850e67d 100644 --- a/docs/benchmarks.md +++ b/docs/benchmarks.md @@ -13,15 +13,15 @@ There are two types of benchmarks: 1) With local database 2) With external database -In a real production system database doesn't usually locate on the same server where application runs, so if you application and database is located on the different servers, we recommend you to check `External Database`. +In a real production system database doesn't usually locate on the same server where application runs, so if you application and database are located on the different servers, we recommend you to check `External Database`. ::: important -For local benchmarks we use 5 connection in a connection pool and 10 processes make requests to the application, while for external database checks we use 40 connection and 100 processes make requests to the application. +For local benchmarks we use 5 connections in a connection pool and 10 processes make requests to the application, while for external database checks we use 40 connections and 100 processes make requests to the application. The main reason is external database is located on a very powerful server and can serve more requests. ::: ## Key findings -If you application and database is located on the same server, there is no significant difference between `AsyncPG`, `PsycoPG` and `PSQLPy` but still you will have performance improve by approximately 10%. +If your application and database are located on the same server, there is no significant difference between `AsyncPG`, `PsycoPG` and `PSQLPy` but still you will have performance improve by approximately 10%. However, if you have application and database located on different machines, you can get significant (up to 3 times) boost in performance. ## Local Database @@ -671,4 +671,4 @@ However, if you have application and database located on different machines, you } } ``` -::: \ No newline at end of file +::: diff --git a/docs/usage/types/extra_types.md b/docs/usage/types/extra_types.md index 05c69680..52431843 100644 --- a/docs/usage/types/extra_types.md +++ b/docs/usage/types/extra_types.md @@ -12,18 +12,18 @@ All extra types available from Python with mapping to PostgreSQL type and Rust t | SmallInt | SmallInt | i16 | | Float32 | FLOAT4 | f32 | | Float64 | FLOAT8 | f64 | -| PyVarChar | VarChar | String | -| PyText | Text | String | -| PyJSON | JSON | serde::Value | -| PyJSONB | JSONB | serde::Value | -| PyMacAddr6 | MacAddr | MacAddr6 | -| PyMacAddr8 | MacAddr8 | MacAddr8 | -| PyPoint | Point | Point | -| PyBox | Rect | Box | -| PyPath | LineString | Path | -| PyLine | LineSegment | Line | -| PyLineSegment | LineSegment | Lseg | -| PyCircle | Circle | Circle | +| VarChar | VarChar | String | +| Text | Text | String | +| JSON | JSON | serde::Value | +| JSONB | JSONB | serde::Value | +| MacAddr6 | MacAddr | MacAddr6 | +| MacAddr8 | MacAddr8 | MacAddr8 | +| Point | Point | Point | +| Box | Rect | Box | +| Path | LineString | Path | +| Line | LineSegment | Line | +| LineSegment | LineSegment | Lseg | +| Circle | Circle | Circle | | PgVector | Vector | Vector | ::: important @@ -208,7 +208,7 @@ Let's assume we have table `geo_info` with all PostgreSQL geo types in the datab from typing import Final from psqlpy import ConnectionPool, QueryResult -from psqlpy.extra_types import PyPoint, PyBox, PyPath, PyLine, PyLineSegment, PyCircle +from psqlpy.extra_types import Point, Box, Path, Line, LineSegment, Circle async def main() -> None: @@ -218,12 +218,12 @@ async def main() -> None: await db_pool.execute( "INSERT INTO geo_info VALUES ($1, $2, $3, $4, $5, $6)", [ - PyPoint([1.5, 2]), - PyBox([(1.7, 2.8), (9, 9)]), - PyPath([(3.5, 3), (9, 9), (8, 8)]), - PyLine([1, -2, 3]), - PyLineSegment([(5.6, 3.1), (4, 5)]), - PyCircle([5, 1.8, 10]), + 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 37bd72bf..70ecb803 100644 --- a/docs/usage/types/supported_types.md +++ b/docs/usage/types/supported_types.md @@ -11,8 +11,8 @@ Here you can find all types supported by `PSQLPy`. If PSQLPy isn't `-`, you can | bool | - | BOOL | | bytes | - | BYTEA | | str | - | VARCHAR | -| str | PyVarChar | VARCHAR | -| str | PyText | TEXT | +| str | VarChar | VARCHAR | +| str | Text | TEXT | | str | - | XML | | int | SmallInt | SMALLINT | | int | INTEGER | INTEGER | @@ -28,20 +28,20 @@ Here you can find all types supported by `PSQLPy`. If PSQLPy isn't `-`, you can | datetime.timedelta | - | INTERVAL | | UUID | - | UUID | | dict | - | JSONB | -| dict | PyJSONB | JSONB | -| dict | PyJSON | JSON | -| Mac Address 6 | PyMacAddr6 | MacAddr | -| Mac Address 8 | PyMacAddr8 | MacAddr | +| dict | JSONB | JSONB | +| dict | JSON | JSON | +| Mac Address 6 | MacAddr6 | MacAddr | +| Mac Address 8 | MacAddr8 | MacAddr | | IPv4Address | - | INET | | IPv6Address | - | INET | | decimal.Decimal | - | NUMERIC | | int/str | Money | MONEY | -| Point | PyPoint | POINT | -| Box | PyBox | BOX | -| Path | PyPath | PATH | -| Line | PyLine | LINE | -| Line Segment | PyLineSegment | LSEG | -| Circle | PyCircle | CIRCLE | +| Point | Point | POINT | +| Box | Box | BOX | +| Path | Path | PATH | +| Line | Line | LINE | +| Line Segment | LineSegment | LSEG | +| Circle | Circle | CIRCLE | | PgVector | PgVector | Vector | ::: important diff --git a/python/psqlpy/_internal/extra_types.pyi b/python/psqlpy/_internal/extra_types.pyi index 8b85f2c7..93037639 100644 --- a/python/psqlpy/_internal/extra_types.pyi +++ b/python/psqlpy/_internal/extra_types.pyi @@ -66,7 +66,7 @@ class Float64: - `inner_value`: float object. """ -class PyVarChar: +class VarChar: """Represent VarChar in PostgreSQL and String in Rust.""" def __init__(self: Self, inner_value: str) -> None: @@ -78,7 +78,7 @@ class PyVarChar: - `inner_value`: str object. """ -class PyText: +class Text: """Represent TEXT in PostgreSQL and String ins Rust.""" def __init__(self: Self, inner_value: str) -> None: @@ -90,7 +90,7 @@ class PyText: - `inner_value`: str object. """ -class PyJSONB: +class JSONB: """Represent JSONB field in PostgreSQL and Value in Rust.""" def __init__( @@ -105,7 +105,7 @@ class PyJSONB: - `value`: value for the JSONB field. """ -class PyJSON: +class JSON: """Represent JSON field in PostgreSQL and Value in Rust.""" def __init__( @@ -120,7 +120,7 @@ class PyJSON: - `value`: value for the JSONB field. """ -class PyMacAddr6: +class MacAddr6: """Represents MACADDR in PostgreSQL.""" def __init__(self, value: str) -> None: @@ -130,7 +130,7 @@ class PyMacAddr6: - `value`: value for MACADDR field. """ -class PyMacAddr8: +class MacAddr8: """Represents MACADDR8 in PostgreSQL.""" def __init__(self, value: str) -> None: @@ -140,7 +140,7 @@ class PyMacAddr8: - `value`: value for MACADDR8 field. """ -class PyCustomType: +class CustomType: def __init__(self, value: bytes) -> None: ... Coordinates: TypeAlias = list[int | float] | set[int | float] | tuple[int | float, int | float] @@ -148,11 +148,11 @@ PairsOfCoordinates: TypeAlias = ( list[Coordinates | int | float] | set[Coordinates | int | float] | tuple[Coordinates | int | float, ...] ) -class PyPoint: +class Point: """Represent point field in PostgreSQL and Point in Rust.""" def __init__(self: Self, value: Coordinates) -> None: - """Create new instance of PyPoint. + """Create new instance of Point. It accepts any pair(List, Tuple or Set) of int/float numbers in every combination. @@ -161,11 +161,11 @@ class PyPoint: - `value`: pair of int/float numbers in every combination. """ -class PyBox: +class Box: """Represent box field in PostgreSQL and Rect in Rust.""" def __init__(self: Self, value: PairsOfCoordinates) -> None: - """Create new instance of PyBox. + """Create new instance of Box. You need to pass any of this structures: - sequence(List, Tuple or Set) of two sequences(List, Tuple or Set), @@ -177,11 +177,11 @@ class PyBox: of int/float numbers in every combination. """ -class PyPath: +class Path: """Represent path field in PostgreSQL and LineString in Rust.""" def __init__(self: Self, value: PairsOfCoordinates) -> None: - """Create new instance of PyPath. + """Create new instance of Path. You need to pass any of this structures: - sequence(List, Tuple or Set) of sequences(List, Tuple or Set), @@ -193,11 +193,11 @@ class PyPath: - `value`: any valid structure with int/float numbers in every combination. """ -class PyLine: +class Line: """Represent line field in PostgreSQL and LineSegment in Rust.""" def __init__(self: Self, value: PairsOfCoordinates) -> None: - """Create new instance of PyLine. + """Create new instance of Line. You need to pass any of this structures: - sequence of three int/float numbers(a, b, c) @@ -206,11 +206,11 @@ class PyLine: - `value`: any valid structure with int/float numbers. """ -class PyLineSegment: +class LineSegment: """Represent lseg field in PostgreSQL and LineSegment in Rust.""" def __init__(self: Self, value: PairsOfCoordinates) -> None: - """Create new instance of PyLineSegment. + """Create new instance of LineSegment. You need to pass any of this structures: - sequence(List, Tuple or Set) of two sequences(List, Tuple or Set), @@ -222,14 +222,14 @@ class PyLineSegment: - `value`: any valid structure with int/float numbers in every combination. """ -class PyCircle: +class Circle: """Represent circle field in PostgreSQL and Circle in Rust.""" def __init__( self: Self, value: list[int | float] | set[int | float] | tuple[int | float, int | float, int | float], ) -> None: - """Create new instance of PyCircle. + """Create new instance of Circle. You need to pass any of this structures: - sequence of three int/float numbers(x, y, r) @@ -390,9 +390,9 @@ class JSONBArray: self: Self, inner: typing.Sequence[ dict[str, typing.Any] - | PyJSONB + | JSONB | typing.Sequence[dict[str, typing.Any]] - | typing.Sequence[PyJSONB] + | typing.Sequence[JSONB] | typing.Sequence[typing.Any] ], ) -> None: @@ -409,9 +409,9 @@ class JSONArray: self: Self, inner: typing.Sequence[ dict[str, typing.Any] - | PyJSON + | JSON | typing.Sequence[dict[str, typing.Any]] - | typing.Sequence[PyJSON] + | typing.Sequence[JSON] | typing.Sequence[typing.Any] ], ) -> None: @@ -478,7 +478,7 @@ class MacAddr6Array: def __init__( self: Self, - inner: typing.Sequence[PyMacAddr6 | typing.Sequence[PyMacAddr6] | typing.Any,], + inner: typing.Sequence[MacAddr6 | typing.Sequence[MacAddr6] | typing.Any,], ) -> None: """Create new instance of MacAddr6Array. @@ -491,7 +491,7 @@ class MacAddr8Array: def __init__( self: Self, - inner: typing.Sequence[PyMacAddr8 | typing.Sequence[PyMacAddr8] | typing.Any,], + inner: typing.Sequence[MacAddr8 | typing.Sequence[MacAddr8] | typing.Any,], ) -> None: """Create new instance of MacAddr8Array. @@ -517,7 +517,7 @@ class PointArray: def __init__( self: Self, - inner: typing.Sequence[PyPoint | typing.Sequence[PyPoint] | typing.Any,], + inner: typing.Sequence[Point | typing.Sequence[Point] | typing.Any,], ) -> None: """Create new instance of PointArray. @@ -530,12 +530,12 @@ class BoxArray: def __init__( self: Self, - inner: typing.Sequence[PyBox | typing.Sequence[PyBox] | typing.Any,], + inner: typing.Sequence[Box | typing.Sequence[Box] | typing.Any,], ) -> None: """Create new instance of BoxArray. ### Parameters: - - `inner`: inner value, sequence of PyBox values. + - `inner`: inner value, sequence of Box values. """ class PathArray: @@ -543,7 +543,7 @@ class PathArray: def __init__( self: Self, - inner: typing.Sequence[PyPath | typing.Sequence[PyPath] | typing.Any,], + inner: typing.Sequence[Path | typing.Sequence[Path] | typing.Any,], ) -> None: """Create new instance of PathArray. @@ -556,7 +556,7 @@ class LineArray: def __init__( self: Self, - inner: typing.Sequence[PyLine | typing.Sequence[PyLine] | typing.Any,], + inner: typing.Sequence[Line | typing.Sequence[Line] | typing.Any,], ) -> None: """Create new instance of LineArray. @@ -569,7 +569,7 @@ class LsegArray: def __init__( self: Self, - inner: typing.Sequence[PyLineSegment | typing.Sequence[PyLineSegment] | typing.Any,], + inner: typing.Sequence[LineSegment | typing.Sequence[LineSegment] | typing.Any,], ) -> None: """Create new instance of LsegArray. @@ -582,7 +582,7 @@ class CircleArray: def __init__( self: Self, - inner: typing.Sequence[PyCircle | typing.Sequence[PyCircle] | typing.Any,], + inner: typing.Sequence[Circle | typing.Sequence[Circle] | typing.Any,], ) -> None: """Create new instance of CircleArray. diff --git a/python/psqlpy/extra_types.py b/python/psqlpy/extra_types.py index 52299b20..dc3df5e3 100644 --- a/python/psqlpy/extra_types.py +++ b/python/psqlpy/extra_types.py @@ -1,8 +1,13 @@ from ._internal.extra_types import ( + JSON, + JSONB, BigInt, BoolArray, + Box, BoxArray, + Circle, CircleArray, + CustomType, DateArray, DateTimeArray, DateTimeTZArray, @@ -18,42 +23,42 @@ IpAddressArray, JSONArray, JSONBArray, + Line, LineArray, + LineSegment, LsegArray, + MacAddr6, MacAddr6Array, + MacAddr8, MacAddr8Array, Money, MoneyArray, NumericArray, + Path, PathArray, PgVector, + Point, PointArray, - PyBox, - PyCircle, - PyCustomType, - PyJSON, - PyJSONB, - PyLine, - PyLineSegment, - PyMacAddr6, - PyMacAddr8, - PyPath, - PyPoint, - PyText, - PyVarChar, SmallInt, + Text, TextArray, TimeArray, UUIDArray, + VarChar, VarCharArray, ) __all__ = [ + "JSON", + "JSONB", "BigInt", "BoolArray", "BoolArray", + "Box", "BoxArray", + "Circle", "CircleArray", + "CustomType", "DateArray", "DateTimeArray", "DateTimeTZArray", @@ -71,33 +76,28 @@ "JSONArray", "JSONBArray", "JSONBArray", + "Line", "LineArray", + "LineSegment", "LsegArray", + "MacAddr6", "MacAddr6Array", + "MacAddr8", "MacAddr8Array", "Money", "MoneyArray", "NumericArray", + "Path", "PathArray", "PgVector", + "Point", "PointArray", - "PyBox", - "PyCircle", - "PyCustomType", - "PyJSON", - "PyJSONB", - "PyLine", - "PyLineSegment", - "PyMacAddr6", - "PyMacAddr8", - "PyPath", - "PyPoint", - "PyText", - "PyVarChar", "SmallInt", + "Text", "TextArray", "TimeArray", "UUIDArray", "UUIDArray", + "VarChar", "VarCharArray", ] diff --git a/python/tests/test_value_converter.py b/python/tests/test_value_converter.py index cb53bad7..414b051f 100644 --- a/python/tests/test_value_converter.py +++ b/python/tests/test_value_converter.py @@ -10,10 +10,15 @@ from psqlpy import ConnectionPool from psqlpy.exceptions import PyToRustValueMappingError from psqlpy.extra_types import ( + JSON, + JSONB, BigInt, BoolArray, + Box, BoxArray, + Circle, CircleArray, + CustomType, DateArray, DateTimeArray, DateTimeTZArray, @@ -28,26 +33,21 @@ IpAddressArray, JSONArray, JSONBArray, + Line, LineArray, + LineSegment, LsegArray, + MacAddr6, + MacAddr8, Money, MoneyArray, NumericArray, + Path, PathArray, + Point, PointArray, - PyBox, - PyCircle, - PyCustomType, - PyJSON, - PyJSONB, - PyLine, - PyLineSegment, - PyMacAddr6, - PyMacAddr8, - PyPath, - PyPoint, - PyText, SmallInt, + Text, TextArray, TimeArray, UUIDArray, @@ -166,7 +166,7 @@ async def test_as_class( ), ( "JSONB", - PyJSONB([{"array": "json"}, {"one more": "test"}]), + JSONB([{"array": "json"}, {"one more": "test"}]), [{"array": "json"}, {"one more": "test"}], ), ( @@ -182,47 +182,47 @@ async def test_as_class( ), ( "JSON", - PyJSON([{"array": "json"}, {"one more": "test"}]), + JSON([{"array": "json"}, {"one more": "test"}]), [{"array": "json"}, {"one more": "test"}], ), ( "MACADDR", - PyMacAddr6("08:00:2b:01:02:03"), + MacAddr6("08:00:2b:01:02:03"), "08:00:2B:01:02:03", ), ( "MACADDR8", - PyMacAddr8("08:00:2b:01:02:03:04:05"), + MacAddr8("08:00:2b:01:02:03:04:05"), "08:00:2B:01:02:03:04:05", ), - ("POINT", PyPoint([1.5, 2]), (1.5, 2.0)), - ("POINT", PyPoint({1.2, 2.3}), (1.2, 2.3)), - ("POINT", PyPoint((1.7, 2.8)), (1.7, 2.8)), - ("BOX", PyBox([3.5, 3, 9, 9]), ((9.0, 9.0), (3.5, 3.0))), - ("BOX", PyBox({(1, 2), (9, 9)}), ((9.0, 9.0), (1.0, 2.0))), - ("BOX", PyBox(((1.7, 2.8), (9, 9))), ((9.0, 9.0), (1.7, 2.8))), + ("POINT", Point([1.5, 2]), (1.5, 2.0)), + ("POINT", Point({1.2, 2.3}), (1.2, 2.3)), + ("POINT", Point((1.7, 2.8)), (1.7, 2.8)), + ("BOX", Box([3.5, 3, 9, 9]), ((9.0, 9.0), (3.5, 3.0))), + ("BOX", Box({(1, 2), (9, 9)}), ((9.0, 9.0), (1.0, 2.0))), + ("BOX", Box(((1.7, 2.8), (9, 9))), ((9.0, 9.0), (1.7, 2.8))), ( "PATH", - PyPath([(3.5, 3), (9, 9), (8, 8)]), + Path([(3.5, 3), (9, 9), (8, 8)]), [(3.5, 3.0), (9.0, 9.0), (8.0, 8.0)], ), ( "PATH", - PyPath(((1.7, 2.8), (3.3, 2.5), (9, 9), (1.7, 2.8))), + Path(((1.7, 2.8), (3.3, 2.5), (9, 9), (1.7, 2.8))), ((1.7, 2.8), (3.3, 2.5), (9.0, 9.0), (1.7, 2.8)), ), - ("LINE", PyLine([-2, 1, 2]), (-2.0, 1.0, 2.0)), - ("LINE", PyLine([1, -2, 3]), (1.0, -2.0, 3.0)), - ("LSEG", PyLineSegment({(1, 2), (9, 9)}), [(1.0, 2.0), (9.0, 9.0)]), - ("LSEG", PyLineSegment(((1.7, 2.8), (9, 9))), [(1.7, 2.8), (9.0, 9.0)]), + ("LINE", Line([-2, 1, 2]), (-2.0, 1.0, 2.0)), + ("LINE", Line([1, -2, 3]), (1.0, -2.0, 3.0)), + ("LSEG", LineSegment({(1, 2), (9, 9)}), [(1.0, 2.0), (9.0, 9.0)]), + ("LSEG", LineSegment(((1.7, 2.8), (9, 9))), [(1.7, 2.8), (9.0, 9.0)]), ( "CIRCLE", - PyCircle((1.7, 2.8, 3)), + Circle((1.7, 2.8, 3)), ((1.7, 2.8), 3.0), ), ( "CIRCLE", - PyCircle([1, 2.8, 3]), + Circle([1, 2.8, 3]), ((1.0, 2.8), 3.0), ), ( @@ -237,7 +237,7 @@ async def test_as_class( ), ( "TEXT ARRAY", - [PyText("Some String"), PyText("Some String")], + [Text("Some String"), Text("Some String")], ["Some String", "Some String"], ), ("BOOL ARRAY", [True, False], [True, False]), @@ -400,8 +400,8 @@ async def test_as_class( ( "JSONB ARRAY", [ - PyJSONB([{"array": "json"}, {"one more": "test"}]), - PyJSONB([{"array": "json"}, {"one more": "test"}]), + JSONB([{"array": "json"}, {"one more": "test"}]), + JSONB([{"array": "json"}, {"one more": "test"}]), ], [ [{"array": "json"}, {"one more": "test"}], @@ -411,8 +411,8 @@ async def test_as_class( ( "JSONB ARRAY", [ - PyJSONB([[{"array": "json"}], [{"one more": "test"}]]), - PyJSONB([[{"array": "json"}], [{"one more": "test"}]]), + JSONB([[{"array": "json"}], [{"one more": "test"}]]), + JSONB([[{"array": "json"}], [{"one more": "test"}]]), ], [ [[{"array": "json"}], [{"one more": "test"}]], @@ -422,13 +422,13 @@ async def test_as_class( ( "JSON ARRAY", [ - PyJSON( + JSON( { "test": ["something", 123, "here"], "nested": ["JSON"], }, ), - PyJSON( + JSON( { "test": ["something", 123, "here"], "nested": ["JSON"], @@ -450,7 +450,7 @@ async def test_as_class( "JSON ARRAY", [ [ - PyJSON( + JSON( { "test": ["something", 123, "here"], "nested": ["JSON"], @@ -458,7 +458,7 @@ async def test_as_class( ), ], [ - PyJSON( + JSON( { "test": ["something", 123, "here"], "nested": ["JSON"], @@ -484,8 +484,8 @@ async def test_as_class( ( "JSON ARRAY", [ - PyJSON([{"array": "json"}, {"one more": "test"}]), - PyJSON([{"array": "json"}, {"one more": "test"}]), + JSON([{"array": "json"}, {"one more": "test"}]), + JSON([{"array": "json"}, {"one more": "test"}]), ], [ [{"array": "json"}, {"one more": "test"}], @@ -495,8 +495,8 @@ async def test_as_class( ( "JSON ARRAY", [ - PyJSON([[{"array": "json"}], [{"one more": "test"}]]), - PyJSON([[{"array": "json"}], [{"one more": "test"}]]), + JSON([[{"array": "json"}], [{"one more": "test"}]]), + JSON([[{"array": "json"}], [{"one more": "test"}]]), ], [ [[{"array": "json"}], [{"one more": "test"}]], @@ -506,8 +506,8 @@ async def test_as_class( ( "POINT ARRAY", [ - PyPoint([1.5, 2]), - PyPoint([2, 3]), + Point([1.5, 2]), + Point([2, 3]), ], [ (1.5, 2.0), @@ -517,8 +517,8 @@ async def test_as_class( ( "POINT ARRAY", [ - [PyPoint([1.5, 2])], - [PyPoint([2, 3])], + [Point([1.5, 2])], + [Point([2, 3])], ], [ [(1.5, 2.0)], @@ -528,8 +528,8 @@ async def test_as_class( ( "BOX ARRAY", [ - PyBox([3.5, 3, 9, 9]), - PyBox([8.5, 8, 9, 9]), + Box([3.5, 3, 9, 9]), + Box([8.5, 8, 9, 9]), ], [ ((9.0, 9.0), (3.5, 3.0)), @@ -539,8 +539,8 @@ async def test_as_class( ( "BOX ARRAY", [ - [PyBox([3.5, 3, 9, 9])], - [PyBox([8.5, 8, 9, 9])], + [Box([3.5, 3, 9, 9])], + [Box([8.5, 8, 9, 9])], ], [ [((9.0, 9.0), (3.5, 3.0))], @@ -550,8 +550,8 @@ async def test_as_class( ( "PATH ARRAY", [ - PyPath([(3.5, 3), (9, 9), (8, 8)]), - PyPath([(3.5, 3), (6, 6), (3.5, 3)]), + Path([(3.5, 3), (9, 9), (8, 8)]), + Path([(3.5, 3), (6, 6), (3.5, 3)]), ], [ [(3.5, 3.0), (9.0, 9.0), (8.0, 8.0)], @@ -561,8 +561,8 @@ async def test_as_class( ( "PATH ARRAY", [ - [PyPath([(3.5, 3), (9, 9), (8, 8)])], - [PyPath([(3.5, 3), (6, 6), (3.5, 3)])], + [Path([(3.5, 3), (9, 9), (8, 8)])], + [Path([(3.5, 3), (6, 6), (3.5, 3)])], ], [ [[(3.5, 3.0), (9.0, 9.0), (8.0, 8.0)]], @@ -572,8 +572,8 @@ async def test_as_class( ( "LINE ARRAY", [ - PyLine([-2, 1, 2]), - PyLine([1, -2, 3]), + Line([-2, 1, 2]), + Line([1, -2, 3]), ], [ (-2.0, 1.0, 2.0), @@ -583,8 +583,8 @@ async def test_as_class( ( "LINE ARRAY", [ - [PyLine([-2, 1, 2])], - [PyLine([1, -2, 3])], + [Line([-2, 1, 2])], + [Line([1, -2, 3])], ], [ [(-2.0, 1.0, 2.0)], @@ -594,8 +594,8 @@ async def test_as_class( ( "LSEG ARRAY", [ - PyLineSegment({(1, 2), (9, 9)}), - PyLineSegment([(5.6, 3.1), (4, 5)]), + LineSegment({(1, 2), (9, 9)}), + LineSegment([(5.6, 3.1), (4, 5)]), ], [ [(1.0, 2.0), (9.0, 9.0)], @@ -605,8 +605,8 @@ async def test_as_class( ( "LSEG ARRAY", [ - [PyLineSegment({(1, 2), (9, 9)})], - [PyLineSegment([(5.6, 3.1), (4, 5)])], + [LineSegment({(1, 2), (9, 9)})], + [LineSegment([(5.6, 3.1), (4, 5)])], ], [ [[(1.0, 2.0), (9.0, 9.0)]], @@ -616,8 +616,8 @@ async def test_as_class( ( "CIRCLE ARRAY", [ - PyCircle([1.7, 2.8, 3]), - PyCircle([5, 1.8, 10]), + Circle([1.7, 2.8, 3]), + Circle([5, 1.8, 10]), ], [ ((1.7, 2.8), 3.0), @@ -627,8 +627,8 @@ async def test_as_class( ( "CIRCLE ARRAY", [ - [PyCircle([1.7, 2.8, 3])], - [PyCircle([5, 1.8, 10])], + [Circle([1.7, 2.8, 3])], + [Circle([5, 1.8, 10])], ], [ [((1.7, 2.8), 3.0)], @@ -757,7 +757,7 @@ class TestEnum(Enum): parameters=[ b"Bytes", "Some String", - PyText("Some String"), + Text("Some String"), True, SmallInt(123), Integer(199), @@ -775,21 +775,21 @@ class TestEnum(Enum): "test": ["something", 123, "here"], "nested": ["JSON"], }, - PyJSON( + JSON( { "test": ["something", 123, "here"], "nested": ["JSON"], }, ), - PyPoint({1.2, 2.3}), - PyBox(((1.7, 2.8), (9, 9))), - PyPath(((1.7, 2.8), (3.3, 2.5), (9, 9), (1.7, 2.8))), - PyLine({-2, 1, 2}), - PyLineSegment(((1.7, 2.8), (9, 9))), - PyCircle([1.7, 2.8, 3]), + Point({1.2, 2.3}), + Box(((1.7, 2.8), (9, 9))), + Path(((1.7, 2.8), (3.3, 2.5), (9, 9), (1.7, 2.8))), + Line({-2, 1, 2}), + LineSegment(((1.7, 2.8), (9, 9))), + Circle([1.7, 2.8, 3]), ["Some String", "Some String"], [["Some String"], ["Some String"]], - [PyText("Some String"), PyText("Some String")], + [Text("Some String"), Text("Some String")], [True, False], [SmallInt(123), SmallInt(321)], [Integer(123), Integer(321)], @@ -812,13 +812,13 @@ class TestEnum(Enum): }, ], [ - PyJSON( + JSON( { "test": ["something", 123, "here"], "nested": ["JSON"], }, ), - PyJSON( + JSON( { "test": ["something", 123, "here"], "nested": ["JSON"], @@ -829,28 +829,28 @@ class TestEnum(Enum): "happy", TestEnum.OK, [ - PyPoint([1.5, 2]), - PyPoint([2, 3]), + Point([1.5, 2]), + Point([2, 3]), ], [ - PyBox([3.5, 3, 9, 9]), - PyBox([8.5, 8, 9, 9]), + Box([3.5, 3, 9, 9]), + Box([8.5, 8, 9, 9]), ], [ - PyPath([(3.5, 3), (9, 9), (8, 8)]), - PyPath([(3.5, 3), (6, 6), (3.5, 3)]), + Path([(3.5, 3), (9, 9), (8, 8)]), + Path([(3.5, 3), (6, 6), (3.5, 3)]), ], [ - PyLine([-2, 1, 2]), - PyLine([5.6, 4, 5]), + Line([-2, 1, 2]), + Line([5.6, 4, 5]), ], [ - PyLineSegment({(1, 2), (9, 9)}), - PyLineSegment([(5.6, 3.1), (4, 5)]), + LineSegment({(1, 2), (9, 9)}), + LineSegment([(5.6, 3.1), (4, 5)]), ], [ - PyCircle([1.7, 2.8, 3]), - PyCircle([5, 1.8, 10]), + Circle([1.7, 2.8, 3]), + Circle([5, 1.8, 10]), ], ], ) @@ -971,7 +971,7 @@ async def test_custom_type_as_parameter( await psql_pool.execute( querystring="INSERT INTO for_test VALUES ($1)", - parameters=[PyCustomType(b"Some Real Nickname")], + parameters=[CustomType(b"Some Real Nickname")], ) qs_result = await psql_pool.execute( @@ -1107,7 +1107,7 @@ async def test_empty_array( ), ( "TEXT ARRAY", - TextArray([PyText("Some String"), PyText("Some String")]), + TextArray([Text("Some String"), Text("Some String")]), ["Some String", "Some String"], ), ("BOOL ARRAY", BoolArray([]), []), @@ -1272,8 +1272,8 @@ async def test_empty_array( "JSONB ARRAY", JSONBArray( [ - PyJSONB([{"array": "json"}, {"one more": "test"}]), - PyJSONB([{"array": "json"}, {"one more": "test"}]), + JSONB([{"array": "json"}, {"one more": "test"}]), + JSONB([{"array": "json"}, {"one more": "test"}]), ], ), [ @@ -1285,8 +1285,8 @@ async def test_empty_array( "JSONB ARRAY", JSONBArray( [ - PyJSONB([[{"array": "json"}], [{"one more": "test"}]]), - PyJSONB([[{"array": "json"}], [{"one more": "test"}]]), + JSONB([[{"array": "json"}], [{"one more": "test"}]]), + JSONB([[{"array": "json"}], [{"one more": "test"}]]), ], ), [ @@ -1298,13 +1298,13 @@ async def test_empty_array( "JSON ARRAY", JSONArray( [ - PyJSON( + JSON( { "test": ["something", 123, "here"], "nested": ["JSON"], }, ), - PyJSON( + JSON( { "test": ["something", 123, "here"], "nested": ["JSON"], @@ -1328,7 +1328,7 @@ async def test_empty_array( JSONArray( [ [ - PyJSON( + JSON( { "test": ["something", 123, "here"], "nested": ["JSON"], @@ -1336,7 +1336,7 @@ async def test_empty_array( ), ], [ - PyJSON( + JSON( { "test": ["something", 123, "here"], "nested": ["JSON"], @@ -1364,8 +1364,8 @@ async def test_empty_array( "JSON ARRAY", JSONArray( [ - PyJSON([{"array": "json"}, {"one more": "test"}]), - PyJSON([{"array": "json"}, {"one more": "test"}]), + JSON([{"array": "json"}, {"one more": "test"}]), + JSON([{"array": "json"}, {"one more": "test"}]), ], ), [ @@ -1377,8 +1377,8 @@ async def test_empty_array( "JSON ARRAY", JSONArray( [ - PyJSON([[{"array": "json"}], [{"one more": "test"}]]), - PyJSON([[{"array": "json"}], [{"one more": "test"}]]), + JSON([[{"array": "json"}], [{"one more": "test"}]]), + JSON([[{"array": "json"}], [{"one more": "test"}]]), ], ), [ @@ -1390,8 +1390,8 @@ async def test_empty_array( "POINT ARRAY", PointArray( [ - PyPoint([1.5, 2]), - PyPoint([2, 3]), + Point([1.5, 2]), + Point([2, 3]), ], ), [ @@ -1403,8 +1403,8 @@ async def test_empty_array( "POINT ARRAY", PointArray( [ - [PyPoint([1.5, 2])], - [PyPoint([2, 3])], + [Point([1.5, 2])], + [Point([2, 3])], ], ), [ @@ -1416,8 +1416,8 @@ async def test_empty_array( "BOX ARRAY", BoxArray( [ - PyBox([3.5, 3, 9, 9]), - PyBox([8.5, 8, 9, 9]), + Box([3.5, 3, 9, 9]), + Box([8.5, 8, 9, 9]), ], ), [ @@ -1429,8 +1429,8 @@ async def test_empty_array( "BOX ARRAY", BoxArray( [ - [PyBox([3.5, 3, 9, 9])], - [PyBox([8.5, 8, 9, 9])], + [Box([3.5, 3, 9, 9])], + [Box([8.5, 8, 9, 9])], ], ), [ @@ -1442,8 +1442,8 @@ async def test_empty_array( "PATH ARRAY", PathArray( [ - PyPath([(3.5, 3), (9, 9), (8, 8)]), - PyPath([(3.5, 3), (6, 6), (3.5, 3)]), + Path([(3.5, 3), (9, 9), (8, 8)]), + Path([(3.5, 3), (6, 6), (3.5, 3)]), ], ), [ @@ -1455,8 +1455,8 @@ async def test_empty_array( "PATH ARRAY", PathArray( [ - [PyPath([(3.5, 3), (9, 9), (8, 8)])], - [PyPath([(3.5, 3), (6, 6), (3.5, 3)])], + [Path([(3.5, 3), (9, 9), (8, 8)])], + [Path([(3.5, 3), (6, 6), (3.5, 3)])], ], ), [ @@ -1468,8 +1468,8 @@ async def test_empty_array( "LINE ARRAY", LineArray( [ - PyLine([-2, 1, 2]), - PyLine([1, -2, 3]), + Line([-2, 1, 2]), + Line([1, -2, 3]), ], ), [ @@ -1481,8 +1481,8 @@ async def test_empty_array( "LINE ARRAY", LineArray( [ - [PyLine([-2, 1, 2])], - [PyLine([1, -2, 3])], + [Line([-2, 1, 2])], + [Line([1, -2, 3])], ], ), [ @@ -1494,8 +1494,8 @@ async def test_empty_array( "LSEG ARRAY", LsegArray( [ - PyLineSegment({(1, 2), (9, 9)}), - PyLineSegment([(5.6, 3.1), (4, 5)]), + LineSegment({(1, 2), (9, 9)}), + LineSegment([(5.6, 3.1), (4, 5)]), ], ), [ @@ -1507,8 +1507,8 @@ async def test_empty_array( "LSEG ARRAY", LsegArray( [ - [PyLineSegment({(1, 2), (9, 9)})], - [PyLineSegment([(5.6, 3.1), (4, 5)])], + [LineSegment({(1, 2), (9, 9)})], + [LineSegment([(5.6, 3.1), (4, 5)])], ], ), [ @@ -1520,8 +1520,8 @@ async def test_empty_array( "CIRCLE ARRAY", CircleArray( [ - PyCircle([1.7, 2.8, 3]), - PyCircle([5, 1.8, 10]), + Circle([1.7, 2.8, 3]), + Circle([5, 1.8, 10]), ], ), [ @@ -1533,8 +1533,8 @@ async def test_empty_array( "CIRCLE ARRAY", CircleArray( [ - [PyCircle([1.7, 2.8, 3])], - [PyCircle([5, 1.8, 10])], + [Circle([1.7, 2.8, 3])], + [Circle([5, 1.8, 10])], ], ), [ diff --git a/src/extra_types.rs b/src/extra_types.rs index 3df1835b..e0b33be8 100644 --- a/src/extra_types.rs +++ b/src/extra_types.rs @@ -1,7 +1,7 @@ use std::str::FromStr; -use geo_types::{Line as LineSegment, LineString, Point, Rect}; -use macaddr::{MacAddr6, MacAddr8}; +use geo_types::{Line as RustLineSegment, LineString, Point as RustPoint, Rect as RustRect}; +use macaddr::{MacAddr6 as RustMacAddr6, MacAddr8 as RustMacAddr8}; use pyo3::{ pyclass, pymethods, types::{PyModule, PyModuleMethods}, @@ -10,7 +10,7 @@ use pyo3::{ use serde_json::Value; use crate::{ - additional_types::{Circle, Line}, + additional_types::{Circle as RustCircle, Line as RustLine}, exceptions::rust_errors::{RustPSQLDriverError, RustPSQLDriverPyResult}, value_converter::{ build_flat_geo_coords, build_geo_coords, build_serde_value, @@ -77,11 +77,11 @@ build_python_type!(Float64, f64); #[pyclass] #[derive(Clone)] -pub struct PyText { +pub struct Text { inner: String, } -impl PyText { +impl Text { #[must_use] pub fn inner(&self) -> String { self.inner.clone() @@ -89,7 +89,7 @@ impl PyText { } #[pymethods] -impl PyText { +impl Text { /// Create new PyText from Python str. #[new] #[allow(clippy::missing_errors_doc)] @@ -101,11 +101,11 @@ impl PyText { #[pyclass] #[derive(Clone)] -pub struct PyVarChar { +pub struct VarChar { inner: String, } -impl PyVarChar { +impl VarChar { #[must_use] pub fn inner(&self) -> String { self.inner.clone() @@ -113,7 +113,7 @@ impl PyVarChar { } #[pymethods] -impl PyVarChar { +impl VarChar { /// Create new PyVarChar from Python str. #[new] #[allow(clippy::missing_errors_doc)] @@ -156,8 +156,8 @@ macro_rules! build_json_py_type { }; } -build_json_py_type!(PyJSONB, Value); -build_json_py_type!(PyJSON, Value); +build_json_py_type!(JSONB, Value); +build_json_py_type!(JSON, Value); macro_rules! build_macaddr_type { ($st_name:ident, $rust_type:ty) => { @@ -187,16 +187,16 @@ macro_rules! build_macaddr_type { }; } -build_macaddr_type!(PyMacAddr6, MacAddr6); -build_macaddr_type!(PyMacAddr8, MacAddr8); +build_macaddr_type!(MacAddr6, RustMacAddr6); +build_macaddr_type!(MacAddr8, RustMacAddr8); #[pyclass] #[derive(Clone, Debug)] -pub struct PyCustomType { +pub struct CustomType { inner: Vec, } -impl PyCustomType { +impl CustomType { #[must_use] pub fn inner(&self) -> Vec { self.inner.clone() @@ -204,10 +204,10 @@ impl PyCustomType { } #[pymethods] -impl PyCustomType { +impl CustomType { #[new] fn new_class(type_bytes: Vec) -> Self { - PyCustomType { inner: type_bytes } + CustomType { inner: type_bytes } } } @@ -228,41 +228,41 @@ macro_rules! build_geo_type { }; } -build_geo_type!(PyPoint, Point); -build_geo_type!(PyBox, Rect); -build_geo_type!(PyPath, LineString); -build_geo_type!(PyLine, Line); -build_geo_type!(PyLineSegment, LineSegment); -build_geo_type!(PyCircle, Circle); +build_geo_type!(Point, RustPoint); +build_geo_type!(Box, RustRect); +build_geo_type!(Path, LineString); +build_geo_type!(Line, RustLine); +build_geo_type!(LineSegment, RustLineSegment); +build_geo_type!(Circle, RustCircle); #[pymethods] -impl PyPoint { +impl Point { #[new] #[allow(clippy::missing_errors_doc)] pub fn new_point(value: Py) -> RustPSQLDriverPyResult { let point_coords = build_geo_coords(value, Some(1))?; Ok(Self { - inner: Point::from(point_coords[0]), + inner: RustPoint::from(point_coords[0]), }) } } #[pymethods] -impl PyBox { +impl Box { #[new] #[allow(clippy::missing_errors_doc)] pub fn new_box(value: Py) -> RustPSQLDriverPyResult { let box_coords = build_geo_coords(value, Some(2))?; Ok(Self { - inner: Rect::new(box_coords[0], box_coords[1]), + inner: RustRect::new(box_coords[0], box_coords[1]), }) } } #[pymethods] -impl PyPath { +impl Path { #[new] #[allow(clippy::missing_errors_doc)] pub fn new_path(value: Py) -> RustPSQLDriverPyResult { @@ -275,39 +275,39 @@ impl PyPath { } #[pymethods] -impl PyLine { +impl Line { #[new] #[allow(clippy::missing_errors_doc)] pub fn new_line(value: Py) -> RustPSQLDriverPyResult { let line_coords = build_flat_geo_coords(value, Some(3))?; Ok(Self { - inner: Line::new(line_coords[0], line_coords[1], line_coords[2]), + inner: RustLine::new(line_coords[0], line_coords[1], line_coords[2]), }) } } #[pymethods] -impl PyLineSegment { +impl LineSegment { #[new] #[allow(clippy::missing_errors_doc)] pub fn new_line_segment(value: Py) -> RustPSQLDriverPyResult { let line_segment_coords = build_geo_coords(value, Some(2))?; Ok(Self { - inner: LineSegment::new(line_segment_coords[0], line_segment_coords[1]), + inner: RustLineSegment::new(line_segment_coords[0], line_segment_coords[1]), }) } } #[pymethods] -impl PyCircle { +impl Circle { #[new] #[allow(clippy::missing_errors_doc)] pub fn new_circle(value: Py) -> RustPSQLDriverPyResult { let circle_coords = build_flat_geo_coords(value, Some(3))?; Ok(Self { - inner: Circle::new(circle_coords[0], circle_coords[1], circle_coords[2]), + inner: RustCircle::new(circle_coords[0], circle_coords[1], circle_coords[2]), }) } } @@ -391,19 +391,19 @@ pub fn extra_types_module(_py: Python<'_>, pymod: &Bound<'_, PyModule>) -> PyRes pymod.add_class::()?; pymod.add_class::()?; pymod.add_class::()?; - pymod.add_class::()?; - pymod.add_class::()?; - pymod.add_class::()?; - pymod.add_class::()?; - pymod.add_class::()?; - pymod.add_class::()?; - pymod.add_class::()?; - pymod.add_class::()?; - pymod.add_class::()?; - pymod.add_class::()?; - pymod.add_class::()?; - pymod.add_class::()?; - pymod.add_class::()?; + pymod.add_class::()?; + pymod.add_class::()?; + pymod.add_class::()?; + pymod.add_class::()?; + pymod.add_class::()?; + pymod.add_class::()?; + pymod.add_class::()?; + pymod.add_class::()?; + pymod.add_class::()?; + pymod.add_class::()?; + pymod.add_class::()?; + pymod.add_class::()?; + pymod.add_class::()?; pymod.add_class::()?; pymod.add_class::()?; pymod.add_class::()?; diff --git a/src/value_converter.rs b/src/value_converter.rs index 8f34bd93..fd9fca37 100644 --- a/src/value_converter.rs +++ b/src/value_converter.rs @@ -832,9 +832,9 @@ pub fn py_to_rust(parameter: &pyo3::Bound<'_, PyAny>) -> RustPSQLDriverPyResult< return Ok(PythonDTO::PyNone); } - if parameter.is_instance_of::() { + if parameter.is_instance_of::() { return Ok(PythonDTO::PyCustomType( - parameter.extract::()?.inner(), + parameter.extract::()?.inner(), )); } @@ -846,15 +846,15 @@ pub fn py_to_rust(parameter: &pyo3::Bound<'_, PyAny>) -> RustPSQLDriverPyResult< return Ok(PythonDTO::PyBytes(parameter.extract::>()?)); } - if parameter.is_instance_of::() { + if parameter.is_instance_of::() { return Ok(PythonDTO::PyText( - parameter.extract::()?.inner(), + parameter.extract::()?.inner(), )); } - if parameter.is_instance_of::() { + if parameter.is_instance_of::() { return Ok(PythonDTO::PyVarChar( - parameter.extract::()?.inner(), + parameter.extract::()?.inner(), )); } @@ -984,27 +984,27 @@ pub fn py_to_rust(parameter: &pyo3::Bound<'_, PyAny>) -> RustPSQLDriverPyResult< return Ok(PythonDTO::PyJsonb(Value::Object(serde_map))); } - if parameter.is_instance_of::() { + if parameter.is_instance_of::() { return Ok(PythonDTO::PyJsonb( - parameter.extract::()?.inner().clone(), + parameter.extract::()?.inner().clone(), )); } - if parameter.is_instance_of::() { + if parameter.is_instance_of::() { return Ok(PythonDTO::PyJson( - parameter.extract::()?.inner().clone(), + parameter.extract::()?.inner().clone(), )); } - if parameter.is_instance_of::() { + if parameter.is_instance_of::() { return Ok(PythonDTO::PyMacAddr6( - parameter.extract::()?.inner(), + parameter.extract::()?.inner(), )); } - if parameter.is_instance_of::() { + if parameter.is_instance_of::() { return Ok(PythonDTO::PyMacAddr8( - parameter.extract::()?.inner(), + parameter.extract::()?.inner(), )); } @@ -1022,45 +1022,41 @@ pub fn py_to_rust(parameter: &pyo3::Bound<'_, PyAny>) -> RustPSQLDriverPyResult< )?)); } - if parameter.is_instance_of::() { + if parameter.is_instance_of::() { return Ok(PythonDTO::PyPoint( - parameter - .extract::()? - .retrieve_value(), + parameter.extract::()?.retrieve_value(), )); } - if parameter.is_instance_of::() { + if parameter.is_instance_of::() { return Ok(PythonDTO::PyBox( - parameter.extract::()?.retrieve_value(), + parameter.extract::()?.retrieve_value(), )); } - if parameter.is_instance_of::() { + if parameter.is_instance_of::() { return Ok(PythonDTO::PyPath( - parameter.extract::()?.retrieve_value(), + parameter.extract::()?.retrieve_value(), )); } - if parameter.is_instance_of::() { + if parameter.is_instance_of::() { return Ok(PythonDTO::PyLine( - parameter.extract::()?.retrieve_value(), + parameter.extract::()?.retrieve_value(), )); } - if parameter.is_instance_of::() { + if parameter.is_instance_of::() { return Ok(PythonDTO::PyLineSegment( parameter - .extract::()? + .extract::()? .retrieve_value(), )); } - if parameter.is_instance_of::() { + if parameter.is_instance_of::() { return Ok(PythonDTO::PyCircle( - parameter - .extract::()? - .retrieve_value(), + parameter.extract::()?.retrieve_value(), )); }