def test_table_singleton_a(self): """set up for table singleton check """ # # For this 'test', create a proxy engine instance, connect it # to a real engine, and make it do some work # engine = ProxyEngine() cats = Table('cats', engine, Column('cat_id', Integer, primary_key=True), Column('cat_name', String)) engine.connect(testbase.db_uri) cats.create(engine) cats.drop(engine) ProxyEngineTest2.cats_table_a = cats assert isinstance(cats, Table)
def test_table_singleton_b(self): """check that a table on a 2nd proxy engine instance gets 2nd table instance """ # # Now create a new proxy engine instance and attach the same # table as the first test. This should result in 2 table instances, # since different proxy engine instances can't attach to the # same table instance # engine = ProxyEngine() cats = Table('cats', engine, Column('cat_id', Integer, primary_key=True), Column('cat_name', String)) assert id(cats) != id(ProxyEngineTest2.cats_table_a) # the real test -- if we're still using the old engine reference, # this will fail because the old reference's local storage will # not have the default attributes engine.connect(testbase.db_uri) cats.create(engine) cats.drop(engine)
def setUpAll(self): global users, User, module_engine, module_metadata module_engine = ProxyEngine(echo=testbase.echo) module_metadata = MetaData() users = Table('users', module_metadata, Column('user_id', Integer, primary_key=True), Column('user_name', String(16)), Column('password', String(20))) class User(object): pass User.mapper = mapper(User, users)
def test_join(self): engine = ProxyEngine() t = Table('table1', engine, Column('col1', Integer, primary_key=True)) t2 = Table('table2', engine, Column('col2', Integer, ForeignKey('table1.col1'))) j = join(t, t2)
from sqlalchemy import objectstore, create_engine, assign_mapper, relation, mapper from sqlalchemy import and_, or_ from sqlalchemy import Table, Column from sqlalchemy.ext.proxy import ProxyEngine import inspect # # the "proxy" to the database engine... this can be swapped out at runtime # engine = ProxyEngine() # # declarative column declaration - this is so that we can infer the colname # class column(object): def __init__(self, coltype, colname=None, foreign_key=None, primary_key=False): self.coltype = coltype self.colname = colname self.foreign_key = foreign_key self.primary_key = primary_key # # declarative relationship declaration #