• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sqlalchemy_utils.database_exists函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sqlalchemy_utils.database_exists函数的典型用法代码示例。如果您正苦于以下问题:Python database_exists函数的具体用法?Python database_exists怎么用?Python database_exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了database_exists函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: makeDbEngine

    def makeDbEngine(self):
        '''
        function to establish engine with PostgreSQl database
        so that additional tables can be made 
        '''
        try:
            ## connect to Postgres
            dbname = self.getDbName()
            username = self.getUserName()
            print dbname
            print username
            
            ## create and set 
            engine = create_engine('postgres://%[email protected]/%s'%(username, dbname))
            self.setDbEngine(engine)

            ## test if it exists
            db_exist = database_exists(engine.url)
            if not db_exist:
                create_database(engine.url)
            db_exist = database_exists(engine.url)
            self.setDbExist(db_exist)
            return 0
        except:
            return 1
开发者ID:astrophys-degroot,项目名称:ncaa_mens_basketball,代码行数:25,代码来源:ncaa_basketball_db.py


示例2: create_postgres_db

def create_postgres_db():
    dbname = 'beer_db_2'
    username = 'postgres'
    mypassword = 'simple'
    
    ## Here, we're using postgres, but sqlalchemy can connect to other things too.
    engine = create_engine('postgres://%s:%[email protected]/%s'%(username,mypassword,dbname))
    print "Connecting to",engine.url
    
    if not database_exists(engine.url):
        create_database(engine.url)
    print "Does database exist?",(database_exists(engine.url))
    
    # load a database from CSV
    brewery_data = pd.DataFrame.from_csv('clean_data_csv/brewery_information_rescrape.csv')
    
    ## insert data into database from Python (proof of concept - this won't be useful for big data, of course)
    ## df is any pandas dataframe 
    brewery_data.to_sql('breweries', engine, if_exists='replace')

    #dbname = 'beer_review_db'
    # load a database from CSV
    beer_data = pd.DataFrame.from_csv('clean_data_csv/beer_review_information_rescrape.csv')
    #engine_2 = create_engine('postgres://%s:%[email protected]/%s'%(username,mypassword,dbname))
    #print "connecting to",engine.url
    
    #if not database_exists(engine_2.url):
    #    create_database(engine_2.url)
        
    #print "Does database exist?",(database_exists(engine_2.url))
    beer_data.to_sql('reviews',engine,if_exists='replace')
    print "database",dbname,"has been created"
    return
开发者ID:Jollyhrothgar,项目名称:ale_trail_codebase,代码行数:33,代码来源:create_db_from_csv.py


示例3: create_findmyride_database

def create_findmyride_database(database_name):
    engine = create_engine('postgresql://%s:%[email protected]/%s'%('dianeivy', password, database_name))
    print(engine.url)

    if not database_exists(engine.url):
        create_database(engine.url)
    print(database_exists(engine.url))
    return engine
开发者ID:dianeivy,项目名称:FindMyRide,代码行数:8,代码来源:create_weather_database.py


示例4: book_uri

def book_uri(request):
    name = request.param

    if name and database_exists(name):
        drop_database(name)
    yield name

    if name and database_exists(name):
        drop_database(name)
开发者ID:sdementen,项目名称:piecash,代码行数:9,代码来源:test_helper.py


示例5: createdb

def createdb():
    print "Connecting to %s" % settings.SQLALCHEMY_DATABASE_URI
    engine = create_engine(settings.SQLALCHEMY_DATABASE_URI)
    if settings.DROP_DB_ON_RESTART and database_exists(engine.url):
        print "Dropping old database... (because DROP_DB_ON_RESTART=True)"
        drop_database(engine.url)
    if not database_exists(engine.url):
        print "Creating databases..."
        create_database(engine.url)
开发者ID:occrp,项目名称:osoba,代码行数:9,代码来源:core.py


示例6: create_database

def create_database(dbname):
    #create a database with name "dbname" using lordluen ad username.
    #dbname = 'legislatr'
    username = 'lordluen'
    engine = create_engine('postgres://%[email protected]/%s'%(username,dbname))
    print(engine.url)
    if not database_exists(engine.url):
        create_database(engine.url)
    print(database_exists(engine.url))
    return
开发者ID:Lordluen,项目名称:legislatr_old,代码行数:10,代码来源:sqlCommands.py


示例7: initialize

