本文整理汇总了Python中sqlalchemy.engine_from_config方法的典型用法代码示例。如果您正苦于以下问题:Python sqlalchemy.engine_from_config方法的具体用法?Python sqlalchemy.engine_from_config怎么用?Python sqlalchemy.engine_from_config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy
的用法示例。
在下文中一共展示了sqlalchemy.engine_from_config方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_migrations_online
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine_from_config [as 别名]
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata
)
with context.begin_transaction():
context.run_migrations()
示例2: run_migrations_online
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine_from_config [as 别名]
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
db_url = os.environ['DRYDOCK_DB_URL']
connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool,
url=db_url)
with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata)
with context.begin_transaction():
context.run_migrations()
示例3: run_migrations_online
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine_from_config [as 别名]
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
connect_args={'options': f'-c search_path={_app_config.POSTGRES_SCHEMA}'}
)
with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata
)
with context.begin_transaction():
context.run_migrations()
示例4: run_migrations_online
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine_from_config [as 别名]
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
engine = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool)
connection = engine.connect()
context.configure(
connection=connection,
target_metadata=target_metadata
)
try:
with context.begin_transaction():
context.run_migrations()
finally:
connection.close()
示例5: run_migrations_online
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine_from_config [as 别名]
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
configuration = config.get_section(config.config_ini_section)
configuration['sqlalchemy.url'] = os.environ['HAMMER_DATABASE_URL']
connectable = engine_from_config(
configuration,
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata
)
with context.begin_transaction():
context.run_migrations()
示例6: run_migrations_online
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine_from_config [as 别名]
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool)
with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata
)
with context.begin_transaction():
context.run_migrations()
示例7: run_migrations_online
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine_from_config [as 别名]
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool)
with connectable.connect() as connection:
context.configure(
connection = connection,
target_metadata = target_metadata,
include_object = include_object,
compare_type=True
)
with context.begin_transaction():
context.run_migrations()
示例8: run_migrations_online
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine_from_config [as 别名]
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
engine = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool
)
connection = engine.connect()
context.configure(
connection=connection,
target_metadata=target_metadata,
compare_type=True
)
try:
with context.begin_transaction():
context.run_migrations()
finally:
connection.close()
示例9: run_migrations_online
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine_from_config [as 别名]
def run_migrations_online():
engine = engine_from_config(
config.get_section(config.config_ini_section),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
connection = engine.connect()
context.configure(
connection=connection, target_metadata=target_metadata, compare_type=True
)
try:
with context.begin_transaction():
context.run_migrations()
finally:
connection.close()
示例10: run_migrations_online
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine_from_config [as 别名]
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(connection=connection,
target_metadata=target_metadata)
with context.begin_transaction():
context.run_migrations()
示例11: __init__
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine_from_config [as 别名]
def __init__(self, config=None, master_url=None, slaves_url=None, session_conf=None, **kwargs):
"""
连接对象init
:param base_conf: 全局配置,sqlalchemy.开头
:param master_url: 主库连接
:param slaves_url: 从库连接
:param others_url: 其他类型,暂未实现
:param kwargs: 自定义配置
"""
super(SQLAlchemy, self).__init__(config=config, master_url=master_url, slaves_url=slaves_url,
session_conf=session_conf, **kwargs)
# 每一个engine都会有一个factory,感觉挺闹心,要是有10个engine。。就得10个factory,未来寻找一下全局只有一个factory的方案
self._slave_tmp = None
session_conf['query_cls'] = BaseQuery
self._master_engine = engine_from_config(self.config, prefix=_SQLALCHEMY_PREFIX, url=master_url[0], **kwargs)
self._master_session = create_session(self._master_engine, **session_conf)
self._slaves_session = []
self._slave_engine = []
for slave in slaves_url:
slave_engine = engine_from_config(self.config, prefix=_SQLALCHEMY_PREFIX, url=slave, **kwargs)
self._slave_engine.append(slave_engine)
self._slaves_session.append(create_session(slave_engine, **session_conf))
示例12: run_migrations_online
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine_from_config [as 别名]
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata
)
with context.begin_transaction():
context.run_migrations()
示例13: run_migrations_online
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine_from_config [as 别名]
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = getattr(config, 'connection', None)
if connectable is None:
connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool)
with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata,
version_table=VERSION_TABLE
)
with context.begin_transaction():
context.run_migrations()
示例14: run_migrations_online
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import engine_from_config [as 别名]
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
engine = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool)
connection = engine.connect()
context.configure(connection=connection,
target_metadata=target_metadata,
transaction_per_migration=True)
try:
with context.begin_transaction():
context.run_migrations()
finally:
connection.close()