--- /dev/null
+from sqlalchemy.orm import scoped_session, sessionmaker
+
+
+Session = scoped_session(sessionmaker())
+
+
+class GMGTableBase(object):
+ query = Session.query_property()
+
+ @classmethod
+ def find(cls, query_dict={}):
+ return cls.query.filter_by(**query_dict)
+
+ @classmethod
+ def find_one(cls, query_dict={}):
+ return cls.query.filter_by(**query_dict).first()
from mediagoblin.db.sql.models import (Base, User, MediaEntry, MediaComment,
Tag, MediaTag)
-Session = sessionmaker()
+# Session = sessionmaker()
+from mediagoblin.db.sql.base import Session
obj_id_table = dict()
Base.metadata.create_all(engine)
convert_users(mk_db)
+ Session.remove()
convert_media_entries(mk_db)
+ Session.remove()
convert_media_tags(mk_db)
+ Session.remove()
convert_media_comments(mk_db)
+ Session.remove()
if __name__ == '__main__':
Column, Integer, Unicode, UnicodeText, DateTime, Boolean, ForeignKey,
UniqueConstraint)
+from mediagoblin.db.sql.base import GMGTableBase
-Base = declarative_base()
+
+Base = declarative_base(cls=GMGTableBase)
class User(Base):
--- /dev/null
+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)