I am currently using SQLalchemy with python 3.7 and I was wondering If I could do somehow the following:
eng = create_engine('sqlite:///test.db')
Base = declarative_base()
with open("columns.json", "r") as f:
columns = json.load(f)
class Tablename(Base):
__tablename__ = "Tablename"
IID = Column(Integer, primary_key=True)
for column, attributes in columns.items():
'''Add the {column} as instance variable
so when I create the {Tablename} table
it will have a column named {column} with
the type and max_length properties'''
JSON
{
"Column1": {
"Type": "Integer",
"MinLength": "0",
"MaxLength": "255",
...
},
{
"Column2": {
"Type": "String",
"MinLength": "0",
"MaxLength": "50",
...
},
...
}
So, essentially I would like to generate the table from a JSON file. Is it possible?