Skip to content

Commit 09e5531

Browse files
author
AGAEV Denis E
committed
Added docs and small fixes
1 parent 402d23a commit 09e5531

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

docs/usage/types/extra_types.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ All extra types available from Python with mapping to PostgreSQL type and Rust t
1818
| PyJSONB | JSONB | serde::Value |
1919
| PyMacAddr6 | MacAddr | MacAddr6 |
2020
| PyMacAddr8 | MacAddr8 | MacAddr8 |
21+
| PyPoint | Point | Point |
22+
| PyBox | Rect | Box |
23+
| PyPath | LineString | Path |
24+
| PyLine | LineSegment | Line |
25+
| PyLineSegment | LineSegment | Lseg |
26+
| PyCircle | Circle | Circle |
27+
2128

2229
## BigInt & Integer & SmallInt & Float32 & Float64
2330
When integer is passed from Python to Rust, it's impossible to understand what type is required on the Database side.
@@ -177,3 +184,43 @@ async def main() -> None:
177184

178185
db_pool.close()
179186
```
187+
188+
## Geo Types
189+
Also in package exists support of PostgreSQL geo types(except Polygon for now).
190+
To use geo types you need specify them directly.
191+
192+
Let's assume we have table `geo_info` with all PostgreSQL geo types in the database:
193+
| database type | database column name |
194+
| :---: | :---: |
195+
| POINT | map_point |
196+
| BOX | point_district |
197+
| PATH | path_to_point |
198+
| LINE | points_line |
199+
| LSEG | lseg_between_points |
200+
| CIRCLE | point_radius_circle |
201+
202+
```python
203+
from typing import Final
204+
205+
from psqlpy import ConnectionPool, QueryResult
206+
from psqlpy.extra_types import PyPoint, PyBox, PyPath, PyLine, PyLineSegment, PyCircle
207+
208+
209+
async def main() -> None:
210+
# It uses default connection parameters
211+
db_pool: Final = ConnectionPool()
212+
213+
await db_pool.execute(
214+
"INSERT INTO geo_info VALUES ($1, $2, $3, $4, $5, $6)",
215+
[
216+
PyPoint([1.5, 2]),
217+
PyBox([(1.7, 2.8), (9, 9)]),
218+
PyPath([(3.5, 3), (9, 9), (8, 8)]),
219+
PyLine([1, -2, 3]),
220+
PyLineSegment([(5.6, 3.1), (4, 5)]),
221+
PyCircle([5, 1.8, 10]),
222+
],
223+
)
224+
225+
db_pool.close()
226+
```

docs/usage/types/supported_types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Here you can find all types supported by `PSQLPy`. If PSQLPy isn't `-`, you can
1818
| int | INTEGER | INTEGER |
1919
| int | - | INTEGER |
2020
| int | BIGINT | BIGINT |
21-
| float | - | FLOAT4 |
21+
| float | - | FLOAT8 |
2222
| float | Float32 | FLOAT4 |
2323
| float | Float64 | FLOAT8 |
2424
| datetime.date | - | DATE |

python/psqlpy/_internal/extra_types.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class PyPath:
202202
"""
203203

204204
class PyLine:
205-
"""Represent line field in PostgreSQL and Line in Rust."""
205+
"""Represent line field in PostgreSQL and LineSegment in Rust."""
206206

207207
def __init__(self: Self, value: PairsOfCoordinates) -> None:
208208
"""Create new instance of PyLine.
@@ -215,7 +215,7 @@ class PyLine:
215215
"""
216216

217217
class PyLineSegment:
218-
"""Represent lseg field in PostgreSQL and Line in Rust."""
218+
"""Represent lseg field in PostgreSQL and LineSegment in Rust."""
219219

220220
def __init__(self: Self, value: PairsOfCoordinates) -> None:
221221
"""Create new instance of PyLineSegment.
@@ -231,7 +231,7 @@ class PyLineSegment:
231231
"""
232232

233233
class PyCircle:
234-
"""Represent line field in PostgreSQL and Line in Rust."""
234+
"""Represent circle field in PostgreSQL and Circle in Rust."""
235235

236236
def __init__(
237237
self: Self,

0 commit comments

Comments
 (0)