dist/packages/partitioning-adapter/lokidb.partitioning-adapter.js
/**
     * Helper method used internally to generate and save the next page of the current (dirty) partition.
     *
     * @returns {Promise} a Promise that resolves after the next partition is saved
     */
Helper method used internally to generate and save the next page of the current (dirty) partition.
@returns {Promise} a Promise that resolves after the next partition is saved
Helper method used internally to generate and save the next page of the current ( dirty ) partition . @returns { Promise } a Promise that resolves after the next partition is saved
_saveNextPage() {
        const coll = this._dbref._collections[this._pageIterator.collection];
        const keyname = this._dbname + "." + this._pageIterator.collection + "." + this._pageIterator.pageIndex;
        let pageLen = 0;
        const cdlen = coll._data.length;
        const delimlen = this._delimiter.length;
        let serializedObject = "";
        let pageBuilder = "";
        let doneWithPartition = false;
        let doneWithPage = false;
        const pageSaveCallback = () => {
            pageBuilder = "";
            if (!doneWithPartition) {
                this._pageIterator.pageIndex++;
                return this._saveNextPage();
            }
            return Promise.resolve();
        };
        if (coll._data.length === 0) {
            doneWithPartition = true;
        }
        while (!doneWithPartition && !doneWithPage) {
            if (!doneWithPartition) {
                serializedObject = JSON.stringify(coll._data[this._pageIterator.docIndex]);
                pageBuilder += serializedObject;
                pageLen += serializedObject.length;
                if (++this._pageIterator.docIndex >= cdlen)
                    doneWithPartition = true;
            }
            if (pageLen >= this._pageSize)
                doneWithPage = true;
            if (!doneWithPage || doneWithPartition) {
                pageBuilder += this._delimiter;
                pageLen += delimlen;
            }
        }
        return this._adapter.saveDatabase(keyname, pageBuilder).then(pageSaveCallback);
    }
_saveNextPage ( ) { const coll = this . _dbref . _collections [ this . _pageIterator . collection ] ; const keyname = this . _dbname + "." + this . _pageIterator . collection + "." + this . _pageIterator . pageIndex ; let pageLen = 0 ; const cdlen = coll . _data . length ; const delimlen = this . _delimiter . length ; let serializedObject = "" ; let pageBuilder = "" ; let doneWithPartition = false ; let doneWithPage = false ; const pageSaveCallback = ( ) => { pageBuilder = "" ; if ( ! doneWithPartition ) { this . _pageIterator . pageIndex ++ ; return this . _saveNextPage ( ) ; } return Promise . resolve ( ) ; } ; if ( coll . _data . length === 0 ) { doneWithPartition = true ; } while ( ! doneWithPartition && ! doneWithPage ) { if ( ! doneWithPartition ) { serializedObject = JSON . stringify ( coll . _data [ this . _pageIterator . docIndex ] ) ; pageBuilder += serializedObject ; pageLen += serializedObject . length ; if ( ++ this . _pageIterator . docIndex >= cdlen ) doneWithPartition = true ; } if ( pageLen >= this . _pageSize ) doneWithPage = true ; if ( ! doneWithPage || doneWithPartition ) { pageBuilder += this . _delimiter ; pageLen += delimlen ; } } return this . _adapter . saveDatabase ( keyname , pageBuilder ) . then ( pageSaveCallback ) ; }
Helper method used internally to generate and save the next page of the current (dirty) partition.
Helper method used internally to generate and save the next page of the current ( dirty ) partition .
// update meta properties then continue process by invoking callback // serialize object // if no more documents in collection to add, we are done with partition // if our current page is bigger than defined pageSize, we are done with page // if not done with current page, need delimiter before next item // if done with partition we also want a delmiter to indicate 'end of pages' final empty row // if we are done with page save it and pass off to next recursive call or callback