本文整理匯總了Python中sqlalchemy_utils.functions.database_exists方法的典型用法代碼示例。如果您正苦於以下問題:Python functions.database_exists方法的具體用法?Python functions.database_exists怎麽用?Python functions.database_exists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlalchemy_utils.functions
的用法示例。
在下文中一共展示了functions.database_exists方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: createdb
# 需要導入模塊: from sqlalchemy_utils import functions [as 別名]
# 或者: from sqlalchemy_utils.functions import database_exists [as 別名]
def createdb(cls, keep_existing=False):
"""Create the database specified in configuration.
::
cls.init_configuration_manager()
cls.createdb()
:param keep_existing: If false drop the previous db before create it
"""
url = Configuration.get('get_url')()
db_template_name = Configuration.get('db_template_name', None)
if database_exists(url):
if keep_existing:
return False
drop_database(url)
create_database(url, template=db_template_name)
return True
示例2: dropdb
# 需要導入模塊: from sqlalchemy_utils import functions [as 別名]
# 或者: from sqlalchemy_utils.functions import database_exists [as 別名]
def dropdb(cls):
"""Drop the database specified in configuration.
::
cls.init_configuration_manager()
cls.dropdb()
"""
url = Configuration.get('get_url')()
if database_exists(url):
drop_database(url)
示例3: db_exists
# 需要導入模塊: from sqlalchemy_utils import functions [as 別名]
# 或者: from sqlalchemy_utils.functions import database_exists [as 別名]
def db_exists(cls, db_name=None):
if not db_name:
raise RegistryException('db_name is required')
url = Configuration.get('get_url', get_url)(db_name=db_name)
return database_exists(url)
示例4: create_db
# 需要導入模塊: from sqlalchemy_utils import functions [as 別名]
# 或者: from sqlalchemy_utils.functions import database_exists [as 別名]
def create_db():
"""Create db if it doesn't exist yet."""
db_url = engine.url
if not database_exists(db_url):
create_database(db_url)
base.metadata.create_all()
示例5: create_tables
# 需要導入模塊: from sqlalchemy_utils import functions [as 別名]
# 或者: from sqlalchemy_utils.functions import database_exists [as 別名]
def create_tables():
eng = get_engine()
if not database_exists(eng.url):
create_database(eng.url)
# Create all tables in the engine
Base.metadata.create_all(eng)
示例6: initialize_database
# 需要導入模塊: from sqlalchemy_utils import functions [as 別名]
# 或者: from sqlalchemy_utils.functions import database_exists [as 別名]
def initialize_database(exist_ok: bool = False, drop_existing: bool = False):
db_url = engine.url
typer.echo(f"Using database at {db_url}")
if database_exists(db_url):
if drop_existing:
with wrap_echo("Dropping database"):
drop_database(db_url)
elif not exist_ok:
typer.echo(
f"Database already exists, aborting.\n"
f"Use --exist-ok if you are sure the database is uninitialized and contains no data.\n"
f"Use --drop-existing if you want to recreate it.",
err=True,
)
return
with wrap_echo("Creating database"):
create_database(db_url)
pass
with engine.connect() as con:
with wrap_echo("Installing pgcrypto extension"):
con.execute("CREATE EXTENSION IF NOT EXISTS pgcrypto;")
pass
with wrap_echo("Creating metadata"):
base.metadata.create_all()
pass
typer.echo("Database initialization complete.")
示例7: configure_orm
# 需要導入模塊: from sqlalchemy_utils import functions [as 別名]
# 或者: from sqlalchemy_utils.functions import database_exists [as 別名]
def configure_orm():
global engine
global Session
engine_args = {}
Session = scoped_session(
sessionmaker(autocommit=False, autoflush=False))
try:
if database_exists(config.get_db()) is False:
create_engine(config.get_mysql()['uri'], echo=False).execute("create database IF NOT EXISTS {} DEFAULT CHARACTER SET utf8mb4".format(config.get_mysql()['db']))
engine = create_engine(config.get_db(), **engine_args)
Session = scoped_session(
sessionmaker(autocommit=False, autoflush=False, bind=engine))
except Exception as e:
pylog.print_err("初始化數據庫出現問題: {}".format(e))