0
基于my previous post构建,我正致力于将SQLite数据库/数据库模式转换为SQLAlchemy。带外键的动态SQLAlchemy表名
在这里,动态生成一系列表格,并分析基因组名称。每个表都有一个对父表(参考基因组)的外键引用。我怎样才能建立外键
class Genome(DynamicName, Base):
"""
Defines database schema for the reference genome.
"""
__abstract__ = True
TranscriptId = Column(String, primary_key=True)
AnalysisA = Column(Integer)
child = relationship('') # how to declare dynamic name?
class AlignedGenome(DynamicName, Base):
"""
Defines database schema for a target (aligned) genome.
"""
__abstract__ = True
AlignmentId = Column(String, primary_key=True)
TranscriptId = Column(String, ForeignKey('')) # how to declare dynamic name?
AnalysisZ = Column(Integer)
parent = relationship('') # how to declare dynamic name?
def build_genome_table(genome, is_ref=False):
d = {'__tablename__': genome}
if is_ref is True:
table = type(genome, (Genome,), d)
else:
table = type(genome, (AlignedGenome,), d)
return table
父和子表都通过TranscriptId
关键,这是一个一对多的关系关联:许多AlignmentId
s的一个TranscriptId
相关。