Permalink
Browse files

added string-based URLS to create connections

  • Loading branch information...
zzzeek committed Dec 3, 2005
1 parent 07d4a9c commit 0f42441edd8269308ec1b3c9936759a289dee826
Showing with 15 additions and 5 deletions.
  1. +9 −1 lib/sqlalchemy/engine.py
  2. +6 −4 test/testbase.py
View
@@ -22,7 +22,7 @@
import sqlalchemy.pool
import sqlalchemy.util as util
import sqlalchemy.sql as sql
-import StringIO, sys
+import StringIO, sys, re
import sqlalchemy.types as types
import sqlalchemy.databases
@@ -36,6 +36,14 @@ def create_engine(name, *args ,**kwargs):
*args, **kwargs - sent directly to the specific engine instance as connect arguments,
options.
"""
+ m = re.match(r'(\w+)://(.*)', name)
+ if m is not None:
+ (name, args) = m.group(1, 2)
+ opts = {}
+ def assign(m):
+ opts[m.group(1)] = m.group(2)
+ re.sub(r'([^&]+)=([^&]*)', assign, args)
+ args = [opts]
module = getattr(__import__('sqlalchemy.databases.%s' % name).databases, name)
return module.engine(*args, **kwargs)
View
@@ -163,13 +163,15 @@ def __exc_info(self):
raise "--db <sqlite|postgres|oracle|sqlite_file> param required"
if DBTYPE == 'sqlite':
- db = engine.create_engine('sqlite', {'filename':':memory:'}, echo = echo)
+ db = engine.create_engine('sqlite://filename=:memory:', echo = echo)
elif DBTYPE == 'sqlite_file':
- db = engine.create_engine('sqlite', {'filename':'querytest.db'}, echo = echo)
+ db = engine.create_engine('sqlite://filename=querytest.db', echo = echo)
elif DBTYPE == 'postgres':
- db = engine.create_engine('postgres', {'database':'test', 'host':'127.0.0.1', 'user':'scott', 'password':'tiger'}, echo=echo)
+ db = engine.create_engine('postgres://database=test&host=127.0.0.1&user=scott&password=tiger', echo=echo)
elif DBTYPE == 'mysql':
- db = engine.create_engine('mysql', {'db':'test', 'host':'127.0.0.1', 'user':'scott', 'passwd':'tiger'}, echo=echo)
+ db = engine.create_engine('mysql://db=test&host=127.0.0.1&user=scott&passwd=tiger', echo=echo)
+elif DBTYPE == 'oracle':
+ db = engine.create_engine('oracle://db=test&host=127.0.0.1&user=scott&passwd=tiger', echo=echo)
db = EngineAssert(db)

0 comments on commit 0f42441

Please sign in to comment.