psqlpy 0.11.10__cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,628 @@
1
+ import typing
2
+ from datetime import date, datetime, time, timedelta
3
+ from decimal import Decimal
4
+ from ipaddress import IPv4Address, IPv6Address
5
+ from typing import TypeAlias
6
+ from uuid import UUID
7
+
8
+ from typing_extensions import Self
9
+
10
+ class SmallInt:
11
+ """Represent SmallInt in PostgreSQL and `i16` in Rust."""
12
+
13
+ def __init__(self: Self, inner_value: int) -> None:
14
+ """Create new instance of class.
15
+
16
+ ### Parameters:
17
+ - `inner_value`: int object.
18
+ """
19
+
20
+ class Integer:
21
+ """Represent Integer in PostgreSQL and `i32` in Rust."""
22
+
23
+ def __init__(self: Self, inner_value: int) -> None:
24
+ """Create new instance of class.
25
+
26
+ ### Parameters:
27
+ - `inner_value`: int object.
28
+ """
29
+
30
+ class BigInt:
31
+ """Represent BigInt in PostgreSQL and `i64` in Rust."""
32
+
33
+ def __init__(self: Self, inner_value: int) -> None:
34
+ """Create new instance of class.
35
+
36
+ ### Parameters:
37
+ - `inner_value`: int object.
38
+ """
39
+
40
+ class Money:
41
+ """Represent `MONEY` in PostgreSQL and `i64` in Rust."""
42
+
43
+ def __init__(self: Self, inner_value: int) -> None:
44
+ """Create new instance of class.
45
+
46
+ ### Parameters:
47
+ - `inner_value`: int object.
48
+ """
49
+
50
+ class Float32:
51
+ """Represents `FLOAT4` in `PostgreSQL` and `f32` in Rust."""
52
+
53
+ def __init__(self: Self, inner_value: float) -> None:
54
+ """Create new instance of a class.
55
+
56
+ ### Parameters:
57
+ - `inner_value`: float object.
58
+ """
59
+
60
+ class Float64:
61
+ """Represents `FLOAT8` in `PostgreSQL` and `f64` in Rust."""
62
+
63
+ def __init__(self: Self, inner_value: float) -> None:
64
+ """Create new instance of a class.
65
+
66
+ ### Parameters:
67
+ - `inner_value`: float object.
68
+ """
69
+
70
+ class VarChar:
71
+ """Represent VarChar in PostgreSQL and String in Rust."""
72
+
73
+ def __init__(self: Self, inner_value: str) -> None:
74
+ """Create new instance of class.
75
+
76
+ You need to pass uuid as a str.
77
+
78
+ ### Parameters:
79
+ - `inner_value`: str object.
80
+ """
81
+
82
+ class Text:
83
+ """Represent TEXT in PostgreSQL and String ins Rust."""
84
+
85
+ def __init__(self: Self, inner_value: str) -> None:
86
+ """Create new instance of class.
87
+
88
+ You need to pass uuid as a str.
89
+
90
+ ### Parameters:
91
+ - `inner_value`: str object.
92
+ """
93
+
94
+ class JSONB:
95
+ """Represent JSONB field in PostgreSQL and Value in Rust."""
96
+
97
+ def __init__(
98
+ self: Self,
99
+ value: dict[str, typing.Any] | list[dict[str, typing.Any]] | list[typing.Any],
100
+ ) -> None:
101
+ """Create new instance of PyJSON.B.
102
+
103
+ It accepts structure that can be used in JSON/JSONB fields.
104
+
105
+ ### Parameters:
106
+ - `value`: value for the JSONB field.
107
+ """
108
+
109
+ class JSON:
110
+ """Represent JSON field in PostgreSQL and Value in Rust."""
111
+
112
+ def __init__(
113
+ self: Self,
114
+ value: dict[str, typing.Any] | list[dict[str, typing.Any]] | list[typing.Any],
115
+ ) -> None:
116
+ """Create new instance of PyJSON.
117
+
118
+ It accepts structure that can be used in JSON/JSONB fields.
119
+
120
+ ### Parameters:
121
+ - `value`: value for the JSONB field.
122
+ """
123
+
124
+ class MacAddr6:
125
+ """Represents MACADDR in PostgreSQL."""
126
+
127
+ def __init__(self, value: str) -> None:
128
+ """Construct new MacAddr.
129
+
130
+ ### Parameters:
131
+ - `value`: value for MACADDR field.
132
+ """
133
+
134
+ class MacAddr8:
135
+ """Represents MACADDR8 in PostgreSQL."""
136
+
137
+ def __init__(self, value: str) -> None:
138
+ """Construct new MacAddr8.
139
+
140
+ ### Parameters:
141
+ - `value`: value for MACADDR8 field.
142
+ """
143
+
144
+ class CustomType:
145
+ def __init__(self, value: bytes) -> None: ...
146
+
147
+ Coordinates: TypeAlias = (
148
+ list[int | float] | set[int | float] | tuple[int | float, int | float]
149
+ )
150
+ PairsOfCoordinates: TypeAlias = (
151
+ list[Coordinates | int | float]
152
+ | set[Coordinates | int | float]
153
+ | tuple[Coordinates | int | float, ...]
154
+ )
155
+
156
+ class Point:
157
+ """Represent point field in PostgreSQL and Point in Rust."""
158
+
159
+ def __init__(self: Self, value: Coordinates) -> None:
160
+ """Create new instance of Point.
161
+
162
+ It accepts any pair(List, Tuple or Set)
163
+ of int/float numbers in every combination.
164
+
165
+ ### Parameters:
166
+ - `value`: pair of int/float numbers in every combination.
167
+ """
168
+
169
+ class Box:
170
+ """Represent box field in PostgreSQL and Rect in Rust."""
171
+
172
+ def __init__(self: Self, value: PairsOfCoordinates) -> None:
173
+ """Create new instance of Box.
174
+
175
+ You need to pass any of this structures:
176
+ - sequence(List, Tuple or Set) of two sequences(List, Tuple or Set),
177
+ each with pair of int/float numbers in every combination
178
+ - sequence(List, Tuple or Set) of two pairs of int/float in every combination
179
+
180
+ ### Parameters:
181
+ - `value`: any valid sequence(List, Tuple or Set) with two pairs
182
+ of int/float numbers in every combination.
183
+ """
184
+
185
+ class Path:
186
+ """Represent path field in PostgreSQL and LineString in Rust."""
187
+
188
+ def __init__(self: Self, value: PairsOfCoordinates) -> None:
189
+ """Create new instance of Path.
190
+
191
+ You need to pass any of this structures:
192
+ - sequence(List, Tuple or Set) of sequences(List, Tuple or Set),
193
+ each with pair of int/float numbers in every combination
194
+ - sequence(List, Tuple or Set) with pairs
195
+ of int/float numbers in every combination
196
+
197
+ ### Parameters:
198
+ - `value`: any valid structure with int/float numbers in every combination.
199
+ """
200
+
201
+ class Line:
202
+ """Represent line field in PostgreSQL and LineSegment in Rust."""
203
+
204
+ def __init__(self: Self, value: PairsOfCoordinates) -> None:
205
+ """Create new instance of Line.
206
+
207
+ You need to pass any of this structures:
208
+ - sequence of three int/float numbers(a, b, c)
209
+
210
+ ### Parameters:
211
+ - `value`: any valid structure with int/float numbers.
212
+ """
213
+
214
+ class LineSegment:
215
+ """Represent lseg field in PostgreSQL and LineSegment in Rust."""
216
+
217
+ def __init__(self: Self, value: PairsOfCoordinates) -> None:
218
+ """Create new instance of LineSegment.
219
+
220
+ You need to pass any of this structures:
221
+ - sequence(List, Tuple or Set) of two sequences(List, Tuple or Set),
222
+ each with pair of int/float numbers in every combination
223
+ - sequence(List, Tuple or Set) with two pairs
224
+ of int/float numbers in every combination
225
+
226
+ ### Parameters:
227
+ - `value`: any valid structure with int/float numbers in every combination.
228
+ """
229
+
230
+ class Circle:
231
+ """Represent circle field in PostgreSQL and Circle in Rust."""
232
+
233
+ def __init__(
234
+ self: Self,
235
+ value: list[int | float]
236
+ | set[int | float]
237
+ | tuple[int | float, int | float, int | float],
238
+ ) -> None:
239
+ """Create new instance of Circle.
240
+
241
+ You need to pass any of this structures:
242
+ - sequence of three int/float numbers(x, y, r)
243
+
244
+ ### Parameters:
245
+ - `value`: any valid structure with int/float numbers.
246
+ """
247
+
248
+ class BoolArray:
249
+ """Represent BOOLEAN ARRAY in PostgreSQL."""
250
+
251
+ def __init__(
252
+ self: Self,
253
+ inner: typing.Sequence[bool | typing.Sequence[bool] | typing.Any,],
254
+ ) -> None:
255
+ """Create new instance of BoolArray.
256
+
257
+ ### Parameters:
258
+ - `inner`: inner value, sequence of UUID values.
259
+ """
260
+
261
+ class UUIDArray:
262
+ """Represent UUID ARRAY in PostgreSQL."""
263
+
264
+ def __init__(
265
+ self: Self,
266
+ inner: typing.Sequence[UUID | typing.Sequence[UUID] | typing.Any,],
267
+ ) -> None:
268
+ """Create new instance of UuidArray.
269
+
270
+ ### Parameters:
271
+ - `inner`: inner value, sequence of UUID values.
272
+ """
273
+
274
+ class VarCharArray:
275
+ """Represent VarChar ARRAY in PostgreSQL."""
276
+
277
+ def __init__(
278
+ self: Self,
279
+ inner: typing.Sequence[str | typing.Sequence[str] | typing.Any,],
280
+ ) -> None:
281
+ """Create new instance of VarCharArray.
282
+
283
+ ### Parameters:
284
+ - `inner`: inner value, sequence of str values.
285
+ """
286
+
287
+ class TextArray:
288
+ """Represent Text ARRAY in PostgreSQL."""
289
+
290
+ def __init__(
291
+ self: Self,
292
+ inner: typing.Sequence[str | typing.Sequence[str] | typing.Any,],
293
+ ) -> None:
294
+ """Create new instance of TextArray.
295
+
296
+ ### Parameters:
297
+ - `inner`: inner value, sequence of str values.
298
+ """
299
+
300
+ class Int16Array:
301
+ """Represent INT2 ARRAY in PostgreSQL."""
302
+
303
+ def __init__(
304
+ self: Self,
305
+ inner: typing.Sequence[int | typing.Sequence[int] | typing.Any,],
306
+ ) -> None:
307
+ """Create new instance of Int16Array.
308
+
309
+ ### Parameters:
310
+ - `inner`: inner value, sequence of int values.
311
+ """
312
+
313
+ class Int32Array:
314
+ """Represent INT4 ARRAY in PostgreSQL."""
315
+
316
+ def __init__(
317
+ self: Self,
318
+ inner: typing.Sequence[int | typing.Sequence[int] | typing.Any,],
319
+ ) -> None:
320
+ """Create new instance of Int32Array.
321
+
322
+ ### Parameters:
323
+ - `inner`: inner value, sequence of int values.
324
+ """
325
+
326
+ class Int64Array:
327
+ """Represent INT8 ARRAY in PostgreSQL."""
328
+
329
+ def __init__(
330
+ self: Self,
331
+ inner: typing.Sequence[int | typing.Sequence[int] | typing.Any,],
332
+ ) -> None:
333
+ """Create new instance of Int64Array.
334
+
335
+ ### Parameters:
336
+ - `inner`: inner value, sequence of int values.
337
+ """
338
+
339
+ class Float32Array:
340
+ """Represent FLOAT4 ARRAY in PostgreSQL."""
341
+
342
+ def __init__(
343
+ self: Self,
344
+ inner: typing.Sequence[float | typing.Sequence[float] | typing.Any,],
345
+ ) -> None:
346
+ """Create new instance of Float32Array.
347
+
348
+ ### Parameters:
349
+ - `inner`: inner value, sequence of float values.
350
+ """
351
+
352
+ class Float64Array:
353
+ """Represent FLOAT8 ARRAY in PostgreSQL."""
354
+
355
+ def __init__(
356
+ self: Self,
357
+ inner: typing.Sequence[float | typing.Sequence[float] | typing.Any,],
358
+ ) -> None:
359
+ """Create new instance of Float64Array.
360
+
361
+ ### Parameters:
362
+ - `inner`: inner value, sequence of float values.
363
+ """
364
+
365
+ class MoneyArray:
366
+ """Represent MONEY ARRAY in PostgreSQL."""
367
+
368
+ def __init__(
369
+ self: Self,
370
+ inner: typing.Sequence[int | typing.Sequence[int] | typing.Any,],
371
+ ) -> None:
372
+ """Create new instance of MoneyArray.
373
+
374
+ ### Parameters:
375
+ - `inner`: inner value, sequence of int values.
376
+ """
377
+
378
+ class IpAddressArray:
379
+ """Represent INET ARRAY in PostgreSQL."""
380
+
381
+ def __init__(
382
+ self: Self,
383
+ inner: typing.Sequence[
384
+ IPv4Address
385
+ | IPv6Address
386
+ | typing.Sequence[IPv4Address]
387
+ | typing.Sequence[IPv6Address]
388
+ | typing.Any,
389
+ ],
390
+ ) -> None:
391
+ """Create new instance of IpAddressArray.
392
+
393
+ ### Parameters:
394
+ - `inner`: inner value, sequence of IPv4Address/IPv6Address values.
395
+ """
396
+
397
+ class JSONBArray:
398
+ """Represent JSONB ARRAY in PostgreSQL."""
399
+
400
+ def __init__(
401
+ self: Self,
402
+ inner: typing.Sequence[
403
+ dict[str, typing.Any]
404
+ | JSONB
405
+ | typing.Sequence[dict[str, typing.Any]]
406
+ | typing.Sequence[JSONB]
407
+ | typing.Sequence[typing.Any]
408
+ ],
409
+ ) -> None:
410
+ """Create new instance of JSONBArray.
411
+
412
+ ### Parameters:
413
+ - `inner`: inner value, sequence of values.
414
+ """
415
+
416
+ class JSONArray:
417
+ """Represent JSON ARRAY in PostgreSQL."""
418
+
419
+ def __init__(
420
+ self: Self,
421
+ inner: typing.Sequence[
422
+ dict[str, typing.Any]
423
+ | JSON
424
+ | typing.Sequence[dict[str, typing.Any]]
425
+ | typing.Sequence[JSON]
426
+ | typing.Sequence[typing.Any]
427
+ ],
428
+ ) -> None:
429
+ """Create new instance of JSONArray.
430
+
431
+ ### Parameters:
432
+ - `inner`: inner value, sequence of values.
433
+ """
434
+
435
+ class DateArray:
436
+ """Represent DATE ARRAY in PostgreSQL."""
437
+
438
+ def __init__(
439
+ self: Self,
440
+ inner: typing.Sequence[date | typing.Sequence[date] | typing.Any,],
441
+ ) -> None:
442
+ """Create new instance of DateArray.
443
+
444
+ ### Parameters:
445
+ - `inner`: inner value, sequence of date values.
446
+ """
447
+
448
+ class TimeArray:
449
+ """Represent TIME ARRAY in PostgreSQL."""
450
+
451
+ def __init__(
452
+ self: Self,
453
+ inner: typing.Sequence[time | typing.Sequence[time] | typing.Any,],
454
+ ) -> None:
455
+ """Create new instance of DateArray.
456
+
457
+ ### Parameters:
458
+ - `inner`: inner value, sequence of time values.
459
+ """
460
+
461
+ class DateTimeArray:
462
+ """Represent TIMESTAMP ARRAY in PostgreSQL."""
463
+
464
+ def __init__(
465
+ self: Self,
466
+ inner: typing.Sequence[datetime | typing.Sequence[datetime] | typing.Any,],
467
+ ) -> None:
468
+ """Create new instance of DateArray.
469
+
470
+ ### Parameters:
471
+ - `inner`: inner value, sequence of datetime values.
472
+ """
473
+
474
+ class DateTimeTZArray:
475
+ """Represent TIMESTAMPTZ ARRAY in PostgreSQL."""
476
+
477
+ def __init__(
478
+ self: Self,
479
+ inner: typing.Sequence[datetime | typing.Sequence[datetime] | typing.Any,],
480
+ ) -> None:
481
+ """Create new instance of DateArray.
482
+
483
+ ### Parameters:
484
+ - `inner`: inner value, sequence of datetime values.
485
+ """
486
+
487
+ class MacAddr6Array:
488
+ """Represent MACADDR ARRAY in PostgreSQL."""
489
+
490
+ def __init__(
491
+ self: Self,
492
+ inner: typing.Sequence[MacAddr6 | typing.Sequence[MacAddr6] | typing.Any,],
493
+ ) -> None:
494
+ """Create new instance of MacAddr6Array.
495
+
496
+ ### Parameters:
497
+ - `inner`: inner value, sequence of PyMacAddr6 values.
498
+ """
499
+
500
+ class MacAddr8Array:
501
+ """Represent MACADDR8 ARRAY in PostgreSQL."""
502
+
503
+ def __init__(
504
+ self: Self,
505
+ inner: typing.Sequence[MacAddr8 | typing.Sequence[MacAddr8] | typing.Any,],
506
+ ) -> None:
507
+ """Create new instance of MacAddr8Array.
508
+
509
+ ### Parameters:
510
+ - `inner`: inner value, sequence of PyMacAddr8 values.
511
+ """
512
+
513
+ class NumericArray:
514
+ """Represent NUMERIC ARRAY in PostgreSQL."""
515
+
516
+ def __init__(
517
+ self: Self,
518
+ inner: typing.Sequence[Decimal | typing.Sequence[Decimal] | typing.Any,],
519
+ ) -> None:
520
+ """Create new instance of NumericArray.
521
+
522
+ ### Parameters:
523
+ - `inner`: inner value, sequence of Decimal values.
524
+ """
525
+
526
+ class PointArray:
527
+ """Represent POINT ARRAY in PostgreSQL."""
528
+
529
+ def __init__(
530
+ self: Self,
531
+ inner: typing.Sequence[Point | typing.Sequence[Point] | typing.Any,],
532
+ ) -> None:
533
+ """Create new instance of PointArray.
534
+
535
+ ### Parameters:
536
+ - `inner`: inner value, sequence of PyPoint values.
537
+ """
538
+
539
+ class BoxArray:
540
+ """Represent BOX ARRAY in PostgreSQL."""
541
+
542
+ def __init__(
543
+ self: Self,
544
+ inner: typing.Sequence[Box | typing.Sequence[Box] | typing.Any,],
545
+ ) -> None:
546
+ """Create new instance of BoxArray.
547
+
548
+ ### Parameters:
549
+ - `inner`: inner value, sequence of Box values.
550
+ """
551
+
552
+ class PathArray:
553
+ """Represent PATH ARRAY in PostgreSQL."""
554
+
555
+ def __init__(
556
+ self: Self,
557
+ inner: typing.Sequence[Path | typing.Sequence[Path] | typing.Any,],
558
+ ) -> None:
559
+ """Create new instance of PathArray.
560
+
561
+ ### Parameters:
562
+ - `inner`: inner value, sequence of PyPath values.
563
+ """
564
+
565
+ class LineArray:
566
+ """Represent LINE ARRAY in PostgreSQL."""
567
+
568
+ def __init__(
569
+ self: Self,
570
+ inner: typing.Sequence[Line | typing.Sequence[Line] | typing.Any,],
571
+ ) -> None:
572
+ """Create new instance of LineArray.
573
+
574
+ ### Parameters:
575
+ - `inner`: inner value, sequence of PyLine values.
576
+ """
577
+
578
+ class LsegArray:
579
+ """Represent LSEG ARRAY in PostgreSQL."""
580
+
581
+ def __init__(
582
+ self: Self,
583
+ inner: typing.Sequence[LineSegment | typing.Sequence[LineSegment] | typing.Any,],
584
+ ) -> None:
585
+ """Create new instance of LsegArray.
586
+
587
+ ### Parameters:
588
+ - `inner`: inner value, sequence of PyLineSegment values.
589
+ """
590
+
591
+ class CircleArray:
592
+ """Represent CIRCLE ARRAY in PostgreSQL."""
593
+
594
+ def __init__(
595
+ self: Self,
596
+ inner: typing.Sequence[Circle | typing.Sequence[Circle] | typing.Any,],
597
+ ) -> None:
598
+ """Create new instance of CircleArray.
599
+
600
+ ### Parameters:
601
+ - `inner`: inner value, sequence of PyCircle values.
602
+ """
603
+
604
+ class IntervalArray:
605
+ """Represent INTERVAL ARRAY in PostgreSQL."""
606
+
607
+ def __init__(
608
+ self: Self,
609
+ inner: typing.Sequence[timedelta | typing.Sequence[timedelta] | typing.Any,],
610
+ ) -> None:
611
+ """Create new instance of IntervalArray.
612
+
613
+ ### Parameters:
614
+ - `inner`: inner value, sequence of timedelta values.
615
+ """
616
+
617
+ class PgVector:
618
+ """Represent VECTOR in PostgreSQL."""
619
+
620
+ def __init__(
621
+ self: Self,
622
+ inner: typing.Sequence[float | int],
623
+ ) -> None:
624
+ """Create new instance of PgVector.
625
+
626
+ ### Parameters:
627
+ - `inner`: inner value, sequence of float or int values.
628
+ """
@@ -0,0 +1,67 @@
1
+ from typing import Any, Generic, TypeVar
2
+
3
+ from typing_extensions import Self
4
+
5
+ _CustomClass = TypeVar(
6
+ "_CustomClass",
7
+ )
8
+
9
+ def tuple_row(row: dict[str, Any]) -> tuple[tuple[str, Any]]:
10
+ """Convert dict row into tuple row.
11
+
12
+ ### Parameters:
13
+ - `row`: row in dictionary.
14
+
15
+ ### Returns:
16
+ row as a tuple of tuples.
17
+
18
+ ### Example:
19
+ ```
20
+ dict_ = {
21
+ "psqlpy": "is",
22
+ "postgresql": "driver",
23
+ }
24
+ # This function will convert this dict into:
25
+ (("psqlpy", "is"), ("postgresql": "driver"))
26
+ ```
27
+ """
28
+
29
+ class class_row(Generic[_CustomClass]): # noqa: N801
30
+ """Row converter to specified class.
31
+
32
+ ### Example:
33
+ ```python
34
+ from psqlpy.row_factories import class_row
35
+
36
+
37
+ class ValidationModel:
38
+ name: str
39
+ views_count: int
40
+
41
+
42
+ async def main:
43
+ res = await db_pool.execute(
44
+ "SELECT * FROM users",
45
+ )
46
+
47
+ results: list[ValidationModel] = res.row_factory(
48
+ class_row(ValidationModel),
49
+ )
50
+ ```
51
+ """
52
+
53
+ def __init__(self: Self, class_: type[_CustomClass]) -> None:
54
+ """Construct new `class_row`.
55
+
56
+ ### Parameters:
57
+ - `class_`: class to transform row into.
58
+ """
59
+ def __call__(self, row: dict[str, Any]) -> _CustomClass:
60
+ """Convert row into specified class.
61
+
62
+ ### Parameters:
63
+ - `row`: row in dictionary.
64
+
65
+ ### Returns:
66
+ Constructed specified class.
67
+ """