Beispiel #1
0
def get_engine():
    args = get_db_args()
    password = args['password']
    connect_str = "{}+pymysql://{}:{}@{}:{}/{}?charset=utf8mb4".format(args['db_type'], args['user'], password,
                                                             args['host'], args['port'], args['db_name'])
    engine = create_engine(connect_str, encoding='utf-8')
    return engine
Beispiel #2
0
def get_engine():
    kwargs = get_db_args()
    connect_str = "postgresql+psycopg2://{}:{}@{}:{}/{}".format(
        kwargs['user'], kwargs['password'], kwargs['host'], kwargs['port'],
        kwargs['dbname'])
    engine = create_engine(connect_str, encoding='utf-8')
    return engine
Beispiel #3
0
 def __init__(self, db_index=0):
     """
     dbindex: 0-mysql,1-postgresql,2-sqlite
     默认为mysql数据库
     """
     self._dbtype = get_db_type(db_index)
     self._dbargs = get_db_args(self._dbtype)
     self._conn = self.connect()
     if self._conn:
         self._cursor = self._conn.cursor()
Beispiel #4
0
def get_engine():
    args = get_db_args()
    connect_str = "{}+pymysql://{}:{}@{}:{}/{}?charset=utf8mb4".format(
        args['db_type'], args['user'], args['password'], args['host'],
        args['port'], args['db_name'])
    eng = create_engine(connect_str,
                        encoding='utf-8',
                        pool_size=1000,
                        pool_recycle=7200,
                        pool_pre_ping=True,
                        max_overflow=100,
                        pool_timeout=1200,
                        pool_reset_on_return='commit')
    return eng
Beispiel #5
0
def get_engine(dbindex=0):
    """dbindex=0
    默认使用mysql数据库
    0-mysql,1-postgresql,2-sqlite
    """
    dbtype = get_db_type(dbindex)
    args = get_db_args(dbtype)
    if dbtype == 'sqlite':
        dbDir = os.path.join(BASE_DIR, '%s_db' % dbtype)
        dbpath = os.path.join(dbDir, args['dbname'])
        connect_str = DSNs[dbtype].format(filepath=dbpath)
    else:
        connect_str = DSNs[dbtype].format(args['user'], args['password'],
                                          args['host'], args['dbname'])
    # print(connect_str)
    engine = create_engine(connect_str, encoding='utf-8')
    return engine