Beispiel #1
0

class NativeCoroutinesRequestHandler(SessionMixin, RequestHandler):
    async def get(self):
        with self.make_session() as session:
            count = await as_future(session.query(User).count)

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


if __name__ == '__main__':
    parse_command_line()

    assert options.database_url, "Need a database URL"

    db.configure(url=options.database_url)

    app = Application(
        [
            (r'/sync', SynchronousRequestHandler),
            (r'/gen-coroutines', GenCoroutinesRequestHandler),
            (r'/native-coroutines', NativeCoroutinesRequestHandler),
        ],
        db=db,
    )

    app.listen(8888)
    print('Listening on port 8888')

    IOLoop.current().start()
Beispiel #2
0
        with self.make_session() as session:
            count = yield as_future(session.query(User).count)

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


class NativeCoroutinesRequestHandler(SessionMixin, RequestHandler):
    async def get(self):
        with self.make_session() as session:
            count = await as_future(session.query(User).count)

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


if __name__ == '__main__':
    db.configure(url='sqlite://')

    app = Application(
        [
            (r'/sync', SynchronousRequestHandler),
            (r'/gen-coroutines', GenCoroutinesRequestHandler),
            (r'/native-coroutines', NativeCoroutinesRequestHandler),
        ],
        db=db,
    )

    app.listen(8888)
    print('Listening on port 8888')

    IOLoop.current().start()
Beispiel #3
0
            session.add(User(username='******'))
            session.add(Foo(foo='d'))
            session.add(Bar(bar='e'))
            session.commit()
            count = await as_future(session.query(User).count)

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


if __name__ == '__main__':
    db.configure(
        url='sqlite://',
        binds={
            'foo': 'sqlite:///foo.db',
            'bar': 'sqlite:///bar.db',
        },
        engine_options={
            'pool_size': 10,
            'pool_timeout': 0,
            'max_overflow': -1,
        },
    )

    app = Application(
        [
            (r'/sync', SynchronousRequestHandler),
            (r'/gen-coroutines', GenCoroutinesRequestHandler),
            (r'/native-coroutines', NativeCoroutinesRequestHandler),
        ],
        db=db,
        autoreload=True,
    )
    async def get(self):
        with self.make_session() as session:
            session.add(User(username='******'))
            session.add(Foo(foo='d'))
            session.add(Bar(bar='e'))
            session.commit()
            count = await as_future(session.query(User).count)

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


if __name__ == '__main__':
    db.configure(
        url='sqlite://',
        binds={
            'foo': 'sqlite:///foo.db',
            'bar': 'sqlite:///bar.db'
        },
    )

    app = Application(
        [
            (r'/sync', SynchronousRequestHandler),
            (r'/gen-coroutines', GenCoroutinesRequestHandler),
            (r'/native-coroutines', NativeCoroutinesRequestHandler),
        ],
        db=db,
        autoreload=True,
    )

    db.create_all()