Skip to content

Commit

Permalink
endpoint instead of db for connection caching (#79)
Browse files Browse the repository at this point in the history
Co-authored-by: ncgl-syngenta <[email protected]>
  • Loading branch information
ncgl-syngenta and ncgl-syngenta authored Oct 11, 2021
1 parent 1e6bd17 commit 2f31396
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions syngenta_digital_dta/postgres/sql_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ def sql_connection(func: typing.Callable) -> typing.Callable:
def decorator(obj: typing.Union["PostgresAdapter", "RedshiftAdapter"]):

# reuse the existing connection if it isn't closed
if __connections.get(obj.database) and __connections[obj.database].connection and not __connections[obj.database].connection.closed:
return func(obj, __connections[obj.database])
if __connections.get(obj.endpoint) and __connections[obj.endpoint].connection and not __connections[obj.endpoint].connection.closed:
return func(obj, __connections[obj.endpoint])

__connections[obj.database] = SQLConnector(obj)
return func(obj, __connections[obj.database])
__connections[obj.endpoint] = SQLConnector(obj)
return func(obj, __connections[obj.endpoint])

return decorator

0 comments on commit 2f31396

Please sign in to comment.