uesleilima opened a new pull request, #2374:
URL: https://github.com/apache/age/pull/2374
## Summary
Two enhancements to the Python driver's public API:
### 1. Public API for connection pooling / external connection management
(#2369)
The `Age` class creates and owns a single connection internally. There's no
supported way to register agtype adapters on externally-managed connections
(e.g., from `psycopg_pool.ConnectionPool`).
**Solution:** Add `configure_connection(conn, graph_name=None,
skip_load=False)` that:
- Sets `search_path` to `ag_catalog`
- Fetches agtype OIDs and registers `AgeLoader`
- Optionally checks/creates the graph
- Does **not** call `LOAD 'age'` by default (suitable for managed PostgreSQL
services)
Also explicitly exports `AgeLoader`, `ClientCursor`, and
`configure_connection` as public symbols in `age/__init__.py`, eliminating the
need for `# type: ignore` when accessing driver internals.
**Usage with connection pool:**
```python
from age import configure_connection, ClientCursor
from psycopg_pool import ConnectionPool
pool = ConnectionPool(
conninfo="host=localhost dbname=mydb",
configure=configure_connection,
kwargs={"cursor_factory": ClientCursor},
)
```
### 2. Vertex/Edge/Path model classes dict/JSON conversion (#2371)
The driver's model classes lack conversion to plain Python data structures,
forcing every consumer to write custom normalization.
**Solution:** Add `to_dict()` methods:
- `Vertex.to_dict()` → `{"id", "label", "properties"}`
- `Edge.to_dict()` → `{"id", "label", "start_id", "end_id", "properties"}`
- `Path.to_dict()` → list of `to_dict()` results
All return plain dicts/lists that work directly with `json.dumps()`.
## Tests
Added 8 new unit tests (no DB required):
- `TestModelToDict` (5 tests): vertex, edge, path `to_dict()`, empty
properties, JSON serializability
- `TestPublicImports` (3 tests): verify `configure_connection`, `AgeLoader`,
`ClientCursor` are importable
## Closes
- Closes #2369
- Closes #2371
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]