Instance Methodgrdb 7.3.0GRDB

registerAccess(to:)

Reports the database region to ValueObservation.

Database.swift:908
func registerAccess(to region: @autoclosure () -> some DatabaseRegionConvertible) throws

Calling this method does not fetch any database values. It just helps optimizing ValueObservation. See trackingConstantRegion(_:) for more information, and some examples of usage.

For example:

let observation = ValueObservation.tracking { db in
    // All changes to the 'player' and 'team' tables
    // will trigger the observation.
    try db.registerAccess(to: Player.all())
    try db.registerAccess(to: Team.all())
}

This method has no effect on a ValueObservation created with tracking(regions:fetch:). In the example below, only the player table is tracked:

// Observes the 'player' table only
let observation = ValueObservation.tracking(region: Player.all()) { db in
    // Ignored
    try db.registerAccess(to: Team.all())
}