Re: [Sqlalchemy-tickets] [sqlalchemy] #2875: attempt to improve the system by which engine_from_con
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2013-11-26 00:19:11
|
#2875: attempt to improve the system by which engine_from_config locates keys w/
special values
------------------------------+----------------------------------
Reporter: zzzeek | Owner: zzzeek
Type: enhancement | Status: new
Priority: high | Milestone: 0.9.0
Component: engine | Severity: minor - half an hour
Resolution: | Keywords:
Progress State: in queue |
------------------------------+----------------------------------
Comment (by zzzeek):
add it to the default strategy once we have the dialect class:
{{{
#!diff
diff --git a/lib/sqlalchemy/engine/__init__.py
b/lib/sqlalchemy/engine/__init__.py
index 16d2141..128c4e8 100644
--- a/lib/sqlalchemy/engine/__init__.py
+++ b/lib/sqlalchemy/engine/__init__.py
@@ -348,10 +348,13 @@ def engine_from_config(configuration,
prefix='sqlalchemy.', **kwargs):
arguments.
"""
- opts = util._coerce_config(configuration, prefix)
- opts.update(kwargs)
- url = opts.pop('url')
- return create_engine(url, **opts)
+ options = dict((key[len(prefix):], configuration[key])
+ for key in configuration
+ if key.startswith(prefix))
+ options['_coerce_config'] = True
+ options.update(kwargs)
+ url = options.pop('url')
+ return create_engine(url, **options)
__all__ = (
diff --git a/lib/sqlalchemy/engine/default.py
b/lib/sqlalchemy/engine/default.py
index 8fb7c3b..007a3ab 100644
--- a/lib/sqlalchemy/engine/default.py
+++ b/lib/sqlalchemy/engine/default.py
@@ -59,6 +59,18 @@ class DefaultDialect(interfaces.Dialect):
supports_simple_order_by_label = True
+ engine_config_types = dict([
+ ('convert_unicode', util.bool_or_str('force')),
+ ('pool_timeout', int),
+ ('echo', util.bool_or_str('debug')),
+ ('echo_pool', util.bool_or_str('debug')),
+ ('pool_recycle', int),
+ ('pool_size', int),
+ ('max_overflow', int),
+ ('pool_threadlocal', bool),
+ ('use_native_unicode', bool),
+ ])
+
# if the NUMERIC type
# returns decimal.Decimal.
# *not* the FLOAT type however.
diff --git a/lib/sqlalchemy/engine/strategies.py
b/lib/sqlalchemy/engine/strategies.py
index ab9d370..aea2fc3 100644
--- a/lib/sqlalchemy/engine/strategies.py
+++ b/lib/sqlalchemy/engine/strategies.py
@@ -49,11 +49,16 @@ class DefaultEngineStrategy(EngineStrategy):
dialect_cls = u.get_dialect()
+ coerce_config = kwargs.pop('_coerce_config', False)
+
dialect_args = {}
# consume dialect arguments from kwargs
for k in util.get_cls_kwargs(dialect_cls):
if k in kwargs:
- dialect_args[k] = kwargs.pop(k)
+ value = kwargs.pop(k)
+ if coerce_config and k in
dialect_cls.engine_config_types:
+ value = dialect_cls.engine_config_types[k](value)
+ dialect_args[k] = value
dbapi = kwargs.pop('module', None)
if dbapi is None:
}}}
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2875#comment:1>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|