Last active
January 29, 2022 14:11
-
-
Save martinyung/d5d2c969dfe9a8ebb39727510007e500 to your computer and use it in GitHub Desktop.
python etl
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
# example queries, will be different across different db platform | |
firebird_extract = (''' | |
SELECT fbd_column_1, fbd_column_2, fbd_column_3 | |
FROM fbd_table; | |
''') | |
firebird_insert = (''' | |
INSERT INTO table (column_1, column_2, column_3) | |
VALUES (?, ?, ?) | |
''') | |
firebird_extract_2 = (''' | |
SELECT fbd_column_1, fbd_column_2, fbd_column_3 | |
FROM fbd_table_2; | |
''') | |
firebird_insert_2 = (''' | |
INSERT INTO table_2 (column_1, column_2, column_3) | |
VALUES (?, ?, ?) | |
''') | |
sqlserver_extract = (''' | |
SELECT sqlserver_column_1, sqlserver_column_2, sqlserver_column_3 | |
FROM sqlserver_table | |
''') | |
sqlserver_insert = (''' | |
INSERT INTO table (column_1, column_2, column_3) | |
VALUES (?, ?, ?) | |
''') | |
mysql_extract = (''' | |
SELECT mysql_column_1, mysql_column_2, mysql_column_3 | |
FROM mysql_table | |
''') | |
mysql_insert = (''' | |
INSERT INTO table (column_1, column_2, column_3) | |
VALUES (?, ?, ?) | |
''') | |
# exporting queries | |
class SqlQuery: | |
def __init__(self, extract_query, load_query): | |
self.extract_query = extract_query | |
self.load_query = load_query | |
# create instances for SqlQuery class | |
fbd_query = SqlQuery(firebird_extract, firebird_insert) | |
fbd_query_2 = SqlQuery(firebird_extract_2, firebird_insert_2) | |
sqlserver_query = SqlQuery(sqlserver_extract, sqlserver_insert) | |
mysql_query = SqlQuery(mysql_extract, mysql_insert) | |
# store as list for iteration | |
fbd_queries = [fbdquery, fbd_query_2] | |
sqlserver_queries = [sqlserver_query] | |
mysql_queries = [mysql_query] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment