def METHOD_NAME(self, filepath, grants, chunk_size=None):
    """Write grants to an SQLite file.
    In case no rows were written to the file, the file is removed.
    :param str filepath: Path to the SQLite file to be written.
    :param grants: Iterable of grants that will be written to the
        database.
    :return: Number of rows written to the file.
    """
    chunk_size = chunk_size or self.rows_write_chunk_size
    with sqlite3.connect(filepath) as conn:
        conn.execute('CREATE TABLE grants (data text, format text)')
        total_rows_inserted = 0
        rows_inserted = 1
        while rows_inserted > 0:
            rows_inserted = conn.executemany(
                'INSERT INTO grants VALUES (?, ?)',
                zip(islice(grants, chunk_size), repeat('xml'))
            ).rowcount
            if rows_inserted > 0:
                total_rows_inserted += rows_inserted
    if total_rows_inserted <= 0:  # delete a zero-rows file
        os.unlink(filepath)
    return total_rows_inserted