Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support allDocs(options) or maybe ICollectionRxOptions['pagination']? #50

Open
msyfls123 opened this issue Mar 1, 2023 · 1 comment

Comments

@msyfls123
Copy link

RxPouch/src/Collection.ts

Lines 179 to 190 in 31f412a

public async all() {
let endkey = this._docType + '-\uffff';
if (this._observableOptions.user) {
let user = await this._observableOptions.user.pipe(first(user => user as any)).toPromise();
endkey = this._docType + '-' + user + '\uffff'
}
let res = await this._pouchdb.allDocs({
startkey: this._docType,
endkey: endkey,
include_docs: true
});

RxPouch/src/Filter.ts

Lines 27 to 29 in 31f412a

public _init() {
this._docsSubject.next(this._getAllDocs());

It looks like that I have to load all documents with collection type into store & filter, it's a bit horrible!
May we can add such an count() method.
Besides that, I want to reserve the pagination feature.

I find out a simple but tricky solution:

  1. Add ICollectionRxOptions['pagination'] which represents pagination options accepted by allDocs.
  2. Copy & Paste Collection.all() to Collection.allDocs(options) and replace Colletion.loadDocs source with Collection.allDocs(options), we still need to call loadDocs with first ICollectionRxOptions['pagination'] value or startsWith {} at first.
  3. Pass Collection._allDocsSubject to filter, then subscribe it to Filter.filter().
  4. Subscribe to ICollectionRxOptions['pagination'] and call Collection._store.setDocs(res) to update store, and then the filter.

That's it.


Maybe some supported pagination related keys from allDocs options:

  • options.startkey & options.endkey: Get documents with IDs in a certain range (inclusive/inclusive).
  • options.inclusive_end: Include documents having an ID equal to the given options.endkey. Default: true.
  • options.limit: Maximum number of documents to return.
  • options.skip: Number of docs to skip before returning (warning: poor performance on IndexedDB/LevelDB!).
  • options.descending: Reverse the order of the output documents. Note that the order of startkey and endkey is reversed when descending:true.
@pablomaurer
Copy link
Owner

pablomaurer commented May 7, 2023

This project ist not really maintained anymore =) But feel free to create a PR or the project ^^

Or look at https://github.com/pubkey/rxdb maybe they got you covered..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants