Ejemplo n.º 1
0
def create_database(app: App) -> None:
    config = get_config(app)
    database = peewee_asyncext.PooledPostgresqlExtDatabase(
        **parse(config.postgres_url))
    database_proxy.initialize(database)
    app.ctx['database'] = database_proxy
    objects = peewee_async.Manager(database_proxy)
    database.set_allow_sync(False)
    app.ctx['objects'] = objects
Ejemplo n.º 2
0
def init_test_db():
    return peewee_asyncext.PooledPostgresqlExtDatabase(
        settings.POSTGRES_TEST_DB,
        user=settings.POSTGRES_TEST_USER,
        password=settings.POSTGRES_TEST_PASSWORD,
        host=settings.POSTGRES_TEST_HOST,
        port=settings.POSTGRES_TEST_PORT,
        register_hstore=False,
    )
Ejemplo n.º 3
0
import peewee
import peewee_asyncext

from playhouse.postgres_ext import ArrayField

db = peewee_asyncext.PooledPostgresqlExtDatabase('delay', register_hstore=False)


class Heading(peewee.Model):
    line = peewee.CharField()
    way = peewee.IntegerField()
    stops = ArrayField(field_class=peewee.BooleanField)
    timestamp = peewee.DateTimeField()

    class Meta:
        database = db
Ejemplo n.º 4
0
import peewee
import peewee_async
import peewee_asyncext
import os
import json

MAX_CONNECTIONS = 5

database_file_name = os.environ["DATABASE_FILE"]
# Load the database access informations
with open(database_file_name, "r") as database_file:
    database_access = json.load(database_file)

# Start connection pool and objects manager
database = peewee_asyncext.PooledPostgresqlExtDatabase(
    **database_access["database-prod"],
    autorollback=True,
    max_connections=MAX_CONNECTIONS,
    register_hstore=False
)

manager = peewee_async.Manager(database)


def close_connections():
    manager.close()
Ejemplo n.º 5
0
Archivo: db.py Proyecto: comger/qor
        cursor.execute(CREATE_DB)
    except Exception as e:
        logger.info(e)
    finally:
        cursor.close()
        conn.close()


create_database()
create_hstore_extension()

pgdb = peewee_asyncext.PooledPostgresqlExtDatabase(
    config.POSTGRES_DB,
    host=config.POSTGRES_SERVER,
    port=config.POSTGRES_PORT,
    user=config.POSTGRES_USER,
    password=config.POSTGRES_PASSWORD,
    register_hstore=True,
    max_connections=10,
)


class DataViewsionManage(peewee_async.Manager):
    async def create(self, obj, **data):
        # 生成创建ID, XX,XX 字段记录
        with pgdb.atomic():
            newObj = await super().create(obj, **data)
            return newObj

    async def update(self, obj, only=None):
        # 生成修改ID, XX,XX 字段的记录