def initialize(re_createTable= False):
    if re_createTable :
        if not database_exists(engine.url):
            create_database(DATABASE.url)

        print(database_exists(engine.url))
        Base.metadata.drop_all(DATABASE, checkfirst = True)


    Base.metadata.create_all(DATABASE, checkfirst = True)
开发者ID:jeeka321,项目名称:Production,代码行数:10,代码来源:models.py


示例8: new_book_USD

def new_book_USD(request):
    name = request.param

    if name and database_exists(name):
        drop_database(name)

    with create_book(uri_conn=name, currency="USD", keep_foreign_keys=False) as b:
        yield b

    if name and database_exists(name):
        drop_database(name)
开发者ID:sdementen,项目名称:piecash,代码行数:11,代码来源:test_helper.py


示例9: book_db_config

def book_db_config(request):
    from piecash.core.session import build_uri

    sql_backend, db_config = request.param
    name = build_uri(**db_config)

    if sql_backend != "sqlite_in_mem" and database_exists(name):
        drop_database(name)

    yield db_config

    if sql_backend != "sqlite_in_mem" and database_exists(name):
        drop_database(name)
开发者ID:sdementen,项目名称:piecash,代码行数:13,代码来源:test_helper.py


示例10: read_user_features

def read_user_features():
    ## create a database (if it doesn't exist)
    if not database_exists(local_weave_pair.url):
        create_database(local_weave_pair.url)
    print(database_exists(local_weave_pair.url))
    # connect:
    con = psycopg2.connect(database = 'weave_pair', user = 'jiongz')
    # query:
    sql_query = """
    SELECT * FROM user_features_combine;
    """
    user_features = pd.read_sql_query(sql_query,con)    
    return user_features
开发者ID:wszjzhang,项目名称:FastMatch,代码行数:13,代码来源:weave_match.py


示例11: app

def app(request):
    """The Flask API (scope = Session)."""
    config.DB_NAME = DB_NAME
    DATABASE_URI = config.DATABASE_URI.format(**config.__dict__)

    if not database_exists(DATABASE_URI):
        create_database(DATABASE_URI)

    print "Test Database: %s" % DATABASE_URI

    # Config the app
    _app.config["SQLALCHEMY_DATABASE_URI"] = DATABASE_URI
    _app.config["SQLALCHEMY_ECHO"] = True # Toggle SQL Alchemy output
    _app.config["DEBUG"] = True
    _app.config["TESTING"] = True

    # Establish an application context before running the tests.
    ctx = _app.app_context()
    ctx.push()

    # Initialize a null cache
    cache.config = {}
    cache.init_app(_app)

    def teardown():
        ctx.pop()

    request.addfinalizer(teardown)
    return _app
开发者ID:adriancooney,项目名称:examist,代码行数:29,代码来源:conftest.py


示例12: init_db

    def init_db(self):
        """
        Initializes the database connection based on the configuration parameters
        """
        db_type = self.config['db_type']
        db_name = self.config['db_name']
        if db_type == 'sqlite':
            # we can ignore host, username, password, etc
            sql_lite_db_path = os.path.join(os.path.split(CONFIG)[0], db_name)
            self.db_connection_string = 'sqlite:///{}'.format(sql_lite_db_path)
        else:
            username = self.config['username']
            password = self.config['password']
            host_string = self.config['host_string']
            self.db_connection_string = '{}://{}:{}@{}/{}'.format(db_type, username, password, host_string, db_name)

        self.db_engine = create_engine(self.db_connection_string)
        # If db not present AND type is not SQLite, create the DB
        if not self.config['db_type'] == 'sqlite':
            if not database_exists(self.db_engine.url):
                create_database(self.db_engine.url)
        Base.metadata.bind = self.db_engine
        Base.metadata.create_all()
        # Bind the global Session to our DB engine
        global Session
        Session.configure(bind=self.db_engine)
开发者ID:MITRECND,项目名称:multiscanner,代码行数:26,代码来源:sql_driver.py


示例13: add_db

def add_db():  # pragma: no cover
    db_url = config['service']['db_uri']
    global engine
    engine = create_engine(db_url)

    if database_exists(engine.url):
        print('!!! DATABASE ALREADY EXISTS !!!')
        return False

    print()
    print('!!! DATABASE NOT DETECTED !!!')
    print()

    try:
        confirm = input('Create database designated in the config file? [Y/n]') or 'Y'
    except KeyboardInterrupt:
        confirm = ''
        print()

    if confirm.strip() != 'Y':
        print('Not createing DB. Exiting.')
        return False

    create_database(engine.url)
    return True
