gallery.accords-library.com/server/szurubooru/db/session.py

28 lines
602 B
Python
Raw Normal View History

import threading
2016-04-18 20:41:39 +00:00
import sqlalchemy
from szurubooru import config
# pylint: disable=invalid-name
_engine = sqlalchemy.create_engine(config.config['database'])
2016-08-26 11:43:55 +00:00
sessionmaker = sqlalchemy.orm.sessionmaker(bind=_engine, autoflush=False)
session = sqlalchemy.orm.scoped_session(sessionmaker)
2016-05-08 17:41:35 +00:00
_data = threading.local()
2016-05-08 17:41:35 +00:00
def reset_query_count():
_data.query_count = 0
2016-05-08 17:41:35 +00:00
def get_query_count():
return _data.query_count
def _bump_query_count():
_data.query_count = getattr(_data, 'query_count', 0) + 1
2016-08-14 18:06:49 +00:00
sqlalchemy.event.listen(
_engine, 'after_execute', lambda *args: _bump_query_count())