コード例 #1
0
 def __new__(cls, *args, **kwargs):
     if not hasattr(cls, "_instance"):
         kwargs = cls.from_config()
         cls.conn = PooledMySQLDatabase(**kwargs, charset='utf8mb4')
         cls.manager = Manager(cls.conn)
         cls._instance = super(MysqlPool, cls).__new__(cls)
     return cls._instance
コード例 #2
0
ファイル: db.py プロジェクト: IvanAlekhin/python-templ
def get_pool():
    return PooledMySQLDatabase(
        database=config.config.db_name,
        max_connections=config.config.db_max_con,
        min_connections=5,
        user=config.config.db_user,
        password=config.config.db_password,
        host=config.config.db_host,
        port=config.config.db_port,
    )
コード例 #3
0
 def __new__(cls, *args, **kwargs):
     if not hasattr(cls, "_instance"):
         logger.debug("init mysql pool")
         cls.conn = PooledMySQLDatabase('blog',
                                        host='localhost',
                                        password='',
                                        port=3306,
                                        user='******',
                                        max_connections=10,
                                        charset='utf8mb4')
         cls.manager = Manager(cls.conn)
         cls._instance = super(MysqlPool, cls).__new__(cls, *args, **kwargs)
     return cls._instance
コード例 #4
0
ファイル: db.py プロジェクト: goeo-/memebot-2.0
    def __init__(self):
        self.database = PooledMySQLDatabase(
            Config()['sql']['db'],
            user=Config()['sql']['user'],
            password=Config()['sql']['password'],
            host=Config()['sql']['host'],
            port=int(Config()['sql']['port']),
            max_connections=10)

        self.objects = Manager(self.database, loop=asyncio.get_event_loop())
        self.objects.database.allow_sync = False

        self.user_locks = defaultdict(asyncio.Lock)
コード例 #5
0
ファイル: mysql.py プロジェクト: PythonerKK/tornado-forum
 def __new__(cls, *args, **kwargs):
     if not hasattr(cls, "_instance"):
         logger.debug("init mysql pool")
         cls.conn = PooledMySQLDatabase(
             database=_settings['database'],
             host=_settings['host'],
             password=_settings['password'],
             port=_settings['port'],
             user=_settings['user'],
             max_connections=_settings['max_connections'],
             charset=_settings['charset'])
         cls.manager = Manager(cls.conn)
         cls._instance = super(MysqlPool, cls).__new__(cls, *args, **kwargs)
     return cls._instance
コード例 #6
0
 def init_db(config: dict) -> PooledMySQLDatabase:
     peer_conn = "_".join([
         config["host"], str(config["port"]), config["database"]])
     if not AsyncMySQLConnect.__conn.get(peer_conn):
         _database = PooledMySQLDatabase(
             database=config["database"],
             max_connections=config['max_connections'],
             host=config['host'],
             user=config['user'],
             password=config["password"],
             port=config['port']
         )
         AsyncMySQLConnect.__conn[peer_conn] = _database
         logging.debug(f"connect mysql {peer_conn} successful")
     return AsyncMySQLConnect.__conn[peer_conn]
コード例 #7
0
ファイル: mysql.py プロジェクト: gzshop/taskserver
    def __new__(cls, *args, **kwargs):
        if not hasattr(cls, "_instance"):
            PROJECT_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), os.path.pardir)
            if PROJECT_PATH not in sys.path:
                sys.path.insert(0, PROJECT_PATH)

            from config import mysql
            cls.conn = PooledMySQLDatabase(
                mysql['name'],
                host=mysql['host'],
                password=mysql['password'],
                port=mysql['port'],
                user=mysql['user'],
                min_connections=mysql['min_connections'],
                max_connections=mysql['max_connections'],
                charset=mysql['charset'])
            cls.manager = Manager(cls.conn)
            # cls.conn.set_allow_sync(False)
            cls.conn.set_allow_sync(True)
            cls._instance = super(MysqlPool, cls).__new__(cls, *args, **kwargs)
        return cls._instance
コード例 #8
0
ファイル: mysql.py プロジェクト: lyonyang/fund
    pass
"""

import operator
from lib.dt import dt
from base import config
from peewee import reduce
from peewee_async import Manager, PooledMySQLDatabase, AsyncQueryWrapper
from peewee import Model, AutoField, DateTimeField, IntegerField, Query
from playhouse.pool import PooledMySQLDatabase as SyncPooledMySQLDatabase

# Connect to a MySQL database on network.
async_db = PooledMySQLDatabase(
    config.MYSQL_CONFIG['db'],
    max_connections=config.MYSQL_CONFIG['max_connections'],
    user=config.MYSQL_CONFIG['username'],
    password=config.MYSQL_CONFIG['password'],
    host=config.MYSQL_CONFIG['host'],
    port=config.MYSQL_CONFIG['port']
)

sync_db = SyncPooledMySQLDatabase(
    config.MYSQL_CONFIG['db'],
    max_connections=config.MYSQL_CONFIG['max_connections'],
    user=config.MYSQL_CONFIG['username'],
    password=config.MYSQL_CONFIG['password'],
    host=config.MYSQL_CONFIG['host'],
    port=config.MYSQL_CONFIG['port']
)


class Func:
コード例 #9
0
ファイル: register.py プロジェクト: qinlinli/miniapp
from sanic_jinja2 import SanicJinja2
from peewee_async import Manager, PooledMySQLDatabase

jinja2 = SanicJinja2()

database = PooledMySQLDatabase('gateway',
                               host='10.39.34.123',
                               port=3306,
                               user='******',
                               password='******')
objects = Manager(database)
コード例 #10
0
def declarative_base(*args, **kwargs):
    """Returns a new Modeled Class after inheriting meta and Model classes"""
    # db = PostgresqlDatabase(*args, **kwargs)
    # db = PooledPostgresqlDatabase(*args, **kwargs)
    db = PooledMySQLDatabase(**kwargs)
    return _get_meta_db_class(db)
コード例 #11
0
import peewee
import asyncio
import datetime
import aiomysql
from random import randint

from peewee_async import Manager, PooledMySQLDatabase
from config import MYSQL_CONFIG

mysql_db = PooledMySQLDatabase(**MYSQL_CONFIG)

loop = asyncio.get_event_loop()
objects = Manager(mysql_db, loop=loop)


class MonitorWsClient(peewee.Model):
    update_time = peewee.DateTimeField(index=True)
    name = peewee.CharField()
    value = peewee.FloatField()

    class Meta:
        database = mysql_db

    @classmethod
    async def record(cls, params):
        valid_names = (
            "valuable room",
            "api room cnt",
            "active clients",
            "broken clients",
            "total clients",
コード例 #12
0
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
=================================================
@Project -> File   :chatbot-management_v2 -> __init__.py
@IDE    :PyCharm
@Author :Mr. Wireless
@Date   :2020/7/14 14:19
@Desc   :
==================================================
"""

from peewee_async import Manager, PooledMySQLDatabase
from config.settings import MYSQL_PARAMS

db = PooledMySQLDatabase(**MYSQL_PARAMS)

dbManger = Manager(db)
コード例 #13
0
ファイル: __init__.py プロジェクト: assad2008/YeeTornado
#/usr/bin/python
# coding=utf-8

from peewee import Model
from peewee_async import PooledMySQLDatabase
from yee.settings.db import *

db_master = PooledMySQLDatabase(DB_NAME, host=DB_HOST, port=DB_PORT, user=DB_USER,
                                password=DB_PASSWD, charset='utf8mb4')
db_master.connect()


class BaseModel(Model):

    class Meta:
        database = db_master