DatabaseRegion

public struct DatabaseRegion : CustomStringConvertible, Equatable

DatabaseRegion defines a region in the database. DatabaseRegion is dedicated to help transaction observers recognize impactful database changes in their observes(eventsOfKind:) and databaseDidChange(with:) methods.

A database region is the union of any number of table regions, which can cover a full table, or the combination of columns and rows:

|Table1 |   |Table2 |   |Table3 |   |Table4 |   |Table5 |
|-------|   |-------|   |-------|   |-------|   |-------|
|x|x|x|x|   |x| | | |   |x|x|x|x|   |x|x| |x|   | | | | |
|x|x|x|x|   |x| | | |   | | | | |   | | | | |   | |x| | |
|x|x|x|x|   |x| | | |   | | | | |   |x|x| |x|   | | | | |
|x|x|x|x|   |x| | | |   | | | | |   | | | | |   | | | | |

To create a database region, you use one of those methods:

  • DatabaseRegion.fullDatabase: the region that covers all database tables.

  • DatabaseRegion(): the empty region.

  • DatabaseRegion(table:): the region that covers one database table.

  • SelectStatement.databaseRegion:

    let statement = try db.makeSelectStatement(sql: "SELECT name, score FROM player")
    let region = statement.databaseRegion
    
  • FetchRequest.databaseRegion(_:)

    let request = Player.filter(key: 1)
    let region = try request.databaseRegion(db)
    
  • Returns whether the region is empty.

    Declaration

    Swift

    public var isEmpty: Bool { get }
  • The region that covers the full database: all columns and all rows from all tables.

    Declaration

    Swift

    public static let fullDatabase: DatabaseRegion
  • Creates an empty database region.

    Declaration

    Swift

    public init()
  • Creates a region that spans all rows and columns of a database table.

    Declaration

    Swift

    public init(table: String)

    Parameters

    table

    A table name.

  • Returns the union of this region and the given one.

    Declaration

    Swift

    public func union(_ other: DatabaseRegion) -> DatabaseRegion
  • Inserts the given region into this region

    Declaration

    Swift

    public mutating func formUnion(_ other: DatabaseRegion)
  • Returns whether the content in the region would be impacted if the database were modified by an event of this kind.

    Declaration

    Swift

    public func isModified(byEventsOfKind eventKind: DatabaseEventKind) -> Bool
  • Returns whether the content in the region is impacted by this event.

    Precondition

    event has been filtered by the same region in the TransactionObserver.observes(eventsOfKind:) method, by calling region.isModified(byEventsOfKind:)

    Declaration

    Swift

    public func isModified(by event: DatabaseEvent) -> Bool