def __init__(self, timeout): global visit_class visit_class_path = config.get("tools.visit.saprovider.model", "gearshift.visit.savisit.TG_Visit") visit_class = load_class(visit_class_path) if visit_class is None: msg = 'No visit class found for %s' % visit_class_path msg += ', did you run setup.py develop?' log.error(msg) bind_metadata() if visit_class is TG_Visit: mapper(visit_class, visits_table) # base-class' __init__ triggers self.create_model, so mappers need to # be initialized before. super(SqlAlchemyVisitManager, self).__init__(timeout)
def setup_module(): global users_table, test_table, multi_table, fresh_multi_table config.update({ 'sqlalchemy.dburi': 'sqlite:///:memory:', 'fresh.dburi': 'sqlite:///freshtest.db', }) if os.path.exists('freshtest.db'): os.unlink('freshtest.db') fresh_metadata = get_metadata('fresh') if metadata.is_bound(): metadata.bind = None bind_metadata() metadata.bind.echo = True fresh_metadata.bind.echo = True users_table = Table("users", metadata, Column("user_id", Integer, primary_key=True), Column("user_name", String(40)), Column("password", String(10))) persons_table = Table("persons", metadata, Column("id", Integer, primary_key=True), Column("name", String(40))) addresses_table = Table("addresses", metadata, Column("id", Integer, primary_key=True), Column("address", String(40)), Column("city", String(40)), Column("person_id", Integer, ForeignKey(persons_table.c.id))) multi_table = Table('multi', metadata, Column('id', Integer, primary_key=True)) metadata.create_all() test_table = Table("test", fresh_metadata, Column("id", Integer, primary_key=True), Column("val", String(40))) fresh_multi_table = Table('multi', fresh_metadata, Column('id', Integer, primary_key=True)) fresh_metadata.create_all() mapper(User, users_table) mapper(Person, persons_table) mapper(Address, addresses_table, properties=dict( person=relation(Person, backref='addresses'))) mapper(Test, test_table) start_server()
def create_tables(): """Create tables filled with test data.""" occupations_table = Table('occupations', metadata, Column('id', Integer, primary_key=True), Column('name', String(20))) users_table = Table( 'users', metadata, Column('id', Integer, primary_key=True), Column('name', String(20)), Column('occupation_id', Integer, ForeignKey("occupations.id"))) addresses_table = Table('addresses', metadata, Column('id', Integer, primary_key=True), Column('user_id', Integer, ForeignKey("users.id")), Column('street', String(50)), Column('city', String(40))) mapper(Occupation, occupations_table) mapper(User, users_table, properties={ 'occupation': relation(Occupation, lazy=False), 'addresses': relation(Address, backref='user', lazy=False) }) mapper(Address, addresses_table) metadata.create_all() occupations = ({ 'id': 1, 'name': 'Doctor' }, { 'id': 2, 'name': 'Actor' }, { 'id': 3, 'name': 'Programmer' }) users = ({ 'id': 1, 'name': 'Smith', 'occupation_id': 1 }, { 'id': 2, 'name': 'John', 'occupation_id': 2 }, { 'id': 3, 'name': 'Fred', 'occupation_id': 2 }, { 'id': 4, 'name': 'Albert', 'occupation_id': 3 }, { 'id': 5, 'name': 'Nicole', 'occupation_id': None }, { 'id': 6, 'name': 'Sarah', 'occupation_id': None }, { 'id': 7, 'name': 'Walter', 'occupation_id': 1 }, { 'id': 8, 'name': 'Bush', 'occupation_id': None }) addresses = ({ 'id': 1, 'user_id': None, 'street': 'street P', 'city': 'city X' }, { 'id': 2, 'user_id': 2, 'street': 'street B', 'city': 'city Z' }, { 'id': 3, 'user_id': 4, 'street': 'street C', 'city': 'city X' }, { 'id': 4, 'user_id': 1, 'street': 'street D', 'city': 'city Y' }, { 'id': 5, 'user_id': None, 'street': 'street E', 'city': 'city Z' }, { 'id': 6, 'user_id': 1, 'street': 'street F', 'city': 'city Z' }, { 'id': 7, 'user_id': 3, 'street': 'street G', 'city': 'city Y' }, { 'id': 8, 'user_id': 7, 'street': 'street H', 'city': 'city Y' }, { 'id': 9, 'user_id': 1, 'street': 'street I', 'city': 'city X' }, { 'id': 10, 'user_id': 6, 'street': 'street J', 'city': 'city X' }, { 'id': 11, 'user_id': 3, 'street': 'street K', 'city': 'city Z' }, { 'id': 12, 'user_id': 2, 'street': 'street L', 'city': 'city X' }, { 'id': 13, 'user_id': 8, 'street': 'street M', 'city': 'city X' }, { 'id': 14, 'user_id': 5, 'street': 'street N', 'city': 'city Y' }, { 'id': 15, 'user_id': 1, 'street': 'street O', 'city': 'city Y' }, { 'id': 16, 'user_id': 3, 'street': 'street A', 'city': 'city X' }) metadata.bind.execute(occupations_table.insert(), occupations) metadata.bind.execute(users_table.insert(), users) metadata.bind.execute(addresses_table.insert(), addresses) SOAddress.createTable() # SQLObject tests will need only "addresses" for kw in addresses: print SOAddress(**kw)
def create_tables(): """Create tables filled with test data.""" occupations_table = Table('occupations', metadata, Column('id', Integer, primary_key=True), Column('name', String(20))) users_table = Table('users', metadata, Column('id', Integer, primary_key=True), Column('name', String(20)), Column('occupation_id', Integer, ForeignKey("occupations.id"))) addresses_table = Table('addresses', metadata, Column('id', Integer, primary_key=True), Column('user_id', Integer, ForeignKey("users.id")), Column('street', String(50)), Column('city', String(40))) mapper(Occupation, occupations_table) mapper(User, users_table, properties={ 'occupation' : relation(Occupation, lazy=False), 'addresses': relation(Address, backref='user', lazy=False)}) mapper(Address, addresses_table) metadata.create_all() occupations = ( {'id': 1, 'name': 'Doctor'}, {'id': 2, 'name': 'Actor'}, {'id': 3, 'name': 'Programmer'}) users = ( {'id': 1, 'name': 'Smith', 'occupation_id': 1}, {'id': 2, 'name': 'John', 'occupation_id': 2}, {'id': 3, 'name': 'Fred', 'occupation_id': 2}, {'id': 4, 'name': 'Albert', 'occupation_id': 3}, {'id': 5, 'name': 'Nicole', 'occupation_id': None}, {'id': 6, 'name': 'Sarah', 'occupation_id': None}, {'id': 7, 'name': 'Walter', 'occupation_id': 1}, {'id': 8, 'name': 'Bush', 'occupation_id': None}); addresses = ( {'id': 1, 'user_id': None, 'street': 'street P', 'city': 'city X'}, {'id': 2, 'user_id': 2, 'street': 'street B', 'city': 'city Z'}, {'id': 3, 'user_id': 4, 'street': 'street C', 'city': 'city X'}, {'id': 4, 'user_id': 1, 'street': 'street D', 'city': 'city Y'}, {'id': 5, 'user_id': None, 'street': 'street E', 'city': 'city Z'}, {'id': 6, 'user_id': 1, 'street': 'street F', 'city': 'city Z'}, {'id': 7, 'user_id': 3, 'street': 'street G', 'city': 'city Y'}, {'id': 8, 'user_id': 7, 'street': 'street H', 'city': 'city Y'}, {'id': 9, 'user_id': 1, 'street': 'street I', 'city': 'city X'}, {'id': 10, 'user_id': 6, 'street': 'street J', 'city': 'city X'}, {'id': 11, 'user_id': 3, 'street': 'street K', 'city': 'city Z'}, {'id': 12, 'user_id': 2, 'street': 'street L', 'city': 'city X'}, {'id': 13, 'user_id': 8, 'street': 'street M', 'city': 'city X'}, {'id': 14, 'user_id': 5, 'street': 'street N', 'city': 'city Y'}, {'id': 15, 'user_id': 1, 'street': 'street O', 'city': 'city Y'}, {'id': 16, 'user_id': 3, 'street': 'street A', 'city': 'city X'}); metadata.bind.execute(occupations_table.insert(), occupations) metadata.bind.execute(users_table.insert(), users) metadata.bind.execute(addresses_table.insert(), addresses) SOAddress.createTable() # SQLObject tests will need only "addresses" for kw in addresses: print SOAddress(**kw)
Column('id', Integer, primary_key=True), Column('name', Unicode, unique=True), ) tg_message_table = Table( 'tg_i18n_message', metadata, Column('id', Integer, primary_key=True), Column('name', Unicode), Column('text', Unicode, default=u""), Column('domain_id', Integer, ForeignKey(tg_domain_table.c.id)), Column('locale', String(length=15)), Column('created', DateTime, default=datetime.now), Column('updated', DateTime, default=None), ) class TG_Domain(object): pass class TG_Message(object): pass mapper(TG_Domain, tg_domain_table, properties=dict(messages=relation(TG_Message, backref='domain'))) mapper(TG_Message, tg_message_table, properties=dict())
tg_domain_table = Table('tg_i18n_domain', metadata, Column('id', Integer, primary_key=True), Column('name', Unicode, unique=True), ) tg_message_table = Table('tg_i18n_message', metadata, Column('id', Integer, primary_key=True), Column('name', Unicode), Column('text', Unicode, default=u""), Column('domain_id', Integer, ForeignKey(tg_domain_table.c.id)), Column('locale', String(length=15)), Column('created', DateTime, default=datetime.now), Column('updated', DateTime, default=None), ) class TG_Domain(object): pass class TG_Message(object): pass mapper(TG_Domain, tg_domain_table, properties=dict( messages=relation( TG_Message, backref='domain') )) mapper(TG_Message, tg_message_table, properties=dict())