Skip to content

Commit cd19755

Browse files
authored
Merge branch 'main' into patch-2
2 parents 540839c + 2549109 commit cd19755

File tree

11 files changed

+3883
-3316
lines changed

11 files changed

+3883
-3316
lines changed

.github/workflows/release_docs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Setup Node.js
1616
uses: actions/setup-node@v3
1717
with:
18-
node-version: 18
18+
node-version: 20
1919
cache: pnpm
2020
- name: Install deps
2121
run: pnpm install

docs/contribute.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ One of the best ways is follow [maturin offical documentation](https://www.matur
2222
```bash
2323
> python3 -m venv .venv
2424
> source .venv/bin/activate
25-
> pip install -U pip maturin
25+
> pip install -U pip maturin pre-commit pytest pytest-anyio pydantic pgpq
2626
```
2727

2828
Then you need to build `PSQLPy` project.

docs/usage/types/advanced_type_usage.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Due to an unavailability to support all possible types in PostgreSQL, we have a
66
This section has `Advanced` in the name because you'll need to work with raw bytes which can be difficult for some developers.
77

88
## Pass unsupported type into PostgreSQL
9-
If you are using some type that we don't support and want to insert it into PostgreSQL from PSQLPy, you must use `PyCustomType` class.
9+
If you are using some type that we don't support and want to insert it into PostgreSQL from PSQLPy, you must use `CustomType` class.
1010

1111
Let's assume we have table `for_test` in the database and `PSQLPy` doesn't support (only for demonstration) `VARCHAR` type:
1212
| database type | database column name |
@@ -16,24 +16,24 @@ Let's assume we have table `for_test` in the database and `PSQLPy` doesn't suppo
1616
from typing import Final
1717

1818
from psqlpy import ConnectionPool
19-
from psqlpy.extra_types import PyCustomType
19+
from psqlpy.extra_types import CustomType
2020

2121

2222
async def main() -> None:
2323
# It uses default connection parameters
2424
db_pool: Final = ConnectionPool()
2525

26-
await db_pool.execute(
27-
"INSERT INTO for_test (nickname) VALUES ($1)",
28-
[PyCustomType(b"SomeDataInBytes")],
29-
)
30-
db_pool.close()
26+
async with db_pool.acquire() as connection:
27+
await connection.execute(
28+
"INSERT INTO for_test (nickname) VALUES ($1)",
29+
[CustomType(b"SomeDataInBytes")],
30+
)
3131
```
3232

33-
Here we pass `PyCustomType` into the parameters. It accepts only bytes.
33+
Here we pass `CustomType` into the parameters. It accepts only bytes.
3434

3535
::: important
36-
You must make bytes passed into `PyCustomType` readable for `PostgreSQL`.
36+
You must make bytes passed into `CustomType` readable for `PostgreSQL`.
3737
If bytes will be wrong, you will get an exception.
3838
:::
3939

@@ -49,7 +49,7 @@ Let's assume we have table `for_test` in the database and `PSQLPy` doesn't suppo
4949
from typing import Final, Any
5050

5151
from psqlpy import ConnectionPool, QueryResult
52-
from psqlpy.extra_types import PyCustomType
52+
from psqlpy.extra_types import CustomType
5353

5454

5555
def nickname_decoder(bytes_from_psql: bytes | None) -> str:
@@ -60,17 +60,17 @@ async def main() -> None:
6060
# It uses default connection parameters
6161
db_pool: Final = ConnectionPool()
6262

63-
result: QueryResult = await db_pool.execute(
64-
"SELECT * FROM for_test",
65-
[PyCustomType(b"SomeDataInBytes")],
66-
)
63+
async with db_pool.acquire() as connection:
64+
result: QueryResult = await connection.execute(
65+
"SELECT * FROM for_test",
66+
[CustomType(b"SomeDataInBytes")],
67+
)
6768

6869
parsed_result: list[dict[str, Any]] = result.result(
6970
custom_decoders={
7071
"nickname": nickname_decoder,
7172
},
7273
)
73-
db_pool.close()
7474
```
7575

7676
::: important

docs/usage/types/array_types.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ from psqlpy.extra_types import TextArray
4949

5050
async def main() -> None:
5151
pool = ConnectionPool()
52-
result = await pool.execute(
53-
querystring="SELECT * FROM users WHERE name = ANY($1)",
54-
parameters=[
55-
TextArray(["Alex", "Dev", "Who"]),
56-
]
57-
)
52+
async with db_pool.acquire() as connection:
53+
result = await connection.execute(
54+
querystring="SELECT * FROM users WHERE name = ANY($1)",
55+
parameters=[
56+
TextArray(["Alex", "Dev", "Who"]),
57+
]
58+
)
5859
```

docs/usage/types/extra_types.md

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,11 @@ from psqlpy.extra_types import SmallInt, Integer, BigInt, Float32, Float64
6262
async def main() -> None:
6363
# It uses default connection parameters
6464
db_pool: Final = ConnectionPool()
65-
66-
await db_pool.execute(
67-
"INSERT INTO numbers (index, elf_life, elon_musk_money) VALUES ($1, $2, $3, $4, $5)",
68-
[SmallInt(101), Integer(10500), BigInt(300000000000), Float32(123.11), Float64(222.12)],
69-
)
70-
db_pool.close()
65+
async with db_pool.acquire() as connection:
66+
await connection.execute(
67+
"INSERT INTO numbers (index, elf_life, elon_musk_money) VALUES ($1, $2, $3, $4, $5)",
68+
[SmallInt(101), Integer(10500), BigInt(300000000000), Float32(123.11), Float64(222.12)],
69+
)
7170
```
7271

7372
::: important
@@ -96,16 +95,16 @@ async def main() -> None:
9695
# It uses default connection parameters
9796
db_pool: Final = ConnectionPool()
9897

99-
await db_pool.execute(
100-
"INSERT INTO banners (title, description) VALUES ($1, $2)",
101-
["SomeTitle", PyText("Very long description")],
102-
)
103-
# Alternatively, you can do this:
104-
await db_pool.execute(
105-
"INSERT INTO banners (title, description) VALUES ($1, $2)",
106-
[PyVarChar("SomeTitle"), PyText("Very long description")],
107-
)
108-
db_pool.close()
98+
async with db_pool.acquire() as connection:
99+
await connection.execute(
100+
"INSERT INTO banners (title, description) VALUES ($1, $2)",
101+
["SomeTitle", PyText("Very long description")],
102+
)
103+
# Alternatively, you can do this:
104+
await connection.execute(
105+
"INSERT INTO banners (title, description) VALUES ($1, $2)",
106+
[PyVarChar("SomeTitle"), PyText("Very long description")],
107+
)
109108
```
110109

111110
## PyJSON & PyJSONB
@@ -140,6 +139,7 @@ from psqlpy.extra_types import PyJSON
140139
async def main() -> None:
141140
# It uses default connection parameters
142141
db_pool: Final = ConnectionPool()
142+
143143
list_for_jsonb_field = [
144144
{"some": "dict"},
145145
[
@@ -154,16 +154,15 @@ async def main() -> None:
154154
]
155155
}
156156

157-
await db_pool.execute(
158-
"INSERT INTO users (additional_user_info) VALUES ($1)",
159-
[PyJSONB(list_for_jsonb_field)],
160-
)
161-
await db_pool.execute(
162-
"INSERT INTO users (additional_user_info) VALUES ($1)",
163-
[dict_for_jsonb_field,],
164-
)
165-
166-
db_pool.close()
157+
async with db_pool.acquire() as connection:
158+
await connection.execute(
159+
"INSERT INTO users (additional_user_info) VALUES ($1)",
160+
[PyJSONB(list_for_jsonb_field)],
161+
)
162+
await connection.execute(
163+
"INSERT INTO users (additional_user_info) VALUES ($1)",
164+
[dict_for_jsonb_field,],
165+
)
167166
```
168167

169168
## PyMacAddr6 & PyMacAddr8
@@ -186,15 +185,14 @@ async def main() -> None:
186185
# It uses default connection parameters
187186
db_pool: Final = ConnectionPool()
188187

189-
await db_pool.execute(
190-
"INSERT INTO devices (device_macaddr6, device_macaddr8) VALUES ($1, $2)",
191-
[
192-
PyMacAddr6("08:00:2b:01:02:03"),
193-
PyMacAddr8("08:00:2b:01:02:03:04:05"),
194-
],
195-
)
196-
197-
db_pool.close()
188+
async with db_pool.acquire() as connection:
189+
await connection.execute(
190+
"INSERT INTO devices (device_macaddr6, device_macaddr8) VALUES ($1, $2)",
191+
[
192+
PyMacAddr6("08:00:2b:01:02:03"),
193+
PyMacAddr8("08:00:2b:01:02:03:04:05"),
194+
],
195+
)
198196
```
199197

200198
## Geo Types
@@ -222,17 +220,16 @@ async def main() -> None:
222220
# It uses default connection parameters
223221
db_pool: Final = ConnectionPool()
224222

225-
await db_pool.execute(
226-
"INSERT INTO geo_info VALUES ($1, $2, $3, $4, $5, $6)",
227-
[
228-
Point([1.5, 2]),
229-
Box([(1.7, 2.8), (9, 9)]),
230-
Path([(3.5, 3), (9, 9), (8, 8)]),
231-
Line([1, -2, 3]),
232-
LineSegment([(5.6, 3.1), (4, 5)]),
233-
Circle([5, 1.8, 10]),
234-
],
235-
)
236-
237-
db_pool.close()
223+
async with db_pool.acquire() as connection:
224+
await connection.execute(
225+
"INSERT INTO geo_info VALUES ($1, $2, $3, $4, $5, $6)",
226+
[
227+
Point([1.5, 2]),
228+
Box([(1.7, 2.8), (9, 9)]),
229+
Path([(3.5, 3), (9, 9), (8, 8)]),
230+
Line([1, -2, 3]),
231+
LineSegment([(5.6, 3.1), (4, 5)]),
232+
Circle([5, 1.8, 10]),
233+
],
234+
)
238235
```

docs/usage/types/supported_types.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ async def main() -> None:
8787
# It uses default connection parameters
8888
db_pool: Final = ConnectionPool()
8989

90-
result = await db_pool.execute(
91-
"SELECT user_info FROM custom_table",
92-
)
93-
print(result.result()[0])
90+
async with db_pool.acquire() as connection:
91+
result = await connection.execute(
92+
"SELECT user_info FROM custom_table",
93+
)
94+
print(result.result()[0])
9495
```
9596
It will return:
9697
```json
@@ -132,22 +133,22 @@ class Weather(str, Enum):
132133
async def main() -> None:
133134
# It uses default connection parameters
134135
db_pool: Final = ConnectionPool()
135-
136-
# Insert new data
137-
await db_pool.execute(
138-
querystring="INSERT INTO weather_plus VALUES($1)",
139-
parameters=[Weather.SUN],
140-
)
141-
142-
# Or you can pass string directly
143-
await db_pool.execute(
144-
querystring="INSERT INTO weather_plus VALUES($1)",
145-
parameters=["sun"],
146-
)
147-
148-
result = await db_pool.execute(
149-
querystring="SELECT * FROM weather_plus",
150-
)
136+
async with db_pool.acquire() as connection:
137+
# Insert new data
138+
await connection.execute(
139+
querystring="INSERT INTO weather_plus VALUES($1)",
140+
parameters=[Weather.SUN],
141+
)
142+
143+
# Or you can pass string directly
144+
await connection.execute(
145+
querystring="INSERT INTO weather_plus VALUES($1)",
146+
parameters=["sun"],
147+
)
148+
149+
result = await connection.execute(
150+
querystring="SELECT * FROM weather_plus",
151+
)
151152
print(result.result()[0])
152153
```
153154
You will receive:

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@
1111
"docs:clean-dev": "vuepress-vite dev docs --clean-cache",
1212
"docs:update-package": "pnpm dlx vp-update"
1313
},
14-
"packageManager": "pnpm@7.22.0",
14+
"packageManager": "pnpm@10.18.1",
1515
"devDependencies": {
16-
"@vuepress/bundler-vite": "2.0.0-rc.23",
17-
"@vuepress/plugin-markdown-tab": "2.0.0-rc.47",
18-
"@vuepress/plugin-slimsearch": "2.0.0-rc.106",
19-
"mermaid": "^11.6.0",
20-
"sass": "^1.89.0",
21-
"sass-embedded": "^1.88.0",
16+
"@vuepress/bundler-vite": "2.0.0-rc.24",
17+
"@vuepress/plugin-markdown-tab": "2.0.0-rc.112",
18+
"@vuepress/plugin-slimsearch": "2.0.0-rc.112",
19+
"mermaid": "^11.12.0",
20+
"sass": "^1.93.2",
21+
"sass-embedded": "^1.93.2",
2222
"sass-loader": "^16.0.5",
23-
"vue": "^3.5.13",
24-
"vuepress": "2.0.0-rc.23",
25-
"vuepress-plugin-md-enhance": "2.0.0-rc.88",
26-
"vuepress-theme-hope": "2.0.0-rc.88"
23+
"vue": "^3.5.22",
24+
"vuepress": "2.0.0-rc.24",
25+
"vuepress-plugin-md-enhance": "2.0.0-rc.94",
26+
"vuepress-theme-hope": "2.0.0-rc.94"
2727
},
2828
"dependencies": {
29-
"chart.js": "^4.4.9"
29+
"chart.js": "^4.5.0"
3030
},
3131
"pnpm": {
3232
"onlyBuiltDependencies": [

0 commit comments

Comments
 (0)