8000 Merge pull request #97 from psqlpy-python/release/0.8.2 · psqlpy-python/psqlpy@fd9a25a · GitHub
[go: up one dir, main page]

Skip to content

Commit fd9a25a

Browse files
authored
Merge pull request #97 from psqlpy-python/release/0.8.2
Added Python 3.13 support
2 parents 89f92bf + 3ba42e6 commit fd9a25a

17 files changed

+333
-191
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
name: ${{matrix.job.os}}-${{matrix.py_version}}
5555
strategy:
5656
matrix:
57-
py_version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
57+
py_version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
5858
job:
5959
- os: ubuntu-latest
6060
ssl_cmd: sudo apt-get update && sudo apt-get install libssl-dev openssl

Cargo.lock

Lines changed: 36 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "psqlpy"
3-
version = "0.8.1"
3+
version = "0.8.2"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -14,10 +14,14 @@ pyo3 = { version = "*", features = [
1414
"chrono",
1515
"experimental-async",
1616
"rust_decimal",
17+
"py-clone",
18+
"gil-refs",
19+
"macros",
1720
] }
18-
pyo3-asyncio = { git = "https://github.com/chandr-andr/pyo3-asyncio.git", version = "0.20.0", features = [
21+
pyo3-async-runtimes = { git = "https://github.com/chandr-andr/pyo3-async-runtimes.git", branch = "main", features = [
1922
"tokio-runtime",
2023
] }
24+
2125
tokio = { version = "1.35.1", features = ["full"] }
2226
thiserror = "1.0.56"
2327
bytes = "1.5.0"

python/tests/test_binary_copy.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import os
2+
import typing
3+
from io import BytesIO
4+
5+
import pytest
6+
from pgpq import ArrowToPostgresBinaryEncoder
7+
from pyarrow import parquet
8+
9+
from psqlpy import ConnectionPool
10+
11+
pytestmark = pytest.mark.anyio
12+
13+
14+
async def test_binary_copy_to_table_in_connection(
15+
psql_pool: ConnectionPool,
16+
) -> None:
17+
"""Test binary copy in connection."""
18+
table_name: typing.Final = "cars"
19+
await psql_pool.execute(f"DROP TABLE IF EXISTS {table_name}")
20+
await psql_pool.execute(
21+
"""
22+
CREATE TABLE IF NOT EXISTS cars (
23+
model VARCHAR,
24+
mpg FLOAT8,
25+
cyl INTEGER,
26+
disp FLOAT8,
27+
hp INTEGER,
28+
drat FLOAT8,
29+
wt FLOAT8,
30+
qsec FLOAT8,
31+
vs INTEGER,
32+
am INTEGER,
33+
gear INTEGER,
34+
carb INTEGER
35+
);
36+
""",
37+
)
38+
39+
arrow_table = parquet.read_table(
40+
f"{os.path.dirname(os.path.abspath(__file__))}/test_data/MTcars.parquet", # noqa: PTH120, PTH100
41+
)
42+
encoder = ArrowToPostgresBinaryEncoder(arrow_table.schema)
43+
buf = BytesIO()
44+
buf.write(encoder.write_header())
45+
for batch in arrow_table.to_batches():
46+
buf.write(encoder.write_batch(batch))
47+
buf.write(encoder.finish())
48+
buf.seek(0)
49+
50+
async with psql_pool.acquire() as connection:
51+
inserted_rows = await connection.binary_copy_to_table(
52+
source=buf,
53+
table_name=table_name,
54+
)
55+
56+
expected_inserted_row: typing.Final = 32
57+
58+
assert inserted_rows == expected_inserted_row
59+
60+
real_table_rows: typing.Final = await psql_pool.execute(
61+
f"SELECT COUNT(*) AS rows_count FROM {table_name}",
62+
)
63+
assert real_table_rows.result()[0]["rows_count"] == expected_inserted_row
64+
65+
66+
async def test_binary_copy_to_table_in_transaction(
67+
psql_pool: ConnectionPool,
68+
) -> None:
69+
"""Test binary copy in transaction."""
70+
table_name: typing.Final = "cars"
71+
await psql_pool.execute(f"DROP TABLE IF EXISTS {table_name}")
72+
await psql_pool.execute(
73+
"""
74+
CREATE TABLE IF NOT EXISTS cars (
75+
model VARCHAR,
76+
mpg FLOAT8,
77+
cyl INTEGER,
78+
disp FLOAT8,
79+
hp INTEGER,
80+
drat FLOAT8,
81+
wt FLOAT8,
82+
qsec FLOAT8,
83+
vs INTEGER,
84+
am INTEGER,
85+
gear INTEGER,
86+
carb INTEGER
87+
);
88+
""",
89+
)
90+
91+
arrow_table = parquet.read_table(
92+
f"{os.path.dirname(os.path.abspath(__file__))}/test_data/MTcars.parquet", # noqa: PTH120, PTH100
93+
)
94+
encoder = ArrowToPostgresBinaryEncoder(arrow_table.schema)
95+
buf = BytesIO()
96+
buf.write(encoder.write_header())
97+
for batch in arrow_table.to_batches():
98+
buf.write(encoder.write_batch(batch))
99+
buf.write(encoder.finish())
100+
buf.seek(0)
101+
102+
async with psql_pool.acquire() as connection:
103+
inserted_rows = await connection.binary_copy_to_table(
104+
source=buf,
105+
table_name=table_name,
106+
)
107+
108+
expected_inserted_row: typing.Final = 32
109+
110+
assert inserted_rows == expected_inserted_row
111+
112+
real_table_rows: typing.Final = await psql_pool.execute(
113+
f"SELECT COUNT(*) AS rows_count FROM {table_name}",
114+
)
115+
assert real_table_rows.result()[0]["rows_count"] == expected_inserted_row

0 commit comments

Comments
 (0)
0