Skip to content

Additional DeleteAll methods to delete a list of objects #77

Open
@ssteiner

Description

@ssteiner

Hi

Rather than to have to fork the lib to integrate this functionality, I'd like to propose to add it to the mainline.

In SQLiteconnection.cs, I've added two methods allowing me to delete more than one item in a transaction, and the item either being identified by its PK, or the object itself. I found that sqlite-net is not very effective when performing mass operations, and those two delete methods allow significant performance gains over doing it one by one.

    public int DeleteAll<T>(System.Collections.IEnumerable keys)
    {
        var c = 0;
        RunInTransaction(() => 
        {
            foreach (var r in keys)
                c += Delete<T>(r);
        });
        return c;
    }

    /// <summary>
    /// deletes all specified objects
    /// </summary>
    /// <param name="objects">
    /// An <see cref="IEnumerable"/> of the bojects to delete
    /// </param>
    /// <returns>
    /// The number of rows deleted
    /// </returns>
    public int DeleteAll(System.Collections.IEnumerable objects)
    {
        var c = 0;
        RunInTransaction(() => 
        {
            foreach(var r in objects) {
                c += Delete(r);
            }
        });
        return c;
    }

perhaps they should be named DeleteMany instead of DeleteAll..

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions