The question is probably very simple, but I can't find an answer anywhere...
Suppose I already have some tables declarad in a declarative way, as
below, how do I create the database schema from them?
I usually always did with the
meta.create_all() after defining the various "Table('name', meta...)"
in this way it should be even easier but I can't find the magic instruction..
class TestStatus(Base):
__tablename__ = 'TestStatus'
id = Column(String, primary_key=True)
done = Column(Boolean, default=False)
def __init__(self, testid):
self.testid = testid
class AreaTests(Base):
__tablename__ = 'AreaTests'
area = Column(String, primary_key=True)
test = Column(String, ForeignKey('TestStatus.id'))
def __init__(self, area, test):
self.area = area
self.test = test
class Results:
"""Keep track of the results of the test that have been run, using
an temporary sqlite database to store
"""
def __init__(self):
db_path = 'sqlite:///%s' % SQLITE_TEMP
eng = create_engine(db_path)
meta = MetaData(bind=eng)
# must first create the schema if not present already
self.session = sessionmaker(bind=eng)()
def add_area(self, area, testid):
"""Add an area and a testid to this simple database
"""
test_obj = TestStatus(testid)
if test_obj not in self.session:
self.session.add(test_obj)
self.session.add(AreaTests(area, testid))
self.session.commit()
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.