示例#1
0
async def startup_stuff(app, loop):
    db = connect(loop=loop, **db_config)
    if db:
        setattr(app, 'db', db)
        # create channel for websocket subscribers
        app.pubsub = MongoChannel(name='pubsub', db=db)
        app.pubsub.kickoff()
示例#2
0
async def startup_stuff(app, loop):
    db = connect(loop=loop, **db_config)
    if db:
        setattr(app, 'db', db)
        # create channel for websocket subscribers
        app.pubsub = MongoChannel(name='pubsub', db=db)
        app.pubsub.kickoff()
        # create websocket multiplexer
        app.multiplexer = WebsocketMultiplexer(app)
        app.multiplexer.add_router('chatrooms', chatrooms_router)
示例#3
0
async def convert():
    db = connect(**db_config)

    cursor = Movie.get_cursor(db=db, query={})
    cursor.skip(0)
    cursor.limit(1000)
    movies = await Movie.find(cursor)
    for movie in movies:
        print(movie.title)
        movie.genres2 = ', '.join(movie.genres)
        await movie.save(db)
示例#4
0
async def bootstrap_db():
    print('Initializing DB...')
    client = _get_client(**db_config)
    client.drop_database('chatrooms')

    db = connect(**db_config)
    print('Creating collections and indices....')

    futures = []
    for model_class in [User, Room, Entry]:
        futures.append(create_collection(db, model_class))

    await asyncio.gather(*futures)
    print('Done')
示例#5
0
async def bootstrap_db():
    print('Initializing DB...')
    client = _get_client(**db_config)
    client.drop_database('weblog')

    db = connect(**db_config)
    print('Creating collections and indices....')
    await create_app_collections(db)
    print('Loading fixture...')

    with open('./data.json') as data_file:
        data = loads(data_file.read())
        await db['entry'].insert_many(data)

    print('Done')
示例#6
0
def create_app(loop):
    # create web application
    app = web.Application(loop=loop, middlewares=[cors],
                          debug=True)  # middlewares=[database], debug=True)
    # connect database
    db = connect(**db_config)
    if db:
        setattr(app, 'db', db)
    # add routes
    for route in routes:
        print(route)
        app.router.add_route(method=route.methods,
                             path=route.path,
                             handler=route.handler,
                             name=route.name)

    return app
示例#7
0
def create_app(loop):
    # create web application
    app = web.Application(loop=loop, middlewares=[cors],
                          debug=True)  # middlewares=[database], debug=True)
    # connect database
    db = connect(**db_config)
    if db:
        setattr(app, 'db', db)
    # add routes
    for route in routes:
        app.router.add_route(method=route.methods,
                             path=route.path,
                             handler=route.handler,
                             name=route.name)
    app.router.add_route(method='*',
                         path='/ws/',
                         handler=ResourceEventsWebSocketView,
                         name='websocket')

    # create channel for websocket subscribers
    app.pubsub = MongoChannel(name='pubsub', db=db)
    app.pubsub.kickoff()

    return app
示例#8
0
async def connect_to_db(app, loop):
    db = connect(loop=loop, **db_config)
    if db:
        setattr(app, 'db', db)