lib/adapter.js
function(connectionName, table, options, data, cb) {
            if (LOG_DEBUG) {
                console.log("BEGIN update");
            }
            //LIMIT in a oracle UPDATE command is not valid
            if (hop(options, 'limit')) {
                return cb(new Error('Your \'LIMIT ' + options.limit + '\' is not allowed in the Oracle DB UPDATE query.'));
            }
            
            var connectionObject = connections[connectionName];
            var collection = connectionObject.collections[table];

            var _schema = connectionObject.schema;
            var processor = new Processor(_schema);

            // Mixin WL Next connection overrides to sqlOptions
            var overrides = connectionOverrides[connectionName] || {};
            var _options = _.cloneDeep(sqlOptions);
            if (hop(overrides, 'wlNext')) {
                _options.wlNext = overrides.wlNext;
            }

            var sequel = new Sequel(_schema, _options);
            var query;
            // Build a query for the specific query strategy
            try {
                query = sequel.update(table, options, data);
            } catch (e) {
                return cb(e);
            }

            query.query = query.query.replace('RETURNING *', '');
            query.query = query.query.replace( /\$/g, ':');
            query.query = query.query.replace(' AS ', " ");
 
            var keys = Object.keys(data);
            var j = 1;
            for (j; j < keys.length + 1; j++) {
                query.query = query.query.replace(":" + j, ":" + keys[j - 1]);
            }
            
            var keysoptions = Object.keys(options.where);
            var oraOptions = {where: {}};
            for(var k=0; k <keysoptions.length; k++){
                oraOptions.where[ "where"+keysoptions[k] ] = options.where[ keysoptions[k] ];
                data["where"+keysoptions[k]] = options.where[ keysoptions[k] ];
            }
            var keysoptions = Object.keys(oraOptions.where);
            for (var z = keys.length; z < keys.length + keysoptions.length + 1; z++) {
                query.query = query.query.replace(":" + z, ":" + keysoptions[z - 1 - keys.length]);
            }
            
            // Run Query
            connectionObject.pool.getConnection(
                    function (err, connection)
                    {
                        if (err) {
                            handleQueryError(err, 'create');
                            return;
                        }
                        if (LOG_QUERIES) {
                            console.log('Executing query: ' + query.query);
                        }
                        connection.execute(query.query, data, {/*outFormat: oracledb.OBJECT, */autoCommit: false}, function __CREATE__(err, result) {

                            if (err) {
                                // Release the connection back to the connection pool
                                return connection.rollback(function(rollerr) {
                                	doRelease(connection);
                                	return cb(handleQueryError(err, 'update'));
                                });
                            }
                            
                            // Build a query for the specific query strategy
                            try {
                                var _seqQuery = sequel.find(table, options);
                            } catch (e) {
                                return cb(handleQueryError(e, 'update'));
                            }

                            var findQuery = _seqQuery.query[0];
                            findQuery = findQuery.split( /\$/g).join(":");
                            findQuery = findQuery.split(" AS ").join(" ");

                            var keysOptionsSelect = Object.keys(oraOptions.where);
                            for (var z = 1; z < keysOptionsSelect.length + 1; z++) {
                                findQuery = findQuery.replace(":" + z, ":" + keysOptionsSelect[z-1]);
                            }
                            
                            connection.execute(findQuery, oraOptions.where,  {outFormat: oracledb.OBJECT}, function __CREATE_SELECT__(err, result){
                                
                                if (err){
                                    // Release the connection back to the connection pool
                                    return connection.rollback(function(rollerr) {
                                    	doRelease(connection);
                                    	return cb(handleQueryError(err, 'update_select'));
                                    });
                                }

                                // Cast special values
                                var values = [];
                                result.rows.forEach(function (row) {
                                    values.push(processor.cast(table, _.omit(row, 'LINE_NUMBER')));
                                });
                                
                                connection.commit(function (err){
                                    
                                    // Release the connection back to the connection pool
                                    doRelease(connection);
                                    if (err){
                                        return cb(handleQueryError(err, 'update_commit')); 
                                    }
                                    
                                    cb(null, values);
                                });
                            });
                        });
                    });

          

        }
