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


Python records.Database方法代码示例

本文整理汇总了Python中records.Database方法的典型用法代码示例。如果您正苦于以下问题:Python records.Database方法的具体用法?Python records.Database怎么用?Python records.Database使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在records的用法示例。


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

示例1: get_conn

# 需要导入模块: import records [as 别名]
# 或者: from records import Database [as 别名]
def get_conn(db_path):
        """
        Get database connection

        :param   db_path: Database path
        :return: db_conn: SQLite database connection
        """
        logger.log('TRACE', f'Establishing database connection')
        if isinstance(db_path, Connection):
            return db_path
        protocol = 'sqlite:///'
        if not db_path:  # 数据库路径为空连接默认数据库
            db_path = f'{protocol}{setting.result_save_dir}/result.sqlite3'
        else:
            db_path = protocol + db_path
        db = records.Database(db_path)  # 不存在数据库时会新建一个数据库
        logger.log('TRACE', f'Use the database: {db_path}')
        return db.get_connection() 
开发者ID:shmilylty,项目名称:OneForAll,代码行数:20,代码来源:database.py

示例2: db

# 需要导入模块: import records [as 别名]
# 或者: from records import Database [as 别名]
def db(request, tmpdir):
    """Instance of `records.Database(dburl)`

    Ensure, it gets closed after being used in a test or fixture.

    Parametrized with (sql_url_id, sql_url_template) tuple.
    If `sql_url_template` contains `{dbfile}` it is replaced with path to a
    temporary file.

    Feel free to parametrize for other databases and experiment with them.
    """
    id, url = request.param
    # replace {dbfile} in url with temporary db file path
    url = url.format(dbfile=str(tmpdir / "db.sqlite"))
    db = records.Database(url)
    yield db  # providing fixture value for a test case
    # tear_down
    db.close() 
开发者ID:kennethreitz-archive,项目名称:records,代码行数:20,代码来源:conftest.py

示例3: __init__

# 需要导入模块: import records [as 别名]
# 或者: from records import Database [as 别名]
def __init__(self, fdb):
        self.db = records.Database('sqlite:///{}'.format(fdb))
        self.conn = self.db.get_connection() 
开发者ID:ZhuiyiTechnology,项目名称:nl2sql_baseline,代码行数:5,代码来源:dbengine.py

示例4: __init__

# 需要导入模块: import records [as 别名]
# 或者: from records import Database [as 别名]
def __init__(self, fdb):
        #fdb = 'data/test.db'
        self.db = records.Database('sqlite:///{}'.format(fdb)) 
开发者ID:llSourcell,项目名称:SQL_Database_Optimization,代码行数:5,代码来源:dbengine.py

示例5: __init__

# 需要导入模块: import records [as 别名]
# 或者: from records import Database [as 别名]
def __init__(self, bot):
        self.bot = bot
        # Create the database object
        self.database = records.Database(f'mysql+mysqldb://{bot.database_user}:{bot.database_password}'
                                         f'@{bot.database_address}:{bot.database_port}'
                                         f'/{bot.database_name}?charset=utf8mb4')
        self.recreate_caches() 
开发者ID:DuckHunt-discord,项目名称:DHV3,代码行数:9,代码来源:database.py

示例6: setup

# 需要导入模块: import records [as 别名]
# 或者: from records import Database [as 别名]
def setup(bot):
    bot.db = Database(bot) 
开发者ID:DuckHunt-discord,项目名称:DHV3,代码行数:4,代码来源:database.py

示例7: __init__

# 需要导入模块: import records [as 别名]
# 或者: from records import Database [as 别名]
def __init__(self, fdb):
        self.db = records.Database('sqlite:///{}'.format(fdb)) 
开发者ID:naver,项目名称:sqlova,代码行数:4,代码来源:dbengine.py

示例8: foo_table

# 需要导入模块: import records [as 别名]
# 或者: from records import Database [as 别名]
def foo_table(db):
    """Database with table `foo` created

    tear_down drops the table.

    Typically applied by `@pytest.mark.usefixtures('foo_table')`
    """
    db.query('CREATE TABLE foo (a integer)')
    yield
    db.query('DROP TABLE foo') 
开发者ID:kennethreitz-archive,项目名称:records,代码行数:12,代码来源:conftest.py


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