# Path: opentuner/resultsdb/models.py
# class Base(object):
#     @declared_attr
#     def __tablename__(cls):
#         """convert camel case to underscores"""
#         return re.sub(r'([a-z])([A-Z])', r'\1_\2', cls.__name__).lower()
# 
#     id = Column(Integer, primary_key=True, index=True)
# 
# class _Meta(Base):
#     """ meta table to track current version """
#     db_version = Column(String(128))
# 
#     @classmethod
#     def has_version(cls, session, version):
#         try:
#             session.flush()
#             session.query(_Meta).filter_by(db_version=version).one()
#             return True
#         except sqlalchemy.orm.exc.NoResultFound:
#             return False
# 
#     @classmethod
#     def get_version(cls, session):
#         try:
#             session.flush()
#             x = session.query(_Meta).one()
#             return x.db_version
#         except sqlalchemy.orm.exc.NoResultFound:
#             return None
# 
#     @classmethod
#     def add_version(cls, session, version):
#         if not cls.has_version(session, version):
#             session.add(_Meta(db_version=version))


import logging
import time
    import atexit
from pprint import pprint
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from .models import Base, _Meta
    from sqlalchemy import event
    from collections import Counter
    from sqlalchemy.engine import Engine
from __future__ import absolute_import




log = logging.getLogger(__name__)

DB_VERSION = "0.0"

if False:  # profiling of queries

    the_query_totals = Counter()


    @event.listens_for(Engine, "before_cursor_execute")
    def before_cursor_execute(conn, cursor, statement,
                              parameters, context, executemany):

# Path: opentuner/resultsdb/models.py
# class Base(object):
#     @declared_attr
#     def __tablename__(cls):
#         """convert camel case to underscores"""
#         return re.sub(r'([a-z])([A-Z])', r'\1_\2', cls.__name__).lower()
# 
#     id = Column(Integer, primary_key=True, index=True)
# 
# class _Meta(Base):
#     """ meta table to track current version """
#     db_version = Column(String(128))
# 
#     @classmethod
#     def has_version(cls, session, version):
#         try:
#             session.flush()
#             session.query(_Meta).filter_by(db_version=version).one()
#             return True
#         except sqlalchemy.orm.exc.NoResultFound:
#             return False
# 
#     @classmethod
#     def get_version(cls, session):
#         try:
#             session.flush()
#             x = session.query(_Meta).one()
#             return x.db_version
#         except sqlalchemy.orm.exc.NoResultFound:
#             return None
# 
#     @classmethod
#     def add_version(cls, session, version):
#         if not cls.has_version(session, version):
#             session.add(_Meta(db_version=version))


# Path: opentuner/resultsdb/connect.py
import logging
import time
    import atexit
from pprint import pprint
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from .models import Base, _Meta
    from sqlalchemy import event
    from collections import Counter
    from sqlalchemy.engine import Engine

from __future__ import absolute_import




log = logging.getLogger(__name__)

DB_VERSION = "0.0"

if False:  # profiling of queries

    the_query_totals = Counter()


    @event.listens_for(Engine, "before_cursor_execute")
    def before_cursor_execute(conn, cursor, statement,
                              parameters, context, executemany):

        context._query_start_time = time.time()