当前位置: 首页>>代码示例>>Python>>正文


Python functions.database_exists方法代码示例

本文整理汇总了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 
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:22,代码来源:testing.py

示例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) 
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:14,代码来源:testing.py

示例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) 
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:8,代码来源:registry.py

示例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() 
开发者ID:Nukesor,项目名称:pornhub-dl,代码行数:8,代码来源:db.py

示例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) 
开发者ID:ntt-sic,项目名称:masakari,代码行数:8,代码来源:api.py

示例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.") 
开发者ID:Nukesor,项目名称:ultimate-poll-bot,代码行数:33,代码来源:initdb.py

示例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)) 
开发者ID:chengyumeng,项目名称:spider163,代码行数:16,代码来源:settings.py


注:本文中的sqlalchemy_utils.functions.database_exists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。