def setUpAll(self): sqlalchemy.clear_mappers() objectstore.clear() global Person, Preferences, Address class Person(ActiveMapper): class mapping: __version_id_col__ = 'row_version' full_name = column(String) first_name = column(String) middle_name = column(String) last_name = column(String) birth_date = column(DateTime) ssn = column(String) gender = column(String) home_phone = column(String) cell_phone = column(String) work_phone = column(String) row_version = column(Integer, default=0) prefs_id = column(Integer, foreign_key=ForeignKey('preferences.id')) addresses = one_to_many('Address', colname='person_id', backref='person', order_by=['state', 'city', 'postal_code']) preferences = one_to_one('Preferences', colname='pref_id', backref='person') def __str__(self): s = '%s\n' % self.full_name s += ' * birthdate: %s\n' % (self.birth_date or 'not provided') s += ' * fave color: %s\n' % (self.preferences.favorite_color or 'Unknown') s += ' * personality: %s\n' % (self.preferences.personality_type or 'Unknown') for address in self.addresses: s += ' * address: %s\n' % address.address_1 s += ' %s, %s %s\n' % (address.city, address.state, address.postal_code) return s class Preferences(ActiveMapper): class mapping: __table__ = 'preferences' favorite_color = column(String) personality_type = column(String) class Address(ActiveMapper): class mapping: # note that in other objects, the 'id' primary key is # automatically added -- if you specify a primary key, # then ActiveMapper will not add an integer primary key # for you. id = column(Integer, primary_key=True) type = column(String) address_1 = column(String) city = column(String) state = column(String) postal_code = column(String) person_id = column(Integer, foreign_key=ForeignKey('person.id')) activemapper.metadata.connect(testbase.db) activemapper.create_tables()
def setUpAll(self): sqlalchemy.clear_mappers() objectstore.clear() global TreeNode class TreeNode(activemapper.ActiveMapper): class mapping: id = column(Integer, primary_key=True) name = column(String(30)) parent_id = column(Integer, foreign_key=ForeignKey('treenode.id')) children = one_to_many('TreeNode', colname='id', backref='parent') activemapper.metadata.connect(testbase.db) activemapper.create_tables()
def setUpAll(self): sqlalchemy.clear_mappers() objectstore.clear() global secondarytable, foo, baz secondarytable = Table("secondarytable", activemapper.metadata, Column("foo_id", Integer, ForeignKey("foo.id"),primary_key=True), Column("baz_id", Integer, ForeignKey("baz.id"),primary_key=True)) class foo(activemapper.ActiveMapper): class mapping: name = column(String(30)) # bazrel = many_to_many('baz', secondarytable, backref='foorel') class baz(activemapper.ActiveMapper): class mapping: name = column(String(30)) foorel = many_to_many("foo", secondarytable, backref='bazrel') activemapper.metadata.connect(testbase.db) activemapper.create_tables()
def setUpAll(self): sqlalchemy.clear_mappers() objectstore.clear() global secondarytable, foo, baz secondarytable = Table( "secondarytable", activemapper.metadata, Column("foo_id", Integer, ForeignKey("foo.id"), primary_key=True), Column("baz_id", Integer, ForeignKey("baz.id"), primary_key=True)) class foo(activemapper.ActiveMapper): class mapping: name = column(String(30)) # bazrel = many_to_many('baz', secondarytable, backref='foorel') class baz(activemapper.ActiveMapper): class mapping: name = column(String(30)) foorel = many_to_many("foo", secondarytable, backref='bazrel') activemapper.metadata.connect(testbase.db) activemapper.create_tables()
def tearDownAll(self): clear_mappers() activemapper.drop_tables()
def tearDownAll(self): clear_mappers() activemapper.drop_tables() objectstore.clear()
def setUpAll(self): sqlalchemy.clear_mappers() objectstore.clear() global Person, Preferences, Address class Person(ActiveMapper): class mapping: __version_id_col__ = 'row_version' full_name = column(String) first_name = column(String) middle_name = column(String) last_name = column(String) birth_date = column(DateTime) ssn = column(String) gender = column(String) home_phone = column(String) cell_phone = column(String) work_phone = column(String) row_version = column(Integer, default=0) prefs_id = column(Integer, foreign_key=ForeignKey('preferences.id')) addresses = one_to_many( 'Address', colname='person_id', backref='person', order_by=['state', 'city', 'postal_code']) preferences = one_to_one('Preferences', colname='pref_id', backref='person') def __str__(self): s = '%s\n' % self.full_name s += ' * birthdate: %s\n' % (self.birth_date or 'not provided') s += ' * fave color: %s\n' % (self.preferences.favorite_color or 'Unknown') s += ' * personality: %s\n' % ( self.preferences.personality_type or 'Unknown') for address in self.addresses: s += ' * address: %s\n' % address.address_1 s += ' %s, %s %s\n' % ( address.city, address.state, address.postal_code) return s class Preferences(ActiveMapper): class mapping: __table__ = 'preferences' favorite_color = column(String) personality_type = column(String) class Address(ActiveMapper): class mapping: # note that in other objects, the 'id' primary key is # automatically added -- if you specify a primary key, # then ActiveMapper will not add an integer primary key # for you. id = column(Integer, primary_key=True) type = column(String) address_1 = column(String) city = column(String) state = column(String) postal_code = column(String) person_id = column(Integer, foreign_key=ForeignKey('person.id')) activemapper.metadata.connect(testbase.db) activemapper.create_tables()
def sqlalchemy_cleanup(): database._engine = None sqlalchemy.clear_mappers() database.metadata.clear() database.metadata.dispose()