我有多个星型模式格式的相关表,如下所示:
FACT TABLE
==========
id (primary key)
globalattribute1
globalattribute2
DIMENSION TABLE 1
==========
id (foreign key to fact_table.id)
specificattribute1
specificatrribute2
DIMENSION TABLE 2
==========
id (foreign key to fact_table.id)
specificattribute1
specificatrribute2
这是我迄今为止在我的 Python 代码中的内容(除了 Base, session 。你能提供任何建议吗?
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import *
engine = create_engine('mysql://...')
Session = sessionmaker(bind=engine)
session = Session()
Base = declarative_base()
class Fact(Base):
__tablename__ = 'fact_table'
id = Column(Integer, primary_key=True)
global1 = Column(String(255))
global2 = Column(String(255))
#Constructor
class Dimension1(Base):
__tablename__ = 'dimension1'
id = Column(Integer, ForeignKey('fact_table.id'))
specific1 = Column(String(255))
specific2 = Column(String(255))
#Constructor
class Dimension2(Base):
__tablename__ = 'dimension2'
id = Column(Integer, ForeignKey('fact_table.id'))
specific1 = Column(String(255))
specific2 = Column(String(255))
#Constructor
Base.metadata.create_all(engine)
我如何使用它来插入一条记录,该记录将包含一个维度表的全局属性和特定属性?