Created
March 14, 2020 02:15
-
-
Save Shogun89/4a53abfe6b92c2f6eb52f755473abfce to your computer and use it in GitHub Desktop.
query_mapping
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
import pandas as pd | |
import os | |
import mysql.connector | |
def basic_data(data): | |
query= data[0] | |
cursor = data[1] | |
cursor.execute(query) | |
df = pd.DataFrame(cursor.fetchall(),columns=cursor.column_names) | |
return df | |
query1 = """ select * from tbl1 """ | |
query2 = """ select * from tbl2 """ | |
queryn = """ select * from tbln """ | |
queries = [query1, query2, queryn] | |
creds = os.environ['MYSQL_CREDS'].split('@#$') | |
cnx = mysql.connector.connect(host=creds[0],user=creds[1],password=creds[2],database=creds[3]) | |
cursor = cnx.cursor() | |
map_queries = list(zip(queries, len(queries)*[cursor])) | |
get_data = list(map(basic_data, map_queries)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment