[Checkins] SVN: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/ - Wrapper
constructor now accepts two new optional dicts
Andreas Jung
andreas at andreas-jung.com
Mon Jan 7 10:20:52 EST 2008
Log message for revision 82730:
- Wrapper constructor now accepts two new optional dicts
'engine_options' and 'session_options' that will be passed down
to the engine and the sessionmaker. Support for the generic
**kw argument has been dropped (might raise a backward
compatibility problem). Patch provided by Klaus Barthelmann.
Changed:
U z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/CHANGES.txt
U z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/base.py
U z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/util.py
-=-
Modified: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/CHANGES.txt
===================================================================
--- z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/CHANGES.txt 2008-01-07 15:13:36 UTC (rev 82729)
+++ z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/CHANGES.txt 2008-01-07 15:20:52 UTC (rev 82730)
@@ -20,6 +20,12 @@
session related modifications should happen within the same
transaction.
+ - Wrapper constructor now accepts two new optional dicts
+ 'engine_options' and 'session_options' that will be passed down
+ to the engine and the sessionmaker. Support for the generic
+ **kw argument has been dropped (might raise a backward
+ compatibility problem). Patch provided by Klaus Barthelmann.
+
1.0.11 (30.07.2007)
-------------------
Modified: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/base.py
===================================================================
--- z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/base.py 2008-01-07 15:13:36 UTC (rev 82729)
+++ z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/base.py 2008-01-07 15:20:52 UTC (rev 82730)
@@ -54,13 +54,17 @@
implements(ISQLAlchemyWrapper)
- def __init__(self, dsn, model=None, transactional=True, **kw):
+ def __init__(self, dsn, model=None, transactional=True, echo=False, engine_options=None, session_options=None):
""" 'dsn' - a RFC-1738-style connection string
'model' - optional instance of model.Model
- 'kw' - optional keyword arguments passed to create_engine()
+ 'echo' - boolean controlling the verbosity of the engine
+ 'engine_options' - optional keyword arguments passed to create_engine()
+
+ 'session_options' - optional keyword arguments passed to create_session() or sessionmaker()
+
'transactional' - True|False, only used by SQLAlchemyDA,
*don't touch it*
"""
@@ -74,8 +78,9 @@
self.dbname = self.url.database
self.drivername = self.url.drivername
self.transactional = transactional
- self.kw = kw
- self.echo = kw.get('echo', False)
+ self.engine_options = engine_options or {}
+ self.session_options = session_options or {}
+ self.echo = echo
self._model = None
self._createEngine()
self._id = str(random.random()) # used as unique key for session/connection cache
@@ -140,12 +145,11 @@
return self._model
def _createEngine(self):
- self._engine = sqlalchemy.create_engine(self.dsn, **self.kw)
- self._engine.echo = self.echo
+ self._engine = sqlalchemy.create_engine(self.dsn, **self.engine_options)
self._sessionmaker = sqlalchemy.orm.sessionmaker(bind=self._engine,
autoflush=True,
transactional=True,
- **self.kw)
+ **self.session_options)
connection_cache = SynchronizedThreadCache()
Modified: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/util.py
===================================================================
--- z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/util.py 2008-01-07 15:13:36 UTC (rev 82729)
+++ z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/util.py 2008-01-07 15:20:52 UTC (rev 82730)
@@ -28,7 +28,7 @@
registeredWrappers = {}
-def createSAWrapper(dsn, model=None, forZope=False, name=None, transactional=True, **kw):
+def createSAWrapper(dsn, model=None, forZope=False, name=None, transactional=True, engine_options=None, session_options=None):
""" Convenience method to generate a wrapper for a DSN and a model.
This method hides all database related magic from the user.
@@ -45,6 +45,12 @@
'name' can be set to register the wrapper automatically in order
to avoid a dedicated registerSAWrapper() call.
+
+ 'engine_options' can be set to a dict containing keyword parameters
+ passed to create_engine.
+
+ 'session_options' can be set to a dict containing keyword parameters
+ passed to create_session or sessionmaker.
"""
url = make_url(dsn)
@@ -55,7 +61,7 @@
if driver == 'postgres':
klass = forZope and ZopePostgresWrapper or PythonPostgresWrapper
- wrapper = klass(dsn, model, transactional, **kw)
+ wrapper = klass(dsn, model, transactional, engine_options, session_options)
if name is not None:
registerSAWrapper(wrapper, name)
More information about the Checkins
mailing list