function(connectionName, table, options, data, cb) {
            if (LOG_DEBUG) {
                console.log("BEGIN update");
            }
            //LIMIT in a oracle UPDATE command is not valid
            if (hop(options, 'limit')) {
                return cb(new Error('Your \'LIMIT ' + options.limit + '\' is not allowed in the Oracle DB UPDATE query.'));
            }
            
            var connectionObject = connections[connectionName];
            var collection = connectionObject.collections[table];

            var _schema = connectionObject.schema;
            var processor = new Processor(_schema);

            // Mixin WL Next connection overrides to sqlOptions
            var overrides = connectionOverrides[connectionName] || {};
            var _options = _.cloneDeep(sqlOptions);
            if (hop(overrides, 'wlNext')) {
                _options.wlNext = overrides.wlNext;
            }

            var sequel = new Sequel(_schema, _options);
            var query;
            // Build a query for the specific query strategy
            try {
                query = sequel.update(table, options, data);
            } catch (e) {
                return cb(e);
            }

            query.query = query.query.replace('RETURNING *', '');
            query.query = query.query.replace( /\$/g, ':');
            query.query = query.query.replace(' AS ', " ");
 
            var keys = Object.keys(data);
            var j = 1;
            for (j; j < keys.length + 1; j++) {
                query.query = query.query.replace(":" + j, ":" + keys[j - 1]);
            }
            
            var keysoptions = Object.keys(options.where);
            var oraOptions = {where: {}};
            for(var k=0; k <keysoptions.length; k++){
                oraOptions.where[ "where"+keysoptions[k] ] = options.where[ keysoptions[k] ];
                data["where"+keysoptions[k]] = options.where[ keysoptions[k] ];
            }
            var keysoptions = Object.keys(oraOptions.where);
            for (var z = keys.length; z < keys.length + keysoptions.length + 1; z++) {
                query.query = query.query.replace(":" + z, ":" + keysoptions[z - 1 - keys.length]);
            }
            
            // Run Query
            connectionObject.pool.getConnection(
                    function (err, connection)
                    {
                        if (err) {
                            handleQueryError(err, 'create');
                            return;
                        }
                        if (LOG_QUERIES) {
                            console.log('Executing query: ' + query.query);
                        }
                        connection.execute(query.query, data, {/*outFormat: oracledb.OBJECT, */autoCommit: false}, function __CREATE__(err, result) {

                            if (err) {
                                // Release the connection back to the connection pool
                                return connection.rollback(function(rollerr) {
                                	doRelease(connection);
                                	return cb(handleQueryError(err, 'update'));
                                });
                            }
                            
                            // Build a query for the specific query strategy
                            try {
                                var _seqQuery = sequel.find(table, options);
                            } catch (e) {
                                return cb(handleQueryError(e, 'update'));
                            }

                            var findQuery = _seqQuery.query[0];
                            findQuery = findQuery.split( /\$/g).join(":");
                            findQuery = findQuery.split(" AS ").join(" ");

                            var keysOptionsSelect = Object.keys(oraOptions.where);
                            for (var z = 1; z < keysOptionsSelect.length + 1; z++) {
                                findQuery = findQuery.replace(":" + z, ":" + keysOptionsSelect[z-1]);
                            }
                            
                            connection.execute(findQuery, oraOptions.where,  {outFormat: oracledb.OBJECT}, function __CREATE_SELECT__(err, result){
                                
                                if (err){
                                    // Release the connection back to the connection pool
                                    return connection.rollback(function(rollerr) {
                                    	doRelease(connection);
                                    	return cb(handleQueryError(err, 'update_select'));
                                    });
                                }

                                // Cast special values
                                var values = [];
                                result.rows.forEach(function (row) {
                                    values.push(processor.cast(table, _.omit(row, 'LINE_NUMBER')));
                                });
                                
                                connection.commit(function (err){
                                    
                                    // Release the connection back to the connection pool
                                    doRelease(connection);
                                    if (err){
                                        return cb(handleQueryError(err, 'update_commit')); 
                                    }
                                    
                                    cb(null, values);
                                });
                            });
                        });
                    });

          

        }
