I am trying to task SQLAlchemy ORM to create class Field
that describes all fields in my database:
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Field(Base):
__tablename__ = 'fields'
__table_args__ = {'schema':'SCM'}
id = Column(String(20), primary_key=True)
The issue is that table fields
describes different fields in different schemas, i.e.
SCM.fields
TDN.fields
...
I need class Field to
- Be initialized with object
fieldset
before records can be read from db
- Schema determined by
fieldset.get_schema()
before table <schema>.fields
is read.
Something like this:
session.query(Field(fieldset))).filter(Field.id=='some field')
However, adding
def __init__(self, fieldset)
pass
to class Field
results in
__init__() takes 1 positional argument...
- I could lump all
fields
tables into one schema and add column 'schema_name' but I still need Field have link to its fieldset.
Can this be done using SQLAlchemy ORM or should I switch to SqlAlchemy Core where I would have more control over object instantiation?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…