-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
8d6edc2
commit 4bdf7dc
Showing
1 changed file
with
49 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from contextlib import contextmanager | ||
from typing import Optional | ||
|
||
import snowflake.connector | ||
|
||
from polar_bare.pbear.generic_db import PolarBareDB | ||
|
||
########## | ||
|
||
|
||
class PolarSnowflake(PolarBareDB): | ||
""" | ||
Establish and authenticate a connection to a Snowflake warehouse | ||
""" | ||
|
||
def __init__( | ||
self, | ||
username: Optional[str] = None, | ||
password: Optional[str] = None, | ||
account: Optional[str] = None, | ||
session_parameters: dict = {}, | ||
): | ||
self.__username = username | ||
self.__password = password | ||
self.account = account | ||
self.session_parameters = session_parameters | ||
|
||
@contextmanager | ||
def connection(self): | ||
""" | ||
TODO - Fill this in | ||
""" | ||
|
||
connection = snowflake.connector.connect( | ||
user=self.__username, | ||
password=self.__password, | ||
account=self.account, | ||
session_parameters=self.session_parameters, | ||
) | ||
|
||
try: | ||
yield connection | ||
except snowflake.connector.Error: | ||
connection.rollback() | ||
raise | ||
else: | ||
connection.commit() | ||
finally: | ||
connection.close() |