-
Notifications
You must be signed in to change notification settings - Fork 0
/
table_creation.py
25 lines (19 loc) · 923 Bytes
/
table_creation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import sqlalchemy
from db_setup import database_create
def create_table(table_data_dict):
"""use data stored as dictionary to create table"""
column_args_list = []
for num in range(len(table_data_dict['column_titles'])):
column_set = sqlalchemy.Column(table_data_dict['column_titles'][num], table_data_dict['column_datatypes'][num])
if table_data_dict['primary_key'] == column_set.name:
column_set = sqlalchemy.Column(table_data_dict['column_titles'][num], table_data_dict['column_datatypes'][num], primary_key=True)
column_args_list.append(column_set)
else:
column_args_list.append(column_set)
new_table = sqlalchemy.Table(table_data_dict['table_title'], metadata, *column_args_list)
metadata.create_all(engine)
print('''
Table has successfully been created.
''')
return
engine, connection, metadata = database_create()