forked from datafold/data-diff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_connect.py
More file actions
54 lines (44 loc) · 1.37 KB
/
_connect.py
File metadata and controls
54 lines (44 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import logging
from data_diff.sqeleton.databases import Connect
from .postgresql import PostgreSQL
from .mysql import MySQL
from .oracle import Oracle
from .snowflake import Snowflake
from .bigquery import BigQuery
from .redshift import Redshift
from .presto import Presto
from .databricks import Databricks
from .trino import Trino
from .clickhouse import Clickhouse
from .vertica import Vertica
from .duckdb import DuckDB
from .mssql import MsSql
DATABASE_BY_SCHEME = {
"postgresql": PostgreSQL,
"mysql": MySQL,
"oracle": Oracle,
"redshift": Redshift,
"snowflake": Snowflake,
"presto": Presto,
"bigquery": BigQuery,
"databricks": Databricks,
"duckdb": DuckDB,
"trino": Trino,
"clickhouse": Clickhouse,
"vertica": Vertica,
"mssql": MsSql,
}
class Connect_SetUTC(Connect):
"""Provides methods for connecting to a supported database using a URL or connection dict.
Ensures all sessions use UTC Timezone, if possible.
"""
def _connection_created(self, db):
db = super()._connection_created(db)
try:
db.query(db.dialect.set_timezone_to_utc())
except NotImplementedError:
logging.debug(
f"Database '{db}' does not allow setting timezone. We recommend making sure it's set to 'UTC'."
)
return db
connect = Connect_SetUTC(DATABASE_BY_SCHEME)