MutableRelation

public protocol MutableRelation : AnyObject, Relation

Undocumented

  • Perform a cascading delete on the relation. The query is used for the initial deletion run. For every deleted row, cascade is called to get further deletions to perform. When nothing remains to be deleted, completionCallback is called.

    Declaration

    Swift

    public func cascadingDelete(
        _ query: SelectExpression,
        affectedRelations: [MutableRelation],
        cascade: @escaping (MutableRelation, Row) -> [(MutableRelation, SelectExpression)],
        update: @escaping (MutableRelation, Row) -> [CascadingUpdate] = { _, _ in [] },
        completionCallback: @escaping (Result<Void, RelationError>) -> Void = { _ in })

    Parameters

    query

    The initial query for rows to delete on this relation.

    affectedRelations

    An array of all relations that this operation will affect. This array must include all relations that will be updated or deleted, otherwise notifications won’t work right. It is acceptable to pass in more than will actually be changed. This will generate spurious but harmless change notifications.

    cascade

    Called for each deleted row to get cascades. Must return an array of (MutableRelation, SelectExpression) pairs indicating what to delete next. The same relation can be specified to perform a cascading delete within the relation, or a different one can be specified to do cross-relation cascades.

    update

    Called for each deleted row to get updates. Must return an array of CascadingUpdate instances indicating what updates to apply on the basis of the deleted row.

    completionCallback

    Called when the cascading delete completes.

  • Do a tree deletion in the relation. This will delete all rows matching the query, as well as all rows whose childAttribute matches the value in the parentAttribute of a deleted row. This proceeds recursively until the whole tree is deleted, or an error occurs.

    Declaration

    Swift

    public func treeDelete(
        _ query: SelectExpression,
        parentAttribute: Attribute,
        childAttribute: Attribute,
        update: @escaping (MutableRelation, Row) -> [CascadingUpdate] = { _, _ in [] },
        completionCallback: @escaping (Result<Void, RelationError>) -> Void = { _ in })