8000 Added expicit array types, changed how they convert · psqlpy-python/psqlpy@399cc63 · GitHub
[go: up one dir, main page]

Skip to content

Commit 399cc63

Browse files
committed
Added expicit array types, changed how they convert
Signed-off-by: chandr-andr (Kiselev Aleksandr) <chandr@chandr.net>
1 parent ba3c25d commit 399cc63

File tree

6 files changed

+57
-3
lines changed

6 files changed

+57
-3
lines changed

docs/.vuepress/sidebar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export default sidebar({
3838
collapsible: true,
3939
children: [
4040
"supported_types",
41+
"array_types",
4142
"extra_types",
4243
"advanced_type_usage",
4344
]

docs/components/connection.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,10 @@ async def main() -> None:
184184
- `isolation_level`: level of isolation. Default how it is in PostgreSQL.
185185
- `read_variant`: configure read variant of the transaction. Default how it is in PostgreSQL.
186186
- `deferrable`: configure deferrable of the transaction. Default how it is in PostgreSQL.
187+
- `synchronous_commit`: configure [synchronous_commit](https://postgresqlco.nf/doc/en/param/synchronous_commit/) option for transaction. Default how it is in PostgreSQL.
187188

188189
```python
189-
from psqlpy import IsolationLevel, ReadVariant
190+
from psqlpy import IsolationLevel, ReadVariant, SynchronousCommit
190191

191192
async def main() -> None:
192193
...
@@ -195,6 +196,7 @@ async def main() -> None:
195196
isolation_level=IsolationLevel.Serializable,
196197
read_variant=ReadVariant.ReadWrite,
197198
deferrable=True,
199+
synchronous_commit=SynchronousCommit.On,
198200
)
199201
```
200202

docs/components/connection_pool.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Parameters must be passed as list after querystring.
192192
::: caution
193193
You must use `ConnectionPool.execute` method in high-load production code wisely!
194194
It pulls connection from the pool each time you execute query.
195-
Preferable way to execute statements with [Connection](./../../introduction/components/connection.md) or [Transaction](./../../introduction/components/transaction.md)
195+
Preferable way to execute statements with [Connection](./../components/connection.md) or [Transaction](./../components/transaction.md)
196196
:::
197197

198198
```python

docs/usage/types/array_types.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: Array Types
3+
---
4+
For type safety and better performance we have predefined array types.
5+
6+
| PSQLPy Array Type | PostgreSQL Array Type |
7+
| :---: | :---: |
8+
| BoolArray | BOOLEAN ARRAY |
9+
| UUIDArray | UUID ARRAY |
10+
| VarCharArray | VarChar ARRAY |
11+
| TextArray | Text ARRAY |
12+
| Int16Array | INT2 ARRAY |
13+
| Int32Array | INT4 ARRAY |
14+
| Int64Array | INT8 ARRAY |
15+
| Float32Array | FLOAT4 ARRAY |
16+
| Float64Array | FLOAT8 ARRAY |
17+
| MoneyArray | MONEY ARRAY |
18+
| IpAddressArray | INET ARRAY |
19+
| JSONBArray | JSONB ARRAY |
20+
| JSONArray | JSON ARRAY |
21+
| DateArray | DATE ARRAY |
22+
| TimeArray | TIME ARRAY |
23+
| DateTimeArray | TIMESTAMP ARRAY |
24+
| DateTimeTZArray | TIMESTAMPTZ ARRAY |
25+
| MacAddr6Array | MACADDR ARRAY |
26+
| MacAddr8Array | MACADDR8 ARRAY |
27+
| NumericArray | NUMERIC ARRAY |
28+
| PointArray | POINT ARRAY |
29+
| BoxArray | BOX ARRAY |
30+
| PathArray | PATH ARRAY |
31+
| LineArray | LINE ARRAY |
32+
| LsegArray | LSEG ARRAY |
33+
| CircleArray | CIRCLE ARRAY |
34+
35+
### Example:
36+
37+
```python
38+
from psqlpy import ConnectionPool
39+
from psqlpy.extra_types import TextArray
40+
41+
42+
async def main() -> None:
43+
pool = ConnectionPool()
44+
result = await pool.execute(
45+
querystring="SELECT * FROM users WHERE id = ANY($1)",
46+
parameters=[
47+
TextArray([1, 2, 3]),
48+
]
49+
)
50+
```

docs/usage/types/supported_types.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ DECIMAL PostgreSQL type isn't supported, use NUMERIC instead.
5050
## Array Type
5151

5252
You can make arrays with any type of `Simple Type`s.
53+
For better performance and type safety we recommend to use predefined [Array Types](./array_types.md).
5354

5455
#### Example:
5556
```sql

python/psqlpy/_internal/extra_types.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ class JSONBArray:
489489
"""
490490

491491
class JSONArray:
492-
"""Represent JSONArray ARRAY in PostgreSQL."""
492+
"""Represent JSON ARRAY in PostgreSQL."""
493493

494494
def __init__(
495495
self: Self,

0 commit comments

Comments
 (0)
0