Skip to content

Commit c85f84a

Browse files
author
Eugene Shershen
committed
implement UUID parameter binding
1 parent 1099f70 commit c85f84a

4 files changed

Lines changed: 58 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ jobs:
1111
test:
1212
name: test
1313
runs-on: ${{ matrix.os }}
14+
services:
15+
postgres:
16+
image: postgres:15
17+
env:
18+
POSTGRES_PASSWORD: password
19+
POSTGRES_USER: postgres
20+
POSTGRES_DB: test_db
21+
options: >-
22+
--health-cmd pg_isready
23+
--health-interval 10s
24+
--health-timeout 5s
25+
--health-retries 5
26+
ports:
27+
- 5432:5432
1428
strategy:
1529
matrix:
1630
build: [linux_3.8, linux_3.9, linux_3.10, linux_3.11, linux_3.13, windows_3.9, windows_3.13, mac_3.9, mac_3.13]
@@ -56,9 +70,21 @@ jobs:
5670
python -m pip install --upgrade pip wheel
5771
pip install -e ".[dev]"
5872
73+
- name: Run tests (with PostgreSQL on Linux)
74+
if: startsWith(matrix.build, 'linux')
75+
run: python -m pytest tests/ -v
76+
env:
77+
DATABASE_URL: postgresql+psqlpy://postgres:password@localhost:5432/test_db
78+
79+
- name: Run tests (without PostgreSQL on Windows/Mac)
80+
if: "!startsWith(matrix.build, 'linux')"
81+
run: python -m pytest tests/ -v
82+
5983
- name: Produce coverage report
6084
if: matrix.build == 'linux_3.9'
6185
run: pytest --cov=psqlpy_sqlalchemy --cov-report=xml
86+
env:
87+
DATABASE_URL: postgresql+psqlpy://postgres:password@localhost:5432/test_db
6288

6389
- name: Upload coverage report
6490
if: matrix.build == 'linux_3.9'

psqlpy_sqlalchemy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
PsqlpyDialect = PSQLPyAsyncDialect
44

5-
__version__ = "0.1.0a7"
5+
__version__ = "0.1.0a8"
66
__all__ = ["PsqlpyDialect", "PSQLPyAsyncDialect"]

psqlpy_sqlalchemy/dialect.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import typing as t
2+
import uuid
23
from types import ModuleType
34
from typing import Any, Dict, MutableMapping, Sequence, Tuple
45

56
import psqlpy
67
from sqlalchemy import URL, util
7-
from sqlalchemy.dialects.postgresql.base import INTERVAL, PGDialect
8+
from sqlalchemy.dialects.postgresql.base import INTERVAL, UUID, PGDialect
89
from sqlalchemy.dialects.postgresql.json import JSONPathType
910
from sqlalchemy.pool import AsyncAdaptedQueuePool, NullPool
1011
from sqlalchemy.sql import operators, sqltypes
@@ -218,6 +219,29 @@ class _PGNullType(sqltypes.NullType):
218219
render_bind_cast = True
219220

220221

222+
class _PGUUID(UUID):
223+
"""PostgreSQL UUID type with proper parameter binding for psqlpy."""
224+
225+
def bind_processor(self, dialect):
226+
"""Process UUID parameters for psqlpy compatibility."""
227+
228+
def process(value):
229+
if value is None:
230+
return None
231+
if isinstance(value, uuid.UUID):
232+
return str(value)
233+
if isinstance(value, str):
234+
# Validate that it's a proper UUID string
235+
try:
236+
uuid.UUID(value)
237+
return value
238+
except ValueError:
239+
raise ValueError(f"Invalid UUID string: {value}")
240+
return str(value)
241+
242+
return process
243+
244+
221245
class PSQLPyAsyncDialect(PGDialect):
222246
driver = "psqlpy"
223247
is_async = True
@@ -264,6 +288,7 @@ class PSQLPyAsyncDialect(PGDialect):
264288
sqltypes.SmallInteger: _PGSmallInteger,
265289
sqltypes.BigInteger: _PGBigInteger,
266290
sqltypes.Boolean: _PGBoolean,
291+
UUID: _PGUUID, # UUID support with proper parameter binding
267292
# Note: NullType mapping removed - standard PostgreSQL dialect doesn't map it
268293
# and mapping it with render_bind_cast=True causes DDL compilation errors
269294
},

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "psqlpy-sqlalchemy"
7-
version = "0.1.0a7"
7+
version = "0.1.0a8"
88
description = "SQLAlchemy dialect for psqlpy PostgreSQL driver"
99
readme = "README.md"
1010
license = {text = "MIT"}
@@ -36,6 +36,7 @@ dependencies = [
3636
dev = [
3737
"pytest>=7.0.0",
3838
"pytest-asyncio>=0.21.0",
39+
"greenlet>=1.0.0",
3940
"ruff>=0.1.0",
4041
"mypy>=1.0.0",
4142
"sqlmodel>=0.0.8",
@@ -112,3 +113,6 @@ ignore_errors = true
112113
[[tool.mypy.overrides]]
113114
module = "tests.*"
114115
ignore_errors = true
116+
117+
[tool.pytest.ini_options]
118+
asyncio_mode = "auto"

0 commit comments

Comments
 (0)