當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。