I have multiple related tables in a star-schema format that look like the following:
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
Here's what I have so far in my Python code (in addition to the Base, session . Can you offer any suggestions on this?
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)
How do I use this to insert one record that would contain both global attirbutes and specific attributes for one of the dimension tables?