Skip to content

Commit

Permalink
added string-based URLS to create connections
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzeek committed Dec 3, 2005
1 parent 07d4a9c commit 0f42441
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 9 additions & 1 deletion lib/sqlalchemy/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down
10 changes: 6 additions & 4 deletions test/testbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 0f42441

Please sign in to comment.