def setup_pg(app, database, **settings): pg_db = peewee_async.PooledPostgresqlDatabase(database, **settings) _BaseModel.set_database(pg_db) pg_db.set_allow_sync(False) app.pg = peewee_async.Manager(pg_db) _BaseModel.manager = app.pg app.pg.get_or_none = types.MethodType(_get_or_none, app.pg) return app.pg
def __init__(self): app_settings = { 'cookie_secret': settings['cookie_secret'], 'xsrf_cookies': True, 'debug': settings['debug'], 'template_path': os.path.join(BASE_DIR, 'templates'), 'facebook_app_id': settings['facebook']['client_id'], 'facebook_secret': settings['facebook']['client_secret'] } routes = [ (r'/', MainHandler), (r'/auth/login', AuthLoginHandler), (r'/auth/logout', AuthLogoutHandler), (r'/articles', ArticlesHandler), ] self.database = peewee_async.PooledPostgresqlDatabase( settings['postgres']['database'], user=settings['postgres']['username'], password=settings['postgres']['password'], host=settings['postgres']['host']) super(Application, self).__init__(routes, **app_settings)
import asyncio import json as JSON import os import aiohttp_jinja2 import aiohttp import jinja2 import peewee import peewee_async HOST = os.environ.get('THOST', '127.0.0.1') database = peewee_async.PooledPostgresqlDatabase('test', max_connections=10, user='******', password='******', host=HOST) class Message(peewee.Model): content = peewee.CharField(max_length=512) class Meta: database = database @asyncio.coroutine def json(request): return aiohttp.web.Response(text=JSON.dumps({'message': 'Hello, World!'}), content_type='application/json')
from copy import deepcopy import peewee import peewee_async from playhouse.db_url import parse from project.application.utils import make_password from project.config.settings import db_url db_param = parse(db_url) db = peewee_async.PooledPostgresqlDatabase(**db_param) # Auth models class User(peewee.Model): name = peewee.CharField(index=True, unique=True, verbose_name='Имя пользователя') password = peewee.CharField(verbose_name='Пароль') @classmethod async def create_user(cls, **kwargs): # Создание пользователя manager = peewee_async.Manager(db) param = deepcopy(kwargs) param['password'] = make_password(param['password']) return await manager.create(cls, **param) async def update_password(self, password):
from proxy_py import settings import peewee import peewee_async raw_db = peewee_async.PooledPostgresqlDatabase( *settings.DATABASE_CONNECTION_ARGS, **settings.DATABASE_CONNECTION_KWARGS, ) class Proxy(peewee.Model): class Meta: database = raw_db db_table = 'proxies' indexes = ( (('raw_protocol', 'auth_data', 'domain', 'port'), True), (('auth_data', 'domain', 'port'), False), # important! (('raw_protocol', ), False), (('auth_data', ), False), (('domain', ), False), (('port', ), False), (('number_of_bad_checks', ), False), (('next_check_time', ), False), (('last_check_time', ), False), (('checking_period', ), False), (('uptime', ), False), (('bad_uptime', ), False), (('response_time', ), False), (('_white_ipv4', ), False), (('_white_ipv6', ), False), (('country_code', ), False),
.. _Tornado: http://www.tornadoweb.org Licensed under The MIT License (MIT) Copyright (c) 2016, Alexey Kinëv <*****@*****.**> """ # Start example [marker for docs] import tornado.web import logging import peewee import asyncio import peewee_async # Set up database and manager database = peewee_async.PooledPostgresqlDatabase('test') # Define model class TestNameModel(peewee.Model): name = peewee.CharField() class Meta: database = database def __str__(self): return self.name # Create table, add some instances TestNameModel.create_table(True)
db_config = { 'database': 'vibing', 'user': '******', 'password': '******', 'host': 'db', 'field_types': { 'point': 'geometry(Point)' }, 'operations': { peewee.OP.BBOX2D: peewee.OP.BBOX2D, peewee.OP.BBOXCONTAINS: peewee.OP.BBOXCONTAINS, peewee.OP.BBOXCONTAINED: peewee.OP.BBOXCONTAINED, } } database = peewee_async.PooledPostgresqlDatabase(**db_config) def create_db(): database.set_allow_sync(False) return peewee_async.Manager(database) async def close_db(app): await database.close() class BaseModel(peewee.Model): class Meta: database = database