本文整理汇总了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()
示例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()
示例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()
示例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))
示例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()
示例6: setup
# 需要导入模块: import records [as 别名]
# 或者: from records import Database [as 别名]
def setup(bot):
bot.db = Database(bot)
示例7: __init__
# 需要导入模块: import records [as 别名]
# 或者: from records import Database [as 别名]
def __init__(self, fdb):
self.db = records.Database('sqlite:///{}'.format(fdb))
示例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')