Skip to content

Commit 0006ed3

Browse files
committed
data client inheritance
1 parent 173a656 commit 0006ed3

18 files changed

Lines changed: 148 additions & 138 deletions

Pipfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ verify_ssl = true
66
[dev-packages]
77

88
[packages]
9-
Google-Cloud-BigQuery = "*"
109
SQLAlchemy = "*"
1110
PyBigQuery = "*"
1211
PyMySQL = "*"

Pipfile.lock

Lines changed: 10 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

config/bigquery_config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from os import environ
2+
3+
# Google Cloud config
4+
gcp_credentials = environ.get('GCP_CREDENTIALS')
5+
gcp_project = environ.get('GCP_PROJECT')
6+
7+
# Google BigQuery config
8+
bigquery_dataset = environ.get('GCP_BIGQUERY_DATASET')
9+
bigquery_table = environ.get('GCP_BIGQUERY_TABLE')

config/sql_config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from os import environ
2+
3+
4+
# SQL database config
5+
database_username = environ.get('DATABASE_USERNAME')
6+
database_password = environ.get('DATABASE_PASSWORD')
7+
database_host = environ.get('DATABASE_HOST')
8+
database_port = environ.get('DATABASE_PORT')
9+
database_name = environ.get('DATABASE_DATABASE_NAME')
10+
database_table = environ.get('DATABASE_TABLE_NAME')

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ certifi==2019.9.11
33
chardet==3.0.4
44
future==0.18.2
55
google-api-core==1.14.3
6-
google-auth==1.7.0
7-
google-cloud-bigquery==1.21.0
6+
google-auth==1.7.1
7+
google-cloud-bigquery==1.22.0
88
google-cloud-core==1.0.3
9-
google-resumable-media==0.4.1
9+
google-resumable-media==0.5.0
1010
googleapis-common-protos==1.6.0
1111
idna==2.8
1212
protobuf==3.10.0

src/__init__.py

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,9 @@
1-
from config import Config
2-
from src.bigquery import BigQueryClient
3-
from src.database import SQLClient
4-
from src.util.read import get_query_from_file
1+
from src.sources.bigquery import bqc
2+
from src.sources.database import dbc
3+
from src.queries import analytics_query
54

65

76
def main():
8-
bigquery = init_bigquery()
9-
database = init_database()
10-
query = get_query_from_file(Config.bigquery_query)
11-
rows = bigquery.fetch_rows(query)
12-
updated = database.insert_rows(rows, replace=True)
7+
rows = bqc.fetch_rows(analytics_query)
8+
updated = dbc.insert_rows(rows, replace=True)
139
print(updated)
14-
15-
16-
def init_bigquery():
17-
"""Initiate BigQuery Client."""
18-
uri, creds = Config.get_bigquery_config()
19-
bigquery = BigQueryClient(uri=uri, creds=creds)
20-
return bigquery
21-
22-
23-
def init_database():
24-
"""Initiate SQL database Client."""
25-
uri, table = Config.get_database_config(type='mysql')
26-
bigquery = SQLClient(uri=uri, table=table)
27-
return bigquery

src/bigquery.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/database.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/queries/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .read import read_query
2+
3+
prefix = 'src/queries/sql'
4+
analytics_query = read_query(f'{prefix}/analytics.sql')

0 commit comments

Comments
 (0)