def __init__(self, bus, url=None, map_file=None): plugins.SimplePlugin.__init__(self, bus) self.url = url self.dbm = DBManager() self.qbs = QueryBuilder() self.qbs.set_mapper(map_file) self.db_result = Results() self.con = None
def setUp(self): """default""" metadata = load_from_file("starting_db.yaml") app = QueryBuilder() app.set_mapper('testmap.yaml') app.set_from_tables(metadata.tables) app.recognize_schema() # without loading statistics self.app = app
class QueryBuilderBus(plugins.SimplePlugin): """ A WSPBus plugin that controls 1. a SQLAlchemy engine/connection pool. 2. a QueryBuilder """ def __init__(self, bus, url=None, map_file=None): plugins.SimplePlugin.__init__(self, bus) self.url = url self.dbm = DBManager() self.qbs = QueryBuilder() self.qbs.set_mapper(map_file) self.db_result = Results() self.con = None def start(self): """get db connection""" print 'Connecting to database ' self.con = self.dbm.connect(self.url) self.qbs.set_from_tables(self.dbm.load_tables( \ self.dbm.get_alias(self.url))) if self.dbm.db_type[self.dbm.get_alias(self.url)] == 'mysql': self.qbs.mapper.set_sens(True) self.qbs.recognize_schema(self.dbm, \ self.dbm.get_alias(self.url)) def stop(self): """close db connection""" self.con.close() self.con = None
def setUp(self): """initialize test sqlite db then metadata""" if os.path.exists('unittest.db'): os.unlink('unittest.db') test_db = UnittestDB() metadata = test_db.load_with_fake_data('oracle.sql', 'sqlite:///unittest.db') self.metadata = metadata app = QueryBuilder() app.set_mapper('map.yaml') app.set_from_tables(metadata.tables) app.recognize_schema() # without loading statistics self.app = app