-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
553 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
libs/checkpoint-postgres/langgraph/checkpoint/postgres/_ainternal.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""Shared async utility functions for the Postgres checkpoint & storage classes.""" | ||
|
||
from contextlib import asynccontextmanager | ||
from typing import AsyncIterator, Union | ||
|
||
from psycopg import AsyncConnection | ||
from psycopg.rows import DictRow | ||
from psycopg_pool import AsyncConnectionPool | ||
|
||
Conn = Union[AsyncConnection[DictRow], AsyncConnectionPool[AsyncConnection[DictRow]]] | ||
|
||
|
||
@asynccontextmanager | ||
async def get_connection( | ||
conn: Conn, | ||
) -> AsyncIterator[AsyncConnection[DictRow]]: | ||
if isinstance(conn, AsyncConnection): | ||
yield conn | ||
elif isinstance(conn, AsyncConnectionPool): | ||
async with conn.connection() as conn: | ||
yield conn | ||
else: | ||
raise TypeError(f"Invalid connection type: {type(conn)}") |
21 changes: 21 additions & 0 deletions
21
libs/checkpoint-postgres/langgraph/checkpoint/postgres/_internal.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"""Shared utility functions for the Postgres checkpoint & storage classes.""" | ||
|
||
from contextlib import contextmanager | ||
from typing import Iterator, Union | ||
|
||
from psycopg import Connection | ||
from psycopg.rows import DictRow | ||
from psycopg_pool import ConnectionPool | ||
|
||
Conn = Union[Connection[DictRow], ConnectionPool[Connection[DictRow]]] | ||
|
||
|
||
@contextmanager | ||
def get_connection(conn: Conn) -> Iterator[Connection[DictRow]]: | ||
if isinstance(conn, Connection): | ||
yield conn | ||
elif isinstance(conn, ConnectionPool): | ||
with conn.connection() as conn: | ||
yield conn | ||
else: | ||
raise TypeError(f"Invalid connection type: {type(conn)}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.