WatermelonDB
WatermelonDB copied to clipboard
Observe ids
Discussed in https://github.com/Nozbe/WatermelonDB/discussions/1381
Originally posted by zhirzh August 28, 2022
An observable equivalent to fetchIds
that emits ids when records are added or removed. This behaviour can be achieved by chaining observeCount
with fetchIds
.
class Query {
...
observeIds(): Promise<RecordId[]> {
return this.observeCount().pipe(switchMap(() => this.fetchIds()))
}
}
Note that this implementation has followingcaveats:
- requires 2 database queries and data transfers over bridge
- no value is emitted if number of matching records remains unchanged even though matching records changed