From 72a02a6e9566abfdf74b77707fc6a8999ecdd419 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sat, 7 Mar 2009 12:45:24 +0100 Subject: [PATCH] do not unnecessarily close the database connection (fixes #20) --- pyalchemybiz/lib/base.py | 6 +----- pyalchemybiz/model/__init__.py | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/pyalchemybiz/lib/base.py b/pyalchemybiz/lib/base.py index 4bbaf27..1e7074a 100644 --- a/pyalchemybiz/lib/base.py +++ b/pyalchemybiz/lib/base.py @@ -11,10 +11,8 @@ from pylons.i18n import _, ungettext, N_, add_fallback, set_lang from pylons.templating import render import pyalchemybiz.lib.helpers as h -import pyalchemybiz.model as model from pyalchemybiz.model import meta -from sqlalchemy.orm import sessionmaker class BaseController(WSGIController): @@ -31,13 +29,11 @@ class BaseController(WSGIController): except: pass # connect to database - conn = meta.engine.connect() - meta.Session.configure(bind=conn) try: return WSGIController.__call__(self, environ, start_response) finally: meta.Session.remove() - conn.close() + # Include the '_' function in the public names __all__ = [__name for __name in locals().keys() if not __name.startswith('_') \ diff --git a/pyalchemybiz/model/__init__.py b/pyalchemybiz/model/__init__.py index 5ccbee3..7b12f5b 100644 --- a/pyalchemybiz/model/__init__.py +++ b/pyalchemybiz/model/__init__.py @@ -16,6 +16,7 @@ def init_model(engine): meta.engine = engine meta.Session = orm.scoped_session(sm) + person.t_person = sa.Table( 'person', meta.metadata, autoload=True, autoload_with=engine) customer.t_customer = sa.Table(