Created
January 31, 2024 02:27
-
-
Save jmyeary/27b972032631d4d35e0119a8e026188d to your computer and use it in GitHub Desktop.
automating azure pipelines: bicep tabular translation in python
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 pyodbc | |
import json | |
# Connect to your database - don't hardcode the creds! | |
conn = pydobc.connect(database="your_database", user="your_username", password="your_password", host="your_host", port="your_port") | |
cur = conn.cursor() | |
# List of your tables | |
tables = ["table1", "table2", "table3", "table4", "table5", "table6", "table7", "table8", "table9"] | |
mappings = [] | |
# For each table | |
for table in tables: | |
# Query the schema | |
cur.execute(f"SELECT column_name, data_type FROM information_schema.columns WHERE table_name = '{table}';") | |
columns = cur.fetchall() | |
# For each column | |
for column in columns: | |
# Generate the mapping | |
mapping = { | |
"source": { | |
"name": column[0], | |
"type": "String", | |
"physicalType": column[1] | |
}, | |
"sink": { | |
"name": column[0], | |
"type": "String", | |
"physicalType": column[1] | |
} | |
} | |
mappings.append(mapping) | |
# Output the mappings | |
print(json.dumps(mappings)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment