rocicorp / replicache

Realtime Sync for Any Backend Stack
https://doc.replicache.dev
1.05k stars 37 forks source link

feat!: Expose a way to reuse ScanResult #926

Closed arv closed 2 years ago

arv commented 2 years ago

We now expose a method called makeScanResult. It takes a ScanOptions and a function that returns an async iterator.

makeScanResult({prefix: 'b'}, async function* (fromKey) {
  // yield ['a', 1];
  yield ['b', 2];
});

or when using an index:

makeScanResult(
  {prefix: 'b', indexName: 'i'},
  async function* (indexName, fromSecondaryKey, fromPrimaryKey) {
    // yield [['as', 'ap', 1];
    yield [['bs', 'bp', 2];
});

To make this work we moved the limit and exclusive handling to the top level iterator loop.

We now compute the fromKey and pass that into the iterator.

Fixes #607

vercel[bot] commented 2 years ago

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/rocicorp/replicache/8chQ5VgV4wGA7PtkpjeXkcyiX53T
✅ Preview: https://replicache-git-arv-scan-interface-rocicorp.vercel.app