-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test and update sql connector * lint * add test * pr review * pr review Co-authored-by: ncgl-syngenta <[email protected]>
- Loading branch information
1 parent
22a173e
commit 1e6bd17
Showing
3 changed files
with
22 additions
and
5 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
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 |
---|---|---|
@@ -1,10 +1,18 @@ | ||
import typing | ||
|
||
from syngenta_digital_dta.postgres.sql_connector import SQLConnector | ||
|
||
|
||
def sql_connection(func): | ||
def sql_connection(func: typing.Callable) -> typing.Callable: | ||
__connections = {} | ||
def decorator(obj): | ||
if not __connections.get(obj.database): | ||
__connections[obj.database] = SQLConnector(obj) | ||
|
||
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]) | ||
|
||
__connections[obj.database] = SQLConnector(obj) | ||
return func(obj, __connections[obj.database]) | ||
|
||
return decorator |
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