Ejemplo n.º 1
0
 def __init__(self):
     if self.INSTANCE is not None:
         raise ValueError("An instantiation already exists!")
     else:
         self.__cnxPool = MySQLConnectionPool(pool_name='myPool',
                                              pool_size=5,
                                              option_files='db_config.conf')
Ejemplo n.º 2
0
 def __init__(self):
     """Mysqldriver Constructor."""
     self.config = {
         "host":
         "db-espresso-dev" if environ.get("APP_ENV") == "development" else
         environ.get("MYSQL_HOST"),
         "database":
         environ.get("MYSQL_DATABASE", "espresso_db"),
         "user":
         environ.get("MYSQL_USER", "root"),
         "password":
         environ.get("MYSQL_ROOT_PASSWORD", "strawberry"),
         "port":
         int(environ.get("MYSQL_PORT", 3306)),
         "pool_name":
         "mysql_pool",
         "pool_size":
         5,
         "pool_reset_session":
         False,  # MySQL version 5.7.2 and earlier does not support COM_RESET_CONNECTION.
     }
     try:
         self.cnxpool = MySQLConnectionPool(**self.config)
     except errors.Error as err:
         print(err)
Ejemplo n.º 3
0
def test():
    from mysql.connector.pooling import MySQLConnectionPool
    from config.db_config import mysql_config as db_conf

    cnx_pool = MySQLConnectionPool(
        pool_name='default_cnx_pool', **db_conf)
    model = DbModel(cnx_pool)
 def __init__(self):
     if self.INSTANCE is not None:
         raise ValueError("An instantiation already exists!")
     else:
         db_config = read_db_config(filename='Config.ini', section='mysql')
         print(type(db_config), db_config)
         self.__cnxPool = MySQLConnectionPool(pool_name='myPool', pool_size=5, **db_config)
Ejemplo n.º 5
0
def test():
    from mysql.connector.pooling import MySQLConnectionPool
    from config.db_config import mysql_config as db_conf

    cnx_pool = MySQLConnectionPool(pool_name='default_cnx_pool', **db_conf)
    model = ModelExchange(cnx_pool)

    print(model.get_exchange_dict())
Ejemplo n.º 6
0
def test():
    from mysql.connector.pooling import MySQLConnectionPool
    from config.db_config import mysql_config as db_conf

    cnx_pool = MySQLConnectionPool(pool_name='default_cnx_pool', **db_conf)
    model = ModelTrCoinone(cnx_pool)
    #model.insert_tr(1, [{'price':355, 'qty':10, 'datetime':datetime.now() },{'price':355, 'qty':12, 'datetime':datetime.now() }] )
    print(model.get_tr(1))
Ejemplo n.º 7
0
 def __init__(self):
     if self.INSTANCE is not None:
         raise ValueError("An instantiation already exists!")
     else:
         db_config = read_db_config()
         self.__cnxPool = MySQLConnectionPool(pool_name="myPool",
                                              pool_size=5,
                                              **db_config)
Ejemplo n.º 8
0
 def __init__(self, filename='../resources/db_properties.ini'):
     if self.INSTANCE is not None:
         raise ValueError("An instantiation already exists!")
     else:
         db_config = read_db_config(filename)
         self.__cnxPool = MySQLConnectionPool(pool_name="myPool",
                                              pool_size=10,
                                              **db_config)
Ejemplo n.º 9
0
class Database:

    dbconfig = {"database": "pythontest", "user": "******", "password": "******"}

    conn = MySQLConnectionPool(pool_name="mypool", pool_size=2, **dbconfig)

    def getConn(self):
        return self.conn.get_connection()
Ejemplo n.º 10
0
def dbconfigload(db_name, user_name, port, password, host_name, pool_name):
    dbconfig = {}
    dbconfig["database"] = db_name
    dbconfig["user"] = user_name
    dbconfig["port"] = port
    dbconfig["password"] = password
    dbconfig["host"] = host_name
    return MySQLConnectionPool(pool_name=pool_name, pool_size=3, **dbconfig)
Ejemplo n.º 11
0
 def _init_pool(self):
     logger.info("Connecting pool to DB")
     self.pool_mutex.acquire()
     self.pool = MySQLConnectionPool(
         pool_name="db_wrapper_pool",
         pool_size=self.application_args.db_poolsize,
         **self.dbconfig)
     self.pool_mutex.release()
