dist/packages/partitioning-adapter/lokidb.partitioning-adapter.js
/**
     * Used to sequentially load the next page of collection partition, one at a time.
     *
     * @returns {Promise} a Promise that resolves after the next page is loaded
     */
Used to sequentially load the next page of collection partition, one at a time.
@returns {Promise} a Promise that resolves after the next page is loaded
Used to sequentially load the next page of collection partition one at a time . @returns { Promise } a Promise that resolves after the next page is loaded
_loadNextPage() {
        const keyname = this._dbname + "." + this._pageIterator.collection + "." + this._pageIterator.pageIndex;
        return this._adapter.loadDatabase(keyname).then((result) => {
            let data = result.split(this._delimiter);
            result = ""; 
            let dlen = data.length;
            const isLastPage = (data[dlen - 1] === "");
            if (isLastPage) {
                data.pop();
                dlen = data.length;
                if (data[dlen - 1] === "" && dlen === 1) {
                    data.pop();
                    dlen = data.length;
                }
            }
            for (let idx = 0; idx < dlen; idx++) {
                this._dbref._collections[this._pageIterator.collection]._data.push(JSON.parse(data[idx]));
                data[idx] = null;
            }
            data = [];
            if (isLastPage) {
                if (++this._pageIterator.collection < this._dbref._collections.length) {
                    return this._loadNextPartition(this._pageIterator.collection);
                }
            }
            else {
                this._pageIterator.pageIndex++;
                return this._loadNextPage();
            }
            return Promise.resolve();
        });
    }
_loadNextPage ( ) { const keyname = this . _dbname + "." + this . _pageIterator . collection + "." + this . _pageIterator . pageIndex ; return this . _adapter . loadDatabase ( keyname ) . then ( ( result ) => { let data = result . split ( this . _delimiter ) ; result = "" ; let dlen = data . length ; const isLastPage = ( data [ dlen - 1 ] === "" ) ; if ( isLastPage ) { data . pop ( ) ; dlen = data . length ; if ( data [ dlen - 1 ] === "" && dlen === 1 ) { data . pop ( ) ; dlen = data . length ; } } for ( let idx = 0 ; idx < dlen ; idx ++ ) { this . _dbref . _collections [ this . _pageIterator . collection ] . _data . push ( JSON . parse ( data [ idx ] ) ) ; data [ idx ] = null ; } data = [ ] ; if ( isLastPage ) { if ( ++ this . _pageIterator . collection < this . _dbref . _collections . length ) { return this . _loadNextPartition ( this . _pageIterator . collection ) ; } } else { this . _pageIterator . pageIndex ++ ; return this . _loadNextPage ( ) ; } return Promise . resolve ( ) ; } ) ; }
Used to sequentially load the next page of collection partition, one at a time.
Used to sequentially load the next page of collection partition one at a time .
// calculate name for next saved page in sequence // load whatever page is next in sequence // free up memory now that we have split it into array // detect if last page by presence of final empty string element and remove it if so // empty collections are just a delimiter meaning two blank items // convert stringified array elements to object instances and push to collection data // if last page, we are done with this partition // if there are more partitions, kick off next partition load