classes/table.js
/**
     * Call persistent data update functions
     * @param callback
     */
Call persistent data update functions
@param callback
Call persistent data update functions @param callback
updatePersistent(callback) {
        const self = this;
        if ((!_.isEmpty(self.persistent) || !_.isEmpty(self.persistentAssoc)) && self.persistentUpdatesSuspended === 0) {
            self.suspendPersistentUpdates();
            async.waterfall([
                function(next) {
                    if (self.persistent) {
                        async.forEachOf(self.persistent, function(persistent, key, next_persistent) {
                            if (_.isFunction(persistent)) {
                                const func = persistent.bind(self);
                                func(function(err, data) {
                                    self.p[key] = data || false;
                                    self[key] = (function(key) {
                                        return function(id) {
                                            return self.p[key][id]
                                        };
                                    })(key);
                                    next_persistent(err);
                                });
                            } else {
                                if (_.isString(persistent)) {
                                    persistent = {
                                        'mode': self.PERSISTENT_MODE_ASSOC,
                                        'collect_by': persistent
                                    }
                                }
                                if (_.isObject(persistent)) {
                                    if (!_.isString(persistent.mode)) {
                                        console.log(`Incorrect persistent description for ${self.name}: ${key} (mode is missing or not a string):`);
                                        return next_persistent({error: `Incorrect persistent description for ${self.name}: ${key} (mode is missing or not a string):`, persistent: persistent});
                                    }
                                    async.waterfall([
                                        function(persistent_next_step) {
                                            self.list(persistent.filters || {}, persistent_next_step);
                                        },
                                        function(rows, persistent_next_step) {
                                            let pdata = {}; 
                                            if (_.isFunction(self.persistentHandlers[persistent.mode])) {
                                                pdata = self.persistentHandlers[persistent.mode](persistent, rows, self);
                                            }  else {
                                                console.log(`Incorrect persistent description for ${self.name}: ${key} (unknown mode: "${persistent.mode}"):`);
                                                return persistent_next_step({error: `Incorrect persistent description for ${self.name}: ${key} (unknown mode: "${persistent.mode}"):`, persistent: persistent});
                                            }
                                            self.p[persistent.key || key] = pdata;
                                            if (!persistent.no_function) {
                                                self[persistent.getter_name || key] =
                                                    _.isFunction(persistent.getter) ?  persistent.getter :
                                                        (function (key) {
                                                            return function (id) {
                                                                return self.p[key][id]
                                                            };
                                                        })(key);
                                            }
                                            persistent_next_step();
                                        }
                                    ], next_persistent);
                                } else {
                                    console.log(`Incorrect persistent description for ${self.name}: ${key}:`, persistent);
                                    next_persistent({error: `Incorrect persistent description for ${self.name}: ${key}:`, persistent: persistent});
                                }
                            }
                        }, next)
                    } else next();
                }
            ], function(err) {
                self.resumePersistentUpdates(null, true);
                callback(err);
            });
        } else callback();
    }
updatePersistent ( callback ) { const self = this ; if ( ( ! _ . isEmpty ( self . persistent ) || ! _ . isEmpty ( self . persistentAssoc ) ) && self . persistentUpdatesSuspended === 0 ) { self . suspendPersistentUpdates ( ) ; async . waterfall ( [ function ( next ) { if ( self . persistent ) { async . forEachOf ( self . persistent , function ( persistent , key , next_persistent ) { if ( _ . isFunction ( persistent ) ) { const func = persistent . bind ( self ) ; func ( function ( err , data ) { self . p [ key ] = data || false ; self [ key ] = ( function ( key ) { return function ( id ) { return self . p [ key ] [ id ] } ; } ) ( key ) ; next_persistent ( err ) ; } ) ; } else { if ( _ . isString ( persistent ) ) { persistent = { 'mode' : self . PERSISTENT_MODE_ASSOC , 'collect_by' : persistent } } if ( _ . isObject ( persistent ) ) { if ( ! _ . isString ( persistent . mode ) ) { console . log ( ` ${ self . name } ${ key } ` ) ; return next_persistent ( { error : ` ${ self . name } ${ key } ` , persistent : persistent } ) ; } async . waterfall ( [ function ( persistent_next_step ) { self . list ( persistent . filters || { } , persistent_next_step ) ; } , function ( rows , persistent_next_step ) { let pdata = { } ; if ( _ . isFunction ( self . persistentHandlers [ persistent . mode ] ) ) { pdata = self . persistentHandlers [ persistent . mode ] ( persistent , rows , self ) ; } else { console . log ( ` ${ self . name } ${ key } ${ persistent . mode } ` ) ; return persistent_next_step ( { error : ` ${ self . name } ${ key } ${ persistent . mode } ` , persistent : persistent } ) ; } self . p [ persistent . key || key ] = pdata ; if ( ! persistent . no_function ) { self [ persistent . getter_name || key ] = _ . isFunction ( persistent . getter ) ? persistent . getter : ( function ( key ) { return function ( id ) { return self . p [ key ] [ id ] } ; } ) ( key ) ; } persistent_next_step ( ) ; } ] , next_persistent ) ; } else { console . log ( ` ${ self . name } ${ key } ` , persistent ) ; next_persistent ( { error : ` ${ self . name } ${ key } ` , persistent : persistent } ) ; } } } , next ) } else next ( ) ; } ] , function ( err ) { self . resumePersistentUpdates ( null , true ) ; callback ( err ) ; } ) ; } else callback ( ) ; }
Call persistent data update functions
 @param callback
Call persistent data update functions @param callback
//persistent data