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 (identified by their rowids):

|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| | | | | | | | | | | | | | | | | | |

You don’t create a database region directly. Instead, you use one of those methods:

  • SelectStatement.fetchedRegion:

    let statement = db.makeSelectStatement(SELECT name, score FROM players) print(statement.fetchedRegion) // prints players(name,score)

  • Request.fetchedRegion(_:)

    let request = Player.filter(key: 1) try print(request.fetchedRegion(db)) // prints players(*)[1]

Database regions returned by requests can be more precise than regions returned by select statements. Especially, regions returned by statements don’t know about rowids:

// A plain statement
let statement = db.makeSelectStatement("SELECT * FROM players WHERE id = 1")
statement.fetchedRegion       // "players(*)"

// A query interface request that executes the same statement:
let request = Player.filter(key: 1)
try request.fetchedRegion(db) // "players(*)[1]"
  • Returns whether the region is empty.

    Declaration

    Swift

    public var isEmpty: Bool
  • The empty database region

    Declaration

    Swift

    public init()
  • 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