summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-08-14 00:40:23 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-08-14 00:40:23 +0000
commit0285ec6beb695bf38ae5cccef8245e04fe5585a0 (patch)
treec35da2760042e2eae31e80a670e176ab83396362 /lib/sqlalchemy
parente623c179da241c1f2bfd8ed5eeeea898d803ab52 (diff)
downloadsqlalchemy-0285ec6beb695bf38ae5cccef8245e04fe5585a0.tar.gz
added engine_from_config() function for helping to create_engine()
from an .ini style config
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/__init__.py2
-rw-r--r--lib/sqlalchemy/engine/__init__.py28
-rw-r--r--lib/sqlalchemy/engine/url.py12
3 files changed, 40 insertions, 2 deletions
diff --git a/lib/sqlalchemy/__init__.py b/lib/sqlalchemy/__init__.py
index ab12ecf4b..bdd3604de 100644
--- a/lib/sqlalchemy/__init__.py
+++ b/lib/sqlalchemy/__init__.py
@@ -7,7 +7,7 @@
from sqlalchemy.types import *
from sqlalchemy.sql import *
from sqlalchemy.schema import *
-from sqlalchemy.engine import create_engine
+from sqlalchemy.engine import create_engine, engine_from_config
__version__ = 'svn'
diff --git a/lib/sqlalchemy/engine/__init__.py b/lib/sqlalchemy/engine/__init__.py
index 2ef163c03..acac8180c 100644
--- a/lib/sqlalchemy/engine/__init__.py
+++ b/lib/sqlalchemy/engine/__init__.py
@@ -48,6 +48,7 @@ The package is represented among several individual modules, including:
import sqlalchemy.databases
from sqlalchemy.engine.base import *
from sqlalchemy.engine import strategies
+from sqlalchemy import util
def engine_descriptors():
"""Provide a listing of all the database implementations supported.
@@ -151,3 +152,30 @@ def create_engine(*args, **kwargs):
strategy = kwargs.pop('strategy', default_strategy)
strategy = strategies.strategies[strategy]
return strategy.create(*args, **kwargs)
+
+def engine_from_config(configuration, prefix='sqlalchemy.', **kwargs):
+ """Create a new Engine instance using a configuration dictionary.
+
+ the dictionary is typically produced from a config file where keys are prefixed,
+ such as sqlalchemy.url, sqlalchemy.echo, etc. The 'prefix' argument indicates
+ the prefix to be searched for.
+
+ A select set of keyword arguments will be "coerced" to their expected type based on
+ string values. in a future release, this functionality will be expanded to include
+ dialect-specific arguments.
+ """
+
+ opts = dict([(key[len(prefix):], configuration[key]) for key in configuration if key.startswith(prefix)])
+ for opt, type_ in (
+ ('convert_unicode', bool),
+ ('pool_timeout', int),
+ ('echo', bool),
+ ('echo_pool', bool),
+ ('pool_recycle', int),
+ ):
+ util.coerce_kw_type(opts, opt, type_)
+ opts.update(kwargs)
+ url = opts.pop('url')
+ return create_engine(url, **opts)
+
+ \ No newline at end of file
diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py
index 98d4d442e..31546bae8 100644
--- a/lib/sqlalchemy/engine/url.py
+++ b/lib/sqlalchemy/engine/url.py
@@ -66,7 +66,17 @@ class URL(object):
keys.sort()
s += '?' + "&".join(["%s=%s" % (k, self.query[k]) for k in keys])
return s
-
+
+ def __eq__(self, other):
+ return \
+ isinstance(other, URL) and \
+ self.drivername == other.drivername and \
+ self.username == other.username and \
+ self.password == other.password and \
+ self.host == other.host and \
+ self.database == other.database and \
+ self.query == other.query
+
def get_dialect(self):
"""Return the SQLAlchemy database dialect class corresponding to this URL's driver name."""
dialect=None