开发者ID:rewardStyle,项目名称:generator-plait,代码行数:25,代码来源:_model.py


示例14: create_ctfd

def create_ctfd(ctf_name="CTFd", name="admin", email="[email protected]", password="password", setup=True):
    app = create_app('CTFd.config.TestingConfig')

    url = make_url(app.config['SQLALCHEMY_DATABASE_URI'])
    if url.drivername == 'postgres':
        url.drivername = 'postgresql'

    if database_exists(url):
        drop_database(url)
        create_database(url)
        with app.app_context():
            app.db.create_all()

    if setup:
        with app.app_context():
            with app.test_client() as client:
                data = {}
                r = client.get('/setup')  # Populate session with nonce
                with client.session_transaction() as sess:
                    data = {
                        "ctf_name": ctf_name,
                        "name": name,
                        "email": email,
                        "password": password,
                        "nonce": sess.get('nonce')
                    }
                client.post('/setup', data=data)
    return app
开发者ID:semprix,项目名称:CTFIgniter,代码行数:28,代码来源:helpers.py


示例15: scan

def scan():
    if not database_exists(Engine.url):
        display_failure('database does not exist.')
        sys.exit(1)

    inspector = reflection.Inspector.from_engine(Engine)

    if not inspector.get_table_names():
        display_failure('no table(s) were found.')
        sys.exit(1)

    with session_scope() as session:
        q1 = session.query(DNSList)
        q2 = session.query(IPRange)

        if not(session.query(q1.exists()).scalar()
               and session.query(q2.exists()).scalar()):
            display_failure(
                'scan requires records in both `dns_list` and `ip_range`.')
            sys.exit(1)

        banner()
        display_info('starting scan ...')
        Scanner().scan(session)
    return 0
开发者ID:UCF,项目名称:Site-Owner-Scanner,代码行数:25,代码来源:smap-cli.py


示例16: __init__

    def __init__(self, chembl_version=20):
        self.chembl_version = chembl_version

        if not database_exists(self.database_url):
            self.load_chembl()

        self.engine = create_engine(self.database_url)
开发者ID:richlewis42,项目名称:qsardb,代码行数:7,代码来源:__init__.py


示例17: setup

def setup():
    print(app.config['SQLALCHEMY_DATABASE_URI'])
    engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
    if database_exists(engine.url):
        drop_database(engine.url)
    create_database(engine.url)
    engine.execute('create extension if not exists fuzzystrmatch')
开发者ID:massover,项目名称:jaypeak,代码行数:7,代码来源:manage.py


示例18: clean_db

def clean_db(ctx: click.Context):
    """Removes Postgres database."""
    db_uri = make_url(ctx.obj['db_uri'])
    db_uri_str = db_uri.__to_string__()
    if database_exists(db_uri):
        logging.info(f'Cleaning "{db_uri_str}" database.')
        drop_database(db_uri)
开发者ID:lycantropos,项目名称:RecommendSystem,代码行数:7,代码来源:manage.py


示例19: init_data

def init_data():
    from imports import (
            Widget,Article,Page,
            User,Setting,Type,
            Template,Tag,Role,
            Category,Block,Profile,
            ContactMessage)
    """Fish data for project"""
    if prompt_bool('Do you want to kill your db?'):
        if squ.database_exists(db.engine.url):
            squ.drop_database(db.engine.url)
    try:
        db.drop_all()
    except:
        pass
    try:
        squ.create_database(db.engine.url)
        db.create_all()
    except:
        pass

    user = User.query.filter(User.email=='[email protected]').first()
    if user is None:
       user = User(username='kyle', email='[email protected]', password='14wp88')
    user.save()
开发者ID:4johndoe,项目名称:flask-cms,代码行数:25,代码来源:manage.py


示例20: dropDatabase

def dropDatabase(dbName):
    """Drop specified database."""
    config = CONFIG_DB
    connectString = "postgresql://{}:{}@{}:{}/{}".format(config["username"],
        config["password"], config["host"], config["port"], dbName)
    if sqlalchemy_utils.database_exists(connectString):
        sqlalchemy_utils.drop_database(connectString)
开发者ID:lisaam,项目名称:data-act-broker-backend,代码行数:7,代码来源:databaseSetup.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sqlalchemy_utils.drop_database函数代码示例发布时间:2022-05-27
下一篇:
Python sqlalchemy_utils.create_database函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap