Michael Bayer wrote: > On Feb 4, 2008, at 8:34 PM, braydon fuller wrote: > >> >> >> This is the wrong way to go about insuring >> that there is a DB connection. I'd like to know the correct way. >> Would this be to test the database, and if that fails to open a >> connection? >> > > > well I dont know cherrypy so i dont see anything familiar to me there. > but as far as SA is concerned, it would like you to create a single > engine just once in your application. after that you dont need to > worry about ensuring the DB is connected, it takes care of it for you. > > > > I have a Borg that has the db connection and session in it. Do I need to reconnect the connection or close and open a new session for a long running web app?
Below is the Class i'm using: class Database(object): db = get_database(settings.database) def __init__(self): self.engine = Database.db.engine self.connection = Database.db.connection self.session = Database.db.session def create_all(self): metadata.create_all(self.engine) def start_engine(self): Database.db = get_database(settings.database) class DB(object): def __init__(self, engine=None, connection=None, session=None): self.engine = engine self.connection = connection self.session = session def get_database(info): info = info info_list = [] info_list.append(info.database) info_list.append("://") info_list.append(info.user) info_list.append(":") info_list.append(info.password) info_list.append("@") info_list.append(info.host) info_list.append(":") info_list.append(info.port) info_list.append("/") info_list.append(info.database_name) """info_list.append("pool_recycle=3600, pool_timeout=30, max_overflow=10, pool_size=5")""" info_url_list = [] for info in info_list: info_url_list.append(info.replace('\"','')) info_url = "".join(info_url_list) db = DB() db.engine = create_engine(info_url) db.connection = db.engine.connect() Session = sessionmaker(bind=db.connection) db.session = Session() return db --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---