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