本文整理匯總了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')