<commit_before>from sqlalchemy import Column, BigInteger, String
from tornado.gen import coroutine
from tornado.ioloop import IOLoop
from tornado.options import options
from tornado_sqlalchemy import (as_future, declarative_base,
                                make_session_factory, SessionMixin)
from tornado.web import RequestHandler, Application


DeclarativeBase = declarative_base()


class User(DeclarativeBase):
    __tablename__ = 'users'

    id = Column(BigInteger, primary_key=True)
    username = Column(String(255), unique=True)


class SyncWebRequestHandler(RequestHandler, SessionMixin):
    def get(self):
        with self.make_session() as session:
            count = session.query(User).count()

        self.write('{} users so far!'.format(count))


class AsyncWebRequestHandler(RequestHandler, SessionMixin):
    @coroutine
    def get(self):
        with self.make_session() as session:
            count = yield as_future(session.query(User).count)

        self.write('{} users so far!'.format(count))


class UsesSelfSessionRequestHandler(RequestHandler, SessionMixin):
    @coroutine
    def get(self):
        count = self.session.query(User).count()

        self.write('{} users so far!'.format(count))<commit_msg>fix SessionMixin usage in tornado example<commit_after>from sqlalchemy import Column, BigInteger, String
from tornado.gen import coroutine
from tornado.ioloop import IOLoop
from tornado.options import options
from tornado_sqlalchemy import (as_future, declarative_base,
                                make_session_factory, SessionMixin)
from tornado.web import RequestHandler, Application


DeclarativeBase = declarative_base()


class User(DeclarativeBase):
    __tablename__ = 'users'

    id = Column(BigInteger, primary_key=True)
    username = Column(String(255), unique=True)


class SyncWebRequestHandler(SessionMixin, RequestHandler):
    def get(self):
        with self.make_session() as session:
            count = session.query(User).count()

        self.write('{} users so far!'.format(count))


class AsyncWebRequestHandler(SessionMixin, RequestHandler):
    @coroutine
    def get(self):
        with self.make_session() as session:
            count = yield as_future(session.query(User).count)

        self.write('{} users so far!'.format(count))


class UsesSelfSessionRequestHandler(SessionMixin, RequestHandler):
    @coroutine
    def get(self):
        count = self.session.query(User).count()

        self.write('{} users so far!'.format(count))
{'fraction_non_alphanumeric': 0.09690230341540905, 'fraction_numerical': 0.0023828435266084196, 'mean_word_length': 3.7708333333333335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4249477', 'n_tokens_mistral': 731, 'n_tokens_neox': 695, 'n_words': 176}