def METHOD_NAME(read_only=True, foreign_keys=True, integrity_check=True):
    """Connects to the SQLite database, returning a db `Connection` object"""
    logger.debug('Creating connection to `{}`.'.format(config.DATABASE))
    if read_only:
        db = apsw.Connection(config.DATABASE, flags=apsw.SQLITE_OPEN_READONLY)
    else:
        db = apsw.Connection(config.DATABASE)
    cursor = db.cursor()
    # For integrity, security.
    if foreign_keys and not read_only:
        logger.info('Checking database foreign keys...')
        cursor.execute('''PRAGMA foreign_keys = ON''')
        cursor.execute('''PRAGMA defer_foreign_keys = ON''')
        rows = list(cursor.execute('''PRAGMA foreign_key_check'''))
        if rows:
            for row in rows:
                logger.debug('Foreign Key Error: {}'.format(row))
            raise exceptions.DatabaseError('Foreign key check failed.')
        # So that writers don’t block readers.
        cursor.execute('''PRAGMA journal_mode = WAL''')
        logger.info('Foreign key check completed.')
    # Make case sensitive the `LIKE` operator.
    # For insensitive queries use 'UPPER(fieldname) LIKE value.upper()''
    cursor.execute('''PRAGMA case_sensitive_like = ON''')
    if integrity_check:
        logger.info('Checking database integrity...')
        integral = False
        for i in range(10): # DUPE
            try:
                cursor.execute('''PRAGMA integrity_check''')
                rows = cursor.fetchall()
                if not (len(rows) == 1 and rows[0][0] == 'ok'):
                    raise exceptions.DatabaseError('Integrity check failed.')
                integral = True
                break
            except DatabaseIntegrityError:
                time.sleep(1)
                continue
        if not integral:
            raise exceptions.DatabaseError('Could not perform integrity check.')
        logger.info('Integrity check completed.')
    db.setrowtrace(rowtracer)
    db.setexectrace(exectracer)
    cursor.close()
    return db