diff options
author | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2011-12-18 17:02:27 +0100 |
---|---|---|
committer | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2011-12-18 17:07:15 +0100 |
commit | 7b194a79f0ad789309b9c34340f19c5a962b0915 (patch) | |
tree | 9e15c72304d867bbe273e46d834af93fc181617d /mediagoblin/db/sql/open.py | |
parent | 18517e888a90bf1c0434dd4da99ef7980d333ed0 (diff) | |
download | mediagoblin-7b194a79f0ad789309b9c34340f19c5a962b0915.tar.lz mediagoblin-7b194a79f0ad789309b9c34340f19c5a962b0915.tar.xz mediagoblin-7b194a79f0ad789309b9c34340f19c5a962b0915.zip |
SQL: mongokit like interface
In trying to ease the migration to SQL, created an
interface to sqlalchemy that looks a lot like the interface
that is currently in use.
*WARNING* Work in progress
Diffstat (limited to 'mediagoblin/db/sql/open.py')
-rw-r--r-- | mediagoblin/db/sql/open.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/mediagoblin/db/sql/open.py b/mediagoblin/db/sql/open.py new file mode 100644 index 00000000..57feaf50 --- /dev/null +++ b/mediagoblin/db/sql/open.py @@ -0,0 +1,29 @@ +from sqlalchemy import create_engine + +from mediagoblin.db.sql.base import Session +from mediagoblin.db.sql.models import Base + + +class DatabaseMaster(object): + def __init__(self, engine): + self.engine = engine + + for k,v in Base._decl_class_registry.iteritems(): + setattr(self, k, v) + + def commit(self): + Session.commit() + + def save(self, obj): + Session.add(obj) + Session.flush() + + def reset_after_request(self): + Session.remove() + + +def setup_connection_and_db_from_config(app_config): + engine = create_engine(app_config['sql_engine'], echo=True) + Session.configure(bind=engine) + + return "dummy conn", DatabaseMaster(engine) |