function ( connectionName , table , options , data , cb ) { if ( LOG_DEBUG ) { console . log ( "BEGIN update" ) ; } //LIMIT in a oracle UPDATE command is not valid if ( hop ( options , 'limit' ) ) { return cb ( new Error ( 'Your \'LIMIT ' + options . limit + '\' is not allowed in the Oracle DB UPDATE query.' ) ) ; } var connectionObject = connections [ connectionName ] ; var collection = connectionObject . collections [ table ] ; var _schema = connectionObject . schema ; var processor = new Processor ( _schema ) ; // Mixin WL Next connection overrides to sqlOptions var overrides = connectionOverrides [ connectionName ] || { } ; var _options = _ . cloneDeep ( sqlOptions ) ; if ( hop ( overrides , 'wlNext' ) ) { _options . wlNext = overrides . wlNext ; } var sequel = new Sequel ( _schema , _options ) ; var query ; // Build a query for the specific query strategy try { query = sequel . update ( table , options , data ) ; } catch ( e ) { return cb ( e ) ; } query . query = query . query . replace ( 'RETURNING *' , '' ) ; query . query = query . query . replace ( / \$ / g , ':' ) ; query . query = query . query . replace ( ' AS ' , " " ) ; var keys = Object . keys ( data ) ; var j = 1 ; for ( j ; j < keys . length + 1 ; j ++ ) { query . query = query . query . replace ( ":" + j , ":" + keys [ j - 1 ] ) ; } var keysoptions = Object . keys ( options . where ) ; var oraOptions = { where : { } } ; for ( var k = 0 ; k < keysoptions . length ; k ++ ) { oraOptions . where [ "where" + keysoptions [ k ] ] = options . where [ keysoptions [ k ] ] ; data [ "where" + keysoptions [ k ] ] = options . where [ keysoptions [ k ] ] ; } var keysoptions = Object . keys ( oraOptions . where ) ; for ( var z = keys . length ; z < keys . length + keysoptions . length + 1 ; z ++ ) { query . query = query . query . replace ( ":" + z , ":" + keysoptions [ z - 1 - keys . length ] ) ; } // Run Query connectionObject . pool . getConnection ( function ( err , connection ) { if ( err ) { handleQueryError ( err , 'create' ) ; return ; } if ( LOG_QUERIES ) { console . log ( 'Executing query: ' + query . query ) ; } connection . execute ( query . query , data , { /*outFormat: oracledb.OBJECT, */ autoCommit : false } , function __CREATE__ ( err , result ) { if ( err ) { // Release the connection back to the connection pool return connection . rollback ( function ( rollerr ) { doRelease ( connection ) ; return cb ( handleQueryError ( err , 'update' ) ) ; } ) ; } // Build a query for the specific query strategy try { var _seqQuery = sequel . find ( table , options ) ; } catch ( e ) { return cb ( handleQueryError ( e , 'update' ) ) ; } var findQuery = _seqQuery . query [ 0 ] ; findQuery = findQuery . split ( / \$ / g ) . join ( ":" ) ; findQuery = findQuery . split ( " AS " ) . join ( " " ) ; var keysOptionsSelect = Object . keys ( oraOptions . where ) ; for ( var z = 1 ; z < keysOptionsSelect . length + 1 ; z ++ ) { findQuery = findQuery . replace ( ":" + z , ":" + keysOptionsSelect [ z - 1 ] ) ; } connection . execute ( findQuery , oraOptions . where , { outFormat : oracledb . OBJECT } , function __CREATE_SELECT__ ( err , result ) { if ( err ) { // Release the connection back to the connection pool return connection . rollback ( function ( rollerr ) { doRelease ( connection ) ; return cb ( handleQueryError ( err , 'update_select' ) ) ; } ) ; } // Cast special values var values = [ ] ; result . rows . forEach ( function ( row ) { values . push ( processor . cast ( table , _ . omit ( row , 'LINE_NUMBER' ) ) ) ; } ) ; connection . commit ( function ( err ) { // Release the connection back to the connection pool doRelease ( connection ) ; if ( err ) { return cb ( handleQueryError ( err , 'update_commit' ) ) ; } cb ( null , values ) ; } ) ; } ) ; } ) ; } ) ; }
Update one or more models in the collection - PENDIENTE
Update one or more models in the collection - PENDIENTE