Last active
March 9, 2019 04:14
-
-
Save rodolfobandeira/2bd10aea98404c18a21794e77b245035 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 json | |
from sqlalchemy import * | |
engine = create_engine('CONNECTION STRING') | |
connection = engine.connect() | |
with open('config.json', 'r') as jsonFile: | |
jsonString = jsonFile.read() | |
config = json.loads(jsonString) | |
snippets = config['snippets'] | |
for snippet in snippets: | |
with open(snippets[snippet]) as snippetFile: | |
snippets[snippet] = snippetFile.read() | |
for view in config['views']: | |
with open(view['query_file'], 'r') as queryFile: | |
query = queryFile.read() | |
for snippet in snippets: | |
query = query.replace(snippet, snippets[snippet]) | |
trans = connection.begin() | |
connection.execute('drop table if exists ' + view['name'] + ';') | |
connection.execute('create table ' + view['name'] + ' as ' + query) | |
connection.execute('grant select on ' + view['name'] + ' to ' + view['user_list'] + ';') | |
trans.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment