> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pool.day/llms.txt
> Use this file to discover all available pages before exploring further.

# Live queries and changes

> Keep a screen fresh as the person takes new photos, or sync Pool's context into your own store.

## Live queries

```swift theme={null}
let grant = try await pool.authorization.requestAccess(
    AccessRequest(data: [.products], operations: [.query, .observe], purpose: "Keep your wishlist fresh")
)

for try await update in pool.context.observe(ContextQuery(types: [.product]), using: grant) {
    render(update.result.matches)
}
```

* The first update is the current answer. Later updates arrive when the index changes in a way the grant covers.
* The grant is checked again before every update. When it is revoked or expires, the stream ends by throwing that error.
* Cancel the task to stop observing.

## The change log

```swift theme={null}
var cursor = savedCursor  // nil the first time
var page: ChangePage
repeat {
    page = try await pool.context.changes(since: cursor, using: grant)
    for change in page.changes {
        switch change.operation {
        case .upsert: refresh(change.recordID)
        case .delete: remove(change.recordID)
        }
    }
    cursor = page.cursor
} while page.hasMore
save(cursor)
```

When a photo is deleted, everything derived from it is deleted and the log lists a tombstone for each removed record, with the cause: `sourceRemoved`, `accessRemoved` or `reset`. If you copy anything out of Pool, apply these deletes. The log only lists records your grant covers.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.