Exemplo n.º 1
0
def create_engine_for_db(*args, **kwargs):
    username = os.environ['DB_USER']
    password = os.environ['DB_PASS']
    host = os.environ['DB_HOST']
    schema = os.environ['DB_SCHEMA']

    DB_URL = f"mysql://{username}:{password}@{host}/{schema}"
    return __create_engine(DB_URL, *args, **kwargs)
Exemplo n.º 2
0
def create_engine(user, password, host, port, database):
    print('create new engine')
    create_engine.engine = __create_engine(f'mysql+pymysql://{user}:{password}@{host}:{port}/{database}',
                                           pool_pre_ping=True,
                                           pool_recycle=3600 * 7,
                                           echo=False)
    create_engine.engine.execute('SET GLOBAL max_allowed_packet=67108864;')
    return create_engine.engine
Exemplo n.º 3
0
def create_engine(engine, **kw):
    # file?
    try:
        f = open(engine, mode="r")
        engine = f.readline()
        if len(engine) > 0 and engine[-1] == "\n":
            engine = engine[:-1]
        f.close()
    except IOError:
        pass

    return __create_engine(engine, **kw)
Exemplo n.º 4
0
def create_engine(adapter, user, password, host, port, database):
    create_engine.adapter = adapter
    print(f'==> create_engine for {create_engine.adapter}')
    try:
        return create_engine.engine
    except AttributeError:
        print('create new engine')
        create_engine.engine = __create_engine(
            f'{adapter}://{user}:{password}@{host}:{port}/{database}',
            pool_pre_ping=True,
            pool_recycle=3600 * 7)
        create_engine.engine.execute('SET GLOBAL max_allowed_packet=67108864;')
        return create_engine.engine
Exemplo n.º 5
0
def create_engine_from_url(connection_url):
    print('create new engine')
    create_engine.engine = __create_engine(f'mysql+pymysql://{connection_url}',
                                           pool_pre_ping=True,
                                           pool_recycle=3600 * 7,
                                           echo=False)
    # Amazon does not give you SUPER privileges on an RDS instance
    # (to prevent you from breaking things like replication accidentally).
    # To configure group_concat_max_len, use an RDS parameter group,
    # which allows you to configure a group of settings to apply to an instance.
    # https://stackoverflow.com/questions/31147206/amazon-rds-unable-to-execute-set-global-command
    try:
        create_engine.engine.execute('SET GLOBAL max_allowed_packet=67108864;')
    except Exception as e:
        print(e)

    return create_engine.engine
Exemplo n.º 6
0
def create_engine():
    return __create_engine(config.DB)
Exemplo n.º 7
0
def connect():
    return __create_engine(__get_project_settings().get('CONNECTION_STRING'))