Permalink
Browse files

Adding SQLALCHEMY_CONNECT_ARGS

  • Loading branch information...
1 parent 087c3c0 commit 296e0a9c9db62ae5f3a7bc26b335af9503ba6072 @ajford committed Apr 14, 2012
Showing with 12 additions and 1 deletion.
  1. +2 −0 docs/config.rst
  2. +10 −1 flask_sqlalchemy.py
View
@@ -20,6 +20,8 @@ A list of configuration keys currently understood by the extension:
- ``sqlite:////tmp/test.db``
- ``mysql://username:password@server/db``
+``SQLALCHEMY_CONNECT_ARGS`` A dictionary passed to `connect_args` in
+ :func:`create_engine`.
``SQLALCHEMY_BINDS`` A dictionary that maps bind keys to
SQLAlchemy connection URIs. For more
information about binds see :ref:`binds`.
View
@@ -426,9 +426,14 @@ def get_uri(self):
'configuration variable' % self._bind
return binds[self._bind]
+ def get_connect_args(self):
+ if self._bind is None:
+ return self._app.config.get('SQLALCHEMY_CONNECT_ARGS',None)
+
def get_engine(self):
with self._lock:
uri = self.get_uri()
+ connect_args = self.get_connect_args()
echo = self._app.config['SQLALCHEMY_ECHO']
if (uri, echo) == self._connected_for:
return self._engine
@@ -440,7 +445,11 @@ def get_engine(self):
options['proxy'] = _ConnectionDebugProxy(self._app.import_name)
if echo:
options['echo'] = True
- self._engine = rv = sqlalchemy.create_engine(info, **options)
+ if connect_args:
+ self._engine = rv = sqlalchemy.create_engine(info,
+ connect_args=connect_args, **options)
+ else:
+ self._engine = rv = sqlalchemy.create_engine(info, **options)
self._connected_for = (uri, echo)
return rv

0 comments on commit 296e0a9

Please sign in to comment.