Define Sqlalchmey Tables Based On Function Input
This is a follow up question to this question. I'm trying to implement a function that generates a table. The function looks like this: import sqlalchemy as sql import sqlalchemy.o
Solution 1:
Figured it out I just need to define the classes outside of the function scope.
import sqlalchemy as sql
import sqlalchemy.orm
TableBase = sql.orm.declarative_base()
class _RealTimeDataBase(TableBase):
__tablename__ = "TBL_RealTimeData"
id = sql.Column(sql.INTEGER, primary_key=True)
SubTestId = sql.Column(sql.INT)
CellOrCup = sql.Column(sql.INT)
TimeInfo = sql.Column(sql.INT)
TestTemp = sql.Column(sql.FLOAT)
OxygenHumid = sql.Column(sql.FLOAT)
NitrogenHumi = sql.Column(sql.FLOAT)
OTR = sql.Column(sql.FLOAT)
TimeDe = sql.Column(sql.INT)
LocalTime = sql.Column(sql.DATETIME)
class _RealTimeDataPackage(_RealTimeDataBase):
CoffOxy = None
class _RealTimeDataFilm(_RealTimeDataBase):
CoffOxy = sql.Column(sql.FLOAT)
def RealTimeData(testType: int):
if testType == 1:
return _RealTimeDataFilm
else:
return _RealTimeDataPackage
Post a Comment for "Define Sqlalchmey Tables Based On Function Input"