def __conn(self, *args): if len(args) == 0: db = PostgresqlDatabase(database=getConfig('conn_default', 'database'), host=getConfig('conn_default', 'host'), user=getConfig('conn_default', 'user'), password=getConfig('conn_default', 'password')) elif len(args) == 1: conn_key = str(args[0]) if conn_key == "": conn_key = "conn_default" dbtype = getConfig(conn_key, 'dbtype') if dbtype == 'pgsql': db = PostgresqlDatabase( database=getConfig(conn_key, 'database'), host=getConfig(conn_key, 'host'), user=getConfig(conn_key, 'user'), password=getConfig(conn_key, 'password')) elif dbtype == 'mysql': db = MySQLDatabase(database=getConfig(conn_key, 'database'), host=getConfig(conn_key, 'host'), user=getConfig(conn_key, 'user'), password=getConfig(conn_key, 'password')) return db
def make_test_app(): clear_entry_services() app = Sanic(__name__) database = PostgresqlDatabase(database=DB) app.blueprint(bp, db=database, db_name=DB_NAME, loop=None) service = get_entry_service() service.dropdb() service.initdb() database.close() database.allow_sync = False app.db = database return app
def main(debug=False, run=True): # loop loop = async_loop.new_event_loop() asyncio.set_event_loop(loop) # database database = PostgresqlDatabase(database=settings.DATABASE) # templates view = View({"HTML_TEMPLATES_DIR": settings.TEMPLATES_DIR}) # app app = make_app(view, database) app.blueprint(sessions, db=database, db_name='sessions', loop=loop) app.blueprint(users, db=database, db_name='users', loop=loop, sessions_db_name='sessions') app.blueprint(entries, db=database, db_name=BLOG_ENTRY_DB_NAME, loop=loop) app.blueprint(entries, db=database, db_name=COMMENT_ENTRY_DB_NAME, loop=loop) app.blueprint(entries, db=database, db_name=FILES_ENTRY_DB_NAME, loop=loop) app.blueprint(registration, view=view) app.blueprint(login, view=view) app.blueprint(logout, view=view) app.blueprint(files, view=view) app.blueprint(blog, view=view) if run: app.run(host="0.0.0.0", port=8000, loop=loop, debug=debug) return app, loop, view, database
def setup(app, loop): database = PostgresqlDatabase(database='test', host='127.0.0.1', user='******', password='******') objects = Manager(database, loop=loop)
def __conn(self): db = PostgresqlDatabase(database=getConfig('pgdb','database'), host=getConfig('pgdb','host'), port=getConfig('pgdb','port'), user=getConfig('pgdb','user'), password=getConfig('pgdb','password')) return db
def make_test_app(): clear_session_services() clear_user_services() app = Sanic(__name__) database = PostgresqlDatabase(database=DB) app.blueprint(session_blueprint, db=database, db_name=DB_SESSION_NAME, loop=None) app.blueprint(bp, db=database, db_name=DB_NAME, loop=None, sessions_db_name=DB_SESSION_NAME) service = get_user_service() service.dropdb() service.initdb() service = get_session_service() service.dropdb() service.initdb() database.close() database.allow_sync = False app.db = database return app
def make_app(view=None, database=None): if not view: view = View({"HTML_TEMPLATES_DIR": settings.TEMPLATES_DIR}) if not database: database = PostgresqlDatabase(database=settings.DATABASE) app = Sanic(__name__) app.config = Config() app.config.LOGO = "Atlantis! Go FAST!" app.config.REQUEST_MAX_SIZE = 2000000 # 2 megababies app.config.REQUEST_TIMEOUT = 60 * 5 # 5 min app.static('/static', settings.STATIC_DIR) @app.middleware('response') async def halt_response(request, response): response.headers['Content-Security-Policy'] = \ "default-src 'self' 'unsafe-inline';" return app
from peewee import Model from playhouse.postgres_ext import PostgresqlExtDatabase from peewee import CharField, TextField, DateTimeField from peewee_async import Manager, PostgresqlDatabase from passlib.hash import pbkdf2_sha512 from datetime import datetime from app import app_loop # psql_db = PostgresqlExtDatabase('sanic_scrum', user='******', register_hstore=False) psql_db = PostgresqlDatabase(database='sanic_scrum', user='******') objects = Manager(psql_db, loop=app_loop) class BaseModel(Model): """A base model that will use our Postgresql database""" class Meta: database = psql_db class User(BaseModel): create_datetime = DateTimeField(default=datetime.utcnow, null=True) username = CharField(unique=True, index=True) passwd = CharField(null=True) email = CharField(unique=True, index=True) phone = CharField() sex = CharField() zone = CharField()
from peewee import Model from settings import (DB_USER, DB_NAME, DB_PORT, DB_HOST) #from playhouse.postgres_ext import PostgresqlExtDatabase from peewee_async import Manager from peewee_async import PostgresqlDatabase #db = SqliteDatabase('zinat.db') db = PostgresqlDatabase( DB_NAME, # Required by Peewee. user=DB_USER, # Will be passed directly to psycopg2. host=DB_HOST, # Ditto. port=DB_PORT, ) class BaseModel(Model): class Meta: database = db
# -*- coding:utf-8 -*- from peewee import Model from peewee_async import Manager from peewee_async import PostgresqlDatabase from future import CONFIG DB_CONFIG = CONFIG.DB_CONFIG database = PostgresqlDatabase(**DB_CONFIG) objects = Manager(database) class BaseModel(Model): class Meta: database = database
def declarative_base(*args, **kwargs): """Returns a new Modeled Class after inheriting meta and Model classes""" db = PostgresqlDatabase(*args, **kwargs) return _get_meta_db_class(db)
import peewee from playhouse.db_url import parse from peewee_async import PostgresqlDatabase from app import settings from app.cache import Cache db_param = parse(settings.DATABASE_URL) db = PostgresqlDatabase(**db_param) PAYD_CONDITIONS = { 'partner1': { 'DE': { 'wowp': { 'tutorial', }, }, 'FR': { 'wowp': { 'tutorial', }, }, 'IT': { 'wowp': { 'tutorial', }, }, }, 'partner2': { 'RU': { 'wot': { 'reg',
import asyncio import datetime import peewee import logging from aiogram import types, exceptions from peewee import DoesNotExist from peewee_async import Manager, PostgresqlDatabase database = PostgresqlDatabase('peewee_test') class MyManager(Manager): database = database objects = MyManager() class User(peewee.Model): tg_id = peewee.BigIntegerField(primary_key=True) full_name = peewee.CharField(max_length=100) username = peewee.CharField(max_length=50) class Meta: database = database table_name = 'users' class CarBrand(peewee.Model):
import asyncio from peewee_async import PostgresqlDatabase from peewee_async import Manager io_loop = asyncio.get_event_loop() psql_db = PostgresqlDatabase(database='betbot', user='******', password='******', host='127.0.0.1') database_manager = Manager(psql_db, loop=io_loop)
"""Module for declare database.""" from peewee_async import PostgresqlDatabase from src import settings DATABASE = PostgresqlDatabase(None) default_name = settings.BFF_POSTGRES_OPTIONS['database'] def init_db(db_name: str = default_name) -> None: """ Init database. May init real/test database depends on argument `db_name`. """ init_args = ('port', 'host', 'user', 'password') init_params = {} for option in settings.BFF_POSTGRES_OPTIONS: if option in init_args: init_params[option] = settings.BFF_POSTGRES_OPTIONS[option] DATABASE.init(db_name, **init_params)
# peewee_async # peewee ## sanic imports import peewee import uvloop from peewee_async import Manager, PostgresqlDatabase from sanic import Sanic from sanic.response import json # we instantiate a custom loop so we can pass it to our db manager loop = uvloop.new_event_loop() database = PostgresqlDatabase(database='test', host='127.0.0.1', user='******', password='******') objects = Manager(database, loop=loop) ## from peewee_async docs: # Also there’s no need to connect and re-connect before executing async queries # with manager! It’s all automatic. But you can run Manager.connect() or # Manager.close() when you need it. # let's create a simple key value store: class KeyValue(peewee.Model): key = peewee.CharField(max_length=40, unique=True) text = peewee.TextField(default='')
from peewee import Model from peewee_async import PostgresqlDatabase database = PostgresqlDatabase(None) class BaseModel(Model): class Meta: database = database
import asyncio import peewee import logging import random from collections import AsyncIterable from peewee_async import Manager, PostgresqlDatabase import asyncio loop = asyncio.get_event_loop() database = PostgresqlDatabase('tags', user='******', password='******', host='postgres') objects = Manager(database, loop=loop) class Tag(peewee.Model): id = peewee.IntegerField(primary_key=True, unique=True, index=True) account = peewee.CharField() campaign_id = peewee.IntegerField(index=True) tag = peewee.CharField() class Meta: database = database objects.database.allow_sync = False async def fill_table():
def init_db(cls, database_name, **kwargs): database = PostgresqlDatabase(database_name, **kwargs) cls.database.initialize(database) User.create_table(fail_silently=True) database.allow_sync = False