Mercurial > pylearn
changeset 622:d2d582bcf7dc
api0 and sql seem to work with session closing
author | James Bergstra <bergstrj@iro.umontreal.ca> |
---|---|
date | Sun, 18 Jan 2009 21:39:28 -0500 |
parents | 7041749cf804 |
children | ae954c27fd11 |
files | pylearn/dbdict/api0.py pylearn/dbdict/sql.py |
diffstat | 2 files changed, 14 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/pylearn/dbdict/api0.py Sun Jan 18 21:14:14 2009 -0500 +++ b/pylearn/dbdict/api0.py Sun Jan 18 21:39:28 2009 -0500 @@ -408,7 +408,7 @@ def __iter__(h_self): return h_self.query.__iter__() - def insert_kwargs(h_self, **dct): + def insert_kwargs(h_self, session=None, **dct): """ @rtype: DbHandle with reference to self @return: a DbHandle initialized as a copy of dct @@ -419,10 +419,9 @@ @param dct: dictionary to insert """ - rval = h_self._Dict() - if dct: rval.update(dct) - return rval - def insert(h_self, dct): + return h_self.insert(dct, session=session) + + def insert(h_self, dct, session=None): """ @rtype: DbHandle with reference to self @return: a DbHandle initialized as a copy of dct @@ -433,8 +432,15 @@ @param dct: dictionary to insert """ - rval = h_self._Dict() - if dct: rval.update(dct) + if session is None: + s = h_self.session() + rval = h_self._Dict(s) + if dct: rval.update(dct, session=s) + s.commit() + s.close() + else: + rval = h_self._Dict(session) + if dct: rval.update(dct, session=session) return rval def query(h_self, session): @@ -555,7 +561,7 @@ """ db_str ='postgres://%(user)s:%(password)s@%(host)s/%(database)s' % locals() - engine = create_engine(db_str, pool_size=pool_size, echo=echo, poolclass=poolclass) + engine = create_engine(db_str, echo=echo, poolclass=poolclass) return db_from_engine(engine, **kwargs)
--- a/pylearn/dbdict/sql.py Sun Jan 18 21:14:14 2009 -0500 +++ b/pylearn/dbdict/sql.py Sun Jan 18 21:39:28 2009 -0500 @@ -44,7 +44,6 @@ c = psycopg2.connect(user=user, password=password, database=database, host=host) c.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE) return c - pool_size = 0 this.engine = create_engine('postgres://' ,creator=connect ,poolclass=poolclass