Skip to content

Commit 97615ab

Browse files
author
AGAEV Denis E
committed
Add builders for rust geo types
1 parent fa4a4f0 commit 97615ab

File tree

5 files changed

+287
-149
lines changed

5 files changed

+287
-149
lines changed

python/psqlpy/_internal/__init__.pyi

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class QueryResult:
1616
custom_decoders: dict[str, Callable[[bytes], Any]] | None = None,
1717
) -> list[dict[Any, Any]]:
1818
"""Return result from database as a list of dicts."""
19-
2019
def as_class(
2120
self: Self,
2221
as_class: Callable[..., _CustomClass],
@@ -58,7 +57,6 @@ class SingleQueryResult:
5857

5958
def result(self: Self) -> dict[Any, Any]:
6059
"""Return result from database as a dict."""
61-
6260
def as_class(
6361
self: Self,
6462
as_class: Callable[..., _CustomClass],
@@ -193,13 +191,11 @@ class Cursor:
193191
194192
Execute DECLARE command for the cursor.
195193
"""
196-
197194
async def close(self: Self) -> None:
198195
"""Close the cursor.
199196
200197
Execute CLOSE command for the cursor.
201198
"""
202-
203199
async def fetch(
204200
self: Self,
205201
fetch_number: int | None = None,
@@ -214,7 +210,6 @@ class Cursor:
214210
### Returns:
215211
result as `QueryResult`.
216212
"""
217-
218213
async def fetch_next(
219214
self: Self,
220215
) -> QueryResult:
@@ -225,7 +220,6 @@ class Cursor:
225220
### Returns:
226221
result as `QueryResult`.
227222
"""
228-
229223
async def fetch_prior(
230224
self: Self,
231225
) -> QueryResult:
@@ -236,7 +230,6 @@ class Cursor:
236230
### Returns:
237231
result as `QueryResult`.
238232
"""
239-
240233
async def fetch_first(
241234
self: Self,
242235
) -> QueryResult:
@@ -247,7 +240,6 @@ class Cursor:
247240
### Returns:
248241
result as `QueryResult`.
249242
"""
250-
251243
async def fetch_last(
252244
self: Self,
253245
) -> QueryResult:
@@ -258,7 +250,6 @@ class Cursor:
258250
### Returns:
259251
result as `QueryResult`.
260252
"""
261-
262253
async def fetch_absolute(
263254
self: Self,
264255
absolute_number: int,
@@ -270,7 +261,6 @@ class Cursor:
270261
### Returns:
271262
result as `QueryResult`.
272263
"""
273-
274264
async def fetch_relative(
275265
self: Self,
276266
relative_number: int,
@@ -282,7 +272,6 @@ class Cursor:
282272
### Returns:
283273
result as `QueryResult`.
284274
"""
285-
286275
async def fetch_forward_all(
287276
self: Self,
288277
) -> QueryResult:
@@ -293,7 +282,6 @@ class Cursor:
293282
### Returns:
294283
result as `QueryResult`.
295284
"""
296-
297285
async def fetch_backward(
298286
self: Self,
299287
backward_count: int,
@@ -305,7 +293,6 @@ class Cursor:
305293
### Returns:
306294
result as `QueryResult`.
307295
"""
308-
309296
async def fetch_backward_all(
310297
self: Self,
311298
) -> QueryResult:
@@ -340,15 +327,13 @@ class Transaction:
340327
341328
`begin()` can be called only once per transaction.
342329
"""
343-
344330
async def commit(self: Self) -> None:
345331
"""Commit the transaction.
346332
347333
Execute `COMMIT`.
348334
349335
`commit()` can be called only once per transaction.
350336
"""
351-
352337
async def execute(
353338
self: Self,
354339
querystring: str,
@@ -387,7 +372,6 @@ class Transaction:
387372
await transaction.commit()
388373
```
389374
"""
390-
391375
async def execute_many(
392376
self: Self,
393377
querystring: str,
@@ -446,7 +430,6 @@ class Transaction:
446430
- `prepared`: should the querystring be prepared before the request.
447431
By default any querystring will be prepared.
448432
"""
449-
450433
async def fetch_row(
451434
self: Self,
452435
querystring: str,
@@ -487,7 +470,6 @@ class Transaction:
487470
await transaction.commit()
488471
```
489472
"""
490-
491473
async def fetch_val(
492474
self: Self,
493475
querystring: str,
@@ -529,7 +511,6 @@ class Transaction:
529511
)
530512
```
531513
"""
532-
533514
async def pipeline(
534515
self,
535516
queries: list[tuple[str, list[Any] | None]],
@@ -596,7 +577,6 @@ class Transaction:
596577
597578
```
598579
"""
599-
600580
async def create_savepoint(self: Self, savepoint_name: str) -> None:
601581
"""Create new savepoint.
602582
@@ -626,7 +606,6 @@ class Transaction:
626606
await transaction.rollback_savepoint("my_savepoint")
627607
```
628608
"""
629-
630609
async def rollback(self: Self) -> None:
631610
"""Rollback all queries in the transaction.
632611
@@ -648,7 +627,6 @@ class Transaction:
648627
await transaction.rollback()
649628
```
650629
"""
651-
652630
async def rollback_savepoint(self: Self, savepoint_name: str) -> None:
653631
"""ROLLBACK to the specified `savepoint_name`.
654632
@@ -675,7 +653,6 @@ class Transaction:
675653
await transaction.rollback_savepoint("my_savepoint")
676654
```
677655
"""
678-
679656
async def release_savepoint(self: Self, savepoint_name: str) -> None:
680657
"""Execute ROLLBACK TO SAVEPOINT.
681658
@@ -701,7 +678,6 @@ class Transaction:
701678
await transaction.release_savepoint
702679
```
703680
"""
704-
705681
def cursor(
706682
self: Self,
707683
querystring: str,
@@ -795,7 +771,6 @@ class Connection:
795771
dict_result: List[Dict[Any, Any]] = query_result.result()
796772
```
797773
"""
798-
799774
async def execute_many(
800775
self: Self,
801776
querystring: str,
@@ -849,7 +824,6 @@ class Connection:
849824
- `prepared`: should the querystring be prepared before the request.
850825
By default any querystring will be prepared.
851826
"""
852-
853827
async def fetch_row(
854828
self: Self,
855829
querystring: str,
@@ -887,7 +861,6 @@ class Connection:
887861
dict_result: Dict[Any, Any] = query_result.result()
888862
```
889863
"""
890-
891864
async def fetch_val(
892865
self: Self,
893866
querystring: str,
@@ -928,7 +901,6 @@ class Connection:
928901
)
929902
```
930903
"""
931-
932904
def transaction(
933905
self,
934906
isolation_level: IsolationLevel | None = None,
@@ -1044,7 +1016,6 @@ class ConnectionPool:
10441016
- `max_db_pool_size`: maximum size of the connection pool.
10451017
- `conn_recycling_method`: how a connection is recycled.
10461018
"""
1047-
10481019
async def execute(
10491020
self: Self,
10501021
querystring: str,
@@ -1080,7 +1051,6 @@ class ConnectionPool:
10801051
# it will be dropped on Rust side.
10811052
```
10821053
"""
1083-
10841054
async def fetch(
10851055
self: Self,
10861056
querystring: str,
@@ -1101,13 +1071,11 @@ class ConnectionPool:
11011071
- `prepared`: should the querystring be prepared before the request.
11021072
By default any querystring will be prepared.
11031073
"""
1104-
11051074
async def connection(self: Self) -> Connection:
11061075
"""Create new connection.
11071076
11081077
It acquires new connection from the database pool.
11091078
"""
1110-
11111079
def close(self: Self) -> None:
11121080
"""Close the connection pool."""
11131081

python/psqlpy/_internal/extra_types.pyi

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ class PyBox:
162162
"""Create new instance of PyBox.
163163
164164
You need to pass any of this structures:
165-
- sequence of two sequences,
165+
- sequence(List, Tuple or Set) of two sequences(List, Tuple or Set),
166166
each with pair of int/float numbers in every combination
167-
- sequence of two pairs of int/float in every combination
167+
- sequence(List, Tuple or Set) of two pairs of int/float in every combination
168168
169169
### Parameters:
170-
- `value`: any valid sequence with two pairs
170+
- `value`: any valid sequence(List, Tuple or Set) with two pairs
171171
of int/float numbers in every combination.
172172
"""
173173

@@ -184,8 +184,10 @@ class PyPath:
184184
"""Create new instance of PyPath.
185185
186186
You need to pass any of this structures:
187-
- sequence of sequences, each with pair of int/float numbers in every combination
188-
- sequence with pairs of int/float numbers in every combination
187+
- sequence(List, Tuple or Set) of sequences(List, Tuple or Set),
188+
each with pair of int/float numbers in every combination
189+
- sequence(List, Tuple or Set) with pairs
190+
of int/float numbers in every combination
189191
190192
### Parameters:
191193
- `value`: any valid structure with int/float numbers in every combination.
@@ -204,13 +206,13 @@ class PyLine:
204206
"""Create new instance of PyLine.
205207
206208
You need to pass any of this structures:
207-
- sequence of three int/float numbers
208-
- sequence of two sequences,
209+
- sequence(List, Tuple or Set) of two sequences(List, Tuple or Set),
209210
each with pair of int/float numbers in every combination
210-
- sequence with two pairs of int/float numbers in every combination
211+
- sequence(List, Tuple or Set) with two pairs
212+
of int/float numbers in every combination
211213
212214
### Parameters:
213-
- `value`: any valid structure with float numbers.
215+
- `value`: any valid structure with int/float numbers.
214216
"""
215217

216218
class PyLineSegment:
@@ -226,9 +228,10 @@ class PyLineSegment:
226228
"""Create new instance of PyLineSegment.
227229
228230
You need to pass any of this structures:
229-
- sequence of two sequences,
231+
- sequence(List, Tuple or Set) of two sequences(List, Tuple or Set),
230232
each with pair of int/float numbers in every combination
231-
- sequence with two pairs of int/float numbers in every combination
233+
- sequence(List, Tuple or Set) with two pairs
234+
of int/float numbers in every combination
232235
233236
### Parameters:
234237
- `value`: any valid structure with int/float numbers in every combination.
@@ -247,9 +250,34 @@ class PyPolygon:
247250
"""Create new instance of PyPolygon.
248251
249252
You need to pass any of this structures:
250-
- sequence of sequences, each with pair of int/float numbers in every combination
251-
- sequence with pairs of int/float numbers in every combination
253+
- sequence(List, Tuple or Set) of sequences(List, Tuple or Set),
254+
each with pair of int/float numbers in every combination
255+
- sequence(List, Tuple or Set) with pairs
256+
of int/float numbers in every combination
252257
253258
### Parameters:
254259
- `value`: any valid structure with int/float numbers in every combination.
255260
"""
261+
262+
class PyCircle:
263+
"""Represent line field in PostgreSQL and Line in Rust."""
264+
265+
def __init__(
266+
self: Self,
267+
value: typing.Union[
268+
typing.Union[list[Coordinates], set[Coordinates], tuple[Coordinates]],
269+
Coordinates,
270+
],
271+
) -> None:
272+
"""Create new instance of PyLine.
273+
274+
You need to pass any of this structures:
275+
- sequence of three int/float numbers
276+
- sequence of two sequences,
277+
each with pair of int/float numbers in every combination
278+
- sequence(List, Tuple or Set) with two pairs
279+
of int/float numbers in every combination
280+
281+
### Parameters:
282+
- `value`: any valid structure with int/float numbers.
283+
"""

python/psqlpy/extra_types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
BigInt,
33
Integer,
44
PyBox,
5+
PyCircle,
56
PyCustomType,
67
PyJSON,
78
PyJSONB,
@@ -36,4 +37,5 @@
3637
"PyLine",
3738
"PyLineSegment",
3839
"PyPolygon",
40+
"PyCircle",
3941
]

0 commit comments

Comments
 (0)