Ejemplo n.º 12
0
 def get_connection_pool():
     MysqlDatabase.pool = MySQLConnectionPool(pool_name="connection_pool",
                                              pool_size=32,
                                              pool_reset_session=True,
                                              host=HOST,
                                              port=PORT,
                                              database=DATABASE,
                                              user=USER,
                                              password=PASSWORD)
Ejemplo n.º 13
0
	def connectDbPool(self,POOLSIZE=1): 
		try:
			if PRINTLEVEL>=INFO_PRINT: print "MySQLConnectionPool connectDbPool ..."
			cnxpool=MySQLConnectionPool(pool_name=self.config['host'],pool_size=POOLSIZE,**self.config)
			self.pool=cnxpool
			return 1
		except Exception, e:
			print "! Failed connectDbPool !"
			if PRINTLEVEL>=ERROR_PRINT: print(e)
Ejemplo n.º 14
0
def init_connection_pool(user, password, database, host, port):
    global CONNECTION_POOL
    CONNECTION_POOL = MySQLConnectionPool(pool_name="opendcpool",
                                          pool_size=5,
                                          user=user,
                                          password=password,
                                          database=database,
                                          host=host,
                                          port=port)
Ejemplo n.º 15
0
 def __init__(self,):
     """Constructs a pool of connection according to the config.py file"""
     self.__pool = MySQLConnectionPool(
         pool_name = config.POOL_NAME,
         pool_size = config.POOL_SIZE,
         host      = config.HOST,
         port      = config.PORT,
         database  = config.DATABASE,
         user      = config.USERNAME,
         password  = config.PASSWORD
     )
Ejemplo n.º 16
0
 def connect_database(self, **kwargs) -> MySQLConnectionPool:
     print("[DEBUG] set connection pool configuration configure: ", kwargs)
     for key, value in kwargs.items():
         # self.__MySQL_Stock_Data_Config[key] = value
         self._Database_Config[key] = value
     print("[DEBUG] database config: ", self._Database_Config)
     connection_pool = MySQLConnectionPool(**self._Database_Config)
     self._logger.debug(
         f"MySQL_Connection_Pool at 'connection_strategy.init_connection_pool': {connection_pool}"
     )
     return connection_pool
Ejemplo n.º 17
0
    def __init__(self, broker_cloud, mode, db_config, time_inactive_platform, time_update_conf, time_check_platform_active):
        self.time_update_conf = time_update_conf
        self.time_check_platform_active = time_check_platform_active
        self.time_inactive_platform = time_inactive_platform
        self.cnxpool = MySQLConnectionPool(pool_name="mypool", pool_size=32, **db_config)
        self.mode = mode

        self.producer_connection = Connection(broker_cloud)
        self.consumer_connection = Connection(broker_cloud)

        self.exchange = Exchange("IoT", type="direct")
Ejemplo n.º 18
0
    def __init__(self, config):
        """Constructor to initialize the connection pool.
            
        Args:
            config (dict): Connection configuration for database.

        """
        self._config = config
        self._db_pool = MySQLConnectionPool(pool_name="disc_pool",
                                            pool_size=_POOL_SIZE,
                                            **config)
Ejemplo n.º 19
0
def init(user, password, host, database):
    global connectionPool
    dbconfig = {
        "host": host,
        "user": user,
        "password": password,
        "database": database
    }
    connectionPool = MySQLConnectionPool(pool_name='connection_pool',
                                        pool_size=10,
                                        pool_reset_session=True,
                                        **dbconfig)
Ejemplo n.º 20
0
def f(x, s):
    cnxpool = MySQLConnectionPool(
        pool_name="dbpool",
        pool_size=5,
        host='10.32.1.31',
        port=3306,
        user='******',
        database='secu',
        # ssl_ca='',
        # use_pure=True,
        connect_timeout=90000)
    return x * x, x + 1, s['a'] * s['b']
Ejemplo n.º 21
0
 def __init__(self):
     cnf = {
         'user': '******',
         'password': '******',
         'host': 'localhost',
         'port': 3306,
         'database': 'steam',
         'charset': 'utf8mb4',
         'pool_name': 'my_pool',
         'pool_size': 5
     }
     self.cnx_pool = MySQLConnectionPool(**cnf)
Ejemplo n.º 22
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     # self._conn_params['use_pure'] = True
     self._conn_params['pool_name'] = 'test_pool'
     self._conn_params['pool_size'] = 10
     try:
         self._pool = MySQLConnectionPool(**self._conn_params)
         self._closed = False
     except InterfaceError as e:
         log.error('MysqlPooledDataSource connect error')
         log.error(formatErrorMsg(e))
         raise e
Ejemplo n.º 23
0
 def _init_pool(self):
     logger.info("Connecting to DB")
     dbconfig = {
         "host": self.host,
         "port": self.port,
         "user": self.user,
         "password": self.password,
         "database": self.database
     }
     with self._pool_mutex:
         self._pool = MySQLConnectionPool(pool_name="db_wrapper_pool",
                                          pool_size=self._poolsize,
                                          **dbconfig)
Ejemplo n.º 24
0
def _init(db_pool_size=None, db_host=None, db_port=None, db_pwd=None):
    global cnxpool
    print("PID {}: initializing mysql connection pool...".format(os.getpid()))
    cnxpool = MySQLConnectionPool(
        pool_name="dbpool",
        pool_size=db_pool_size or 5,
        host=db_host or '127.0.0.1',
        port=db_port or 3306,
        user='******',
        database='secu',
        password=db_pwd or '123456',
        # ssl_ca='',
        # use_pure=True,
        connect_timeout=60000)
Ejemplo n.º 25
0
def _init():
    global cnxpool
    print("PID %d: initializing mysql connection pool..." % os.getpid())
    cnxpool = MySQLConnectionPool(
        pool_name="dbpool",
        pool_size=1,
        host='127.0.0.1',
        port=3306,
        user='******',
        database='secu',
        password='******',
        # ssl_ca='',
        # use_pure=True,
        connect_timeout=60000)
Ejemplo n.º 26
0
 def _init_pool(self):
     logger.info("Connecting to DB")
     dbconfig = {
         "host": self.host,
         "port": self.port,
         "user": self.user,
         "password": self.password,
         "database": self.database,
         "time_zone": "America/Los_Angeles"
     }
     self._pool_mutex.acquire()
     self._pool = MySQLConnectionPool(pool_name="db_wrapper_pool",
                                      pool_size=self._poolsize,
                                      **dbconfig)
     self._pool_mutex.release()
Ejemplo n.º 27
0
    def __init__(self):
        if MySQL._connection_pool:
            return

        with MySQL.__singleton_lock:
            if not MySQL._connection_pool:
                MySQL._connection_pool = MySQLConnectionPool(
                    host=MySQL.mysql_host,
                    user=MySQL.mysql_user,
                    password=MySQL.mysql_password,
                    db=MySQL.mysql_db,
                    charset='utf8',
                    pool_name="db_pool",
                    pool_size=MySQL.mysql_pool_size,
                    buffered=True)
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self._conn_params['use_pure'] = True
     self._conn_params['pool_name'] = 'test_pool'
     self._conn_params['pool_size'] = 10
     # self._pool = MySQLConnectionPool(**{'user':self._user_name,'password':self._pass_word,\
     #                                     'host':self._host,'port':self._port,'database':self._data_base,\
     #                                     'use_pure':True,'pool_name':"test_pool",'pool_size':10})
     try:
         self._traceback = None
         self._pool = MySQLConnectionPool(**self._conn_params)
     except InterfaceError as e:
         print('MysqlPooledDataSource connect error')
         e.with_traceback(self._traceback)
         raise e
Ejemplo n.º 29
0
 def _init(cls):
     if cls.is_initialized:
         return
     cls.connection_config = {
         "host": Config.MYSQL_HOST,
         "port": Config.MYSQL_PORT,
         "database": Config.MYSQL_DATABASE,
         "user": Config.MYSQL_USER,
         "password": Config.MYSQL_PASSWORD,
     }
     cls.connection_pool = (MySQLConnectionPool(
         pool_name="app_pool",
         pool_size=Config.MYSQL_POOL_SIZE,
         pool_reset_session=False,
         **cls.connection_config) if Config.MYSQL_POOL_SIZE else None)
Ejemplo n.º 30
0
 def __init__(self,
              *args,
              db_schema: DBSchema,
              dictionary: bool = False,
              named_tuple: bool = False,
              pool_size: int = 16,
              **kwargs):
     print('MySQLPooledConnection: Init with pool_size=%d' % pool_size)
     self.cnx_pool = MySQLConnectionPool(pool_size=pool_size,
                                         *args,
                                         **kwargs)
     super().__init__(*args,
                      db_schema=db_schema,
                      dictionary=dictionary,
                      named_tuple=named_tuple,
                      **kwargs)