Python records.Database() Examples

The following are 14 code examples of records.Database(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module records , or try the search function .
Example #1
Source File: database.py    From OneForAll with GNU General Public License v3.0 6 votes vote down vote up
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() 
Example #2
Source File: conftest.py    From records with ISC License 6 votes vote down vote up
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() 
Example #3
Source File: dbengine.py    From SQL_Database_Optimization with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, fdb):
        #fdb = 'data/test.db'
        self.db = records.Database('sqlite:///{}'.format(fdb)) 
Example #4
Source File: dbengine.py    From SQLNet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, fdb):
        #fdb = 'data/test.db'
        self.db = records.Database('sqlite:///{}'.format(fdb)) 
Example #5
Source File: dbengine.py    From nl2sql_baseline with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, fdb):
        self.db = records.Database('sqlite:///{}'.format(fdb))
        self.conn = self.db.get_connection() 
Example #6
Source File: database.py    From DHV3 with GNU Affero General Public License v3.0 5 votes vote down vote up
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() 
Example #7
Source File: database.py    From DHV3 with GNU Affero General Public License v3.0 5 votes vote down vote up
def setup(bot):
    bot.db = Database(bot) 
Example #8
Source File: dbengine.py    From sqlova with Apache License 2.0 5 votes vote down vote up
def __init__(self, fdb):
        self.db = records.Database('sqlite:///{}'.format(fdb)) 
Example #9
Source File: dbengine.py    From sqlova with Apache License 2.0 5 votes vote down vote up
def __init__(self, fdb):
        #fdb = 'data/test.db'
        self.db = records.Database('sqlite:///{}'.format(fdb)) 
Example #10
Source File: dbengine.py    From tranX with Apache License 2.0 5 votes vote down vote up
def __init__(self, fdb):
        self.db = records.Database('sqlite:///{}'.format(fdb)) 
Example #11
Source File: conftest.py    From records with ISC License 5 votes vote down vote up
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') 
Example #12
Source File: dbengine.py    From nl2sql with MIT License 5 votes vote down vote up
def __init__(self, fdb):
        self.db = records.Database('sqlite:///{}'.format(fdb)) 
Example #13
Source File: dbengine.py    From claf with MIT License 5 votes vote down vote up
def __init__(self, fdb):
        self.db = records.Database('sqlite:///{}'.format(fdb))
        self.conn = self.db.get_connection() 
Example #14
Source File: dbengine.py    From coarse2fine with MIT License 5 votes vote down vote up
def __init__(self, fdb):
        self.db = records.Database('sqlite:///{}'.format(fdb))