BVB Source Codes

waterline Show update.js Source code

Return Download waterline: download update.js Source code - Download waterline Source code - Type:.js
  1. /**
  2.  * Module Dependencies
  3.  */
  4.  
  5. var util = require('util');
  6. var async = require('async');
  7. var _ = require('@sailshq/lodash');
  8. var flaverr = require('flaverr');
  9. var Deferred = require('../utils/query/deferred');
  10. var forgeStageTwoQuery = require('../utils/query/forge-stage-two-query');
  11. var forgeStageThreeQuery = require('../utils/query/forge-stage-three-query');
  12. var transformUniquenessError = require('../utils/query/transform-uniqueness-error');
  13. var processAllRecords = require('../utils/records/process-all-records');
  14.  
  15.  
  16. /**
  17.  * Update all records matching criteria
  18.  *
  19.  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  20.  * FUTURE: when time allows, update these fireworks up here to match the other methods
  21.  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  22.  *
  23.  * @param {Dictionary} criteria
  24.  * @param {Dictionary} valuesToSet
  25.  * @param {Function} done
  26.  * @returns Deferred object if no callback
  27.  */
  28.  
  29. module.exports = function update(criteria, valuesToSet, done, metaContainer) {
  30.  
  31.   // Set up a few, common local vars for convenience / familiarity.
  32.   var WLModel = this;
  33.   var orm = this.waterline;
  34.   var modelIdentity = this.identity;
  35.  
  36.  
  37.   // Build an omen.
  38.   //
  39.   // This Error instance is defined up here in order to grab a stack trace.
  40.   // (used for providing a better experience when viewing the stack trace of errors that come from
  41.   // one or more asynchronous ticks down the line; e.g. uniqueness errors)
  42.   //
  43.   // > Note that this can only be used once.
  44.   var omen = new Error('omen');
  45.   Error.captureStackTrace(omen, update);
  46.   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  47.   // FUTURE: do something fancier here to keep track of this so that it suppots both sorts of usages
  48.   // and does an even better job of reporting exactly where the error came from in userland code as
  49.   // the very first entry in the stack trace.  e.g.
  50.   // ```
  51.   // Error.captureStackTrace(omen, Deferred.prototype.exec);
  52.   // // ^^ but would need to pass through the original omen or something
  53.   // ```
  54.   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  55.  
  56.  
  57.   //  鈻堚枅鈺   鈻堚枅鈺 鈻堚枅鈻堚枅鈻堚晽 鈻堚枅鈻堚枅鈻堚枅鈺 鈻堚枅鈺 鈻堚枅鈻堚枅鈻堚晽 鈻堚枅鈻堚枅鈻堚枅鈺 鈻堚枅鈺 鈻堚枅鈻堚枅鈻堚枅鈺椻枅鈻堚枅鈻堚枅鈻堚枅鈺
  58.   //  鈻堚枅鈺   鈻堚枅鈺戔枅鈻堚晹鈺愨晲鈻堚枅鈺椻枅鈻堚晹鈺愨晲鈻堚枅鈺椻枅鈻堚晳鈻堚枅鈺斺晲鈺愨枅鈻堚晽鈻堚枅鈺斺晲鈺愨枅鈻堚晽鈻堚枅鈺戔枅鈻堚晹鈺愨晲鈺愨晲鈺濃枅鈻堚晹鈺愨晲鈺愨晲鈺
  59.   //  鈻堚枅鈺   鈻堚枅鈺戔枅鈻堚枅鈻堚枅鈻堚枅鈺戔枅鈻堚枅鈻堚枅鈻堚晹鈺濃枅鈻堚晳鈻堚枅鈻堚枅鈻堚枅鈻堚晳鈻堚枅鈺  鈻堚枅鈺戔枅鈻堚晳鈻堚枅鈺     鈻堚枅鈻堚枅鈻堚枅鈻堚晽
  60.   //  鈺氣枅鈻堚晽 鈻堚枅鈺斺暆鈻堚枅鈺斺晲鈺愨枅鈻堚晳鈻堚枅鈺斺晲鈺愨枅鈻堚晽鈻堚枅鈺戔枅鈻堚晹鈺愨晲鈻堚枅鈺戔枅鈻堚晳  鈻堚枅鈺戔枅鈻堚晳鈻堚枅鈺     鈺氣晲鈺愨晲鈺愨枅鈻堚晳
  61.   //   鈺氣枅鈻堚枅鈻堚晹鈺 鈻堚枅鈺  鈻堚枅鈺戔枅鈻堚晳  鈻堚枅鈺戔枅鈻堚晳鈻堚枅鈺  鈻堚枅鈺戔枅鈻堚枅鈻堚枅鈻堚晹鈺濃枅鈻堚晳鈺氣枅鈻堚枅鈻堚枅鈻堚晽鈻堚枅鈻堚枅鈻堚枅鈻堚晳
  62.   //    鈺氣晲鈺愨晲鈺  鈺氣晲鈺  鈺氣晲鈺濃暁鈺愨暆  鈺氣晲鈺濃暁鈺愨暆鈺氣晲鈺  鈺氣晲鈺濃暁鈺愨晲鈺愨晲鈺愨暆 鈺氣晲鈺 鈺氣晲鈺愨晲鈺愨晲鈺濃暁鈺愨晲鈺愨晲鈺愨晲鈺
  63.   //
  64.   // FUTURE: when time allows, update this to match the "VARIADICS" format
  65.   // used in the other model methods.
  66.  
  67.   if (typeof criteria === 'function') {
  68.     done = criteria;
  69.     criteria = null;
  70.   }
  71.  
  72.   //  鈻堚枅鈻堚枅鈻堚枅鈺 鈻堚枅鈻堚枅鈻堚枅鈻堚晽鈻堚枅鈻堚枅鈻堚枅鈻堚晽鈻堚枅鈻堚枅鈻堚枅鈻堚晽鈻堚枅鈻堚枅鈻堚枅鈺
  73.   //  鈻堚枅鈺斺晲鈺愨枅鈻堚晽鈻堚枅鈺斺晲鈺愨晲鈺愨暆鈻堚枅鈺斺晲鈺愨晲鈺愨暆鈻堚枅鈺斺晲鈺愨晲鈺愨暆鈻堚枅鈺斺晲鈺愨枅鈻堚晽
  74.   //  鈻堚枅鈺  鈻堚枅鈺戔枅鈻堚枅鈻堚枅鈺  鈻堚枅鈻堚枅鈻堚晽  鈻堚枅鈻堚枅鈻堚晽  鈻堚枅鈻堚枅鈻堚枅鈺斺暆
  75.   //  鈻堚枅鈺  鈻堚枅鈺戔枅鈻堚晹鈺愨晲鈺  鈻堚枅鈺斺晲鈺愨暆  鈻堚枅鈺斺晲鈺愨暆  鈻堚枅鈺斺晲鈺愨枅鈻堚晽
  76.   //  鈻堚枅鈻堚枅鈻堚枅鈺斺暆鈻堚枅鈻堚枅鈻堚枅鈻堚晽鈻堚枅鈺     鈻堚枅鈻堚枅鈻堚枅鈻堚晽鈻堚枅鈺  鈻堚枅鈺
  77.   //  鈺氣晲鈺愨晲鈺愨晲鈺 鈺氣晲鈺愨晲鈺愨晲鈺愨暆鈺氣晲鈺     鈺氣晲鈺愨晲鈺愨晲鈺愨暆鈺氣晲鈺  鈺氣晲鈺
  78.   //
  79.   //   鈻堚枅鈺椻枅鈻堚枅鈺   鈻堚枅鈻堚晽 鈻堚枅鈻堚枅鈻堚晽 鈻堚枅鈺   鈻堚枅鈺椻枅鈻堚枅鈻堚枅鈻堚晽 鈻堚枅鈻堚枅鈻堚枅鈻堚晽鈻堚枅鈺
  80.   //  鈻堚枅鈺斺暆鈻堚枅鈻堚枅鈺 鈻堚枅鈻堚枅鈺戔枅鈻堚晹鈺愨晲鈻堚枅鈺椻暁鈻堚枅鈺 鈻堚枅鈺斺暆鈻堚枅鈺斺晲鈺愨枅鈻堚晽鈻堚枅鈺斺晲鈺愨晲鈺愨暆鈺氣枅鈻堚晽
  81.   //  鈻堚枅鈺 鈻堚枅鈺斺枅鈻堚枅鈻堚晹鈻堚枅鈺戔枅鈻堚枅鈻堚枅鈻堚枅鈺 鈺氣枅鈻堚枅鈻堚晹鈺 鈻堚枅鈻堚枅鈻堚枅鈺斺暆鈻堚枅鈻堚枅鈻堚晽   鈻堚枅鈺
  82.   //  鈻堚枅鈺 鈻堚枅鈺戔暁鈻堚枅鈺斺暆鈻堚枅鈺戔枅鈻堚晹鈺愨晲鈻堚枅鈺  鈺氣枅鈻堚晹鈺  鈻堚枅鈺斺晲鈺愨枅鈻堚晽鈻堚枅鈺斺晲鈺愨暆   鈻堚枅鈺
  83.   //  鈺氣枅鈻堚晽鈻堚枅鈺 鈺氣晲鈺 鈻堚枅鈺戔枅鈻堚晳  鈻堚枅鈺   鈻堚枅鈺   鈻堚枅鈻堚枅鈻堚枅鈺斺暆鈻堚枅鈻堚枅鈻堚枅鈻堚晽鈻堚枅鈺斺暆
  84.   //   鈺氣晲鈺濃暁鈺愨暆     鈺氣晲鈺濃暁鈺愨暆  鈺氣晲鈺   鈺氣晲鈺   鈺氣晲鈺愨晲鈺愨晲鈺 鈺氣晲鈺愨晲鈺愨晲鈺愨暆鈺氣晲鈺
  85.   //
  86.   //  鈹屸攼 鈹 鈹敩鈹  鈹屸敩鈹   鈹   鈹攢鈹愨攲鈹€鈹愨攲鈹攼鈹 鈹敩鈹€鈹愨攲鈹愨攲  鈹屸攼鈹屸攲鈹€鈹愨敩 鈹  鈹屸敩鈹愨攲鈹€鈹愨攲鈹€鈹愨攲鈹€鈹愨敩鈹€鈹愨敩鈹€鈹愨攲鈹€鈹愨攲鈹攼
  87.   //  鈹溾敶鈹愨攤 鈹傗攤鈹   鈹傗攤  鈹屸敿鈹€  鈹溾敩鈹樷敎鈹  鈹 鈹 鈹傗敎鈹敇鈹傗攤鈹  鈹傗攤鈹傗敎鈹 鈹傗攤鈹   鈹傗攤鈹溾敜 鈹溾敜 鈹溾敜 鈹溾敩鈹樷敎鈹敇鈹溾敜  鈹傗攤
  88.   //  鈹斺攢鈹樷敂鈹€鈹樷敶鈹粹攢鈹樷攢鈹粹敇  鈹斺敇   鈹粹敂鈹€鈹斺攢鈹 鈹 鈹斺攢鈹樷敶鈹斺攢鈹樷敂鈹  鈹樷敂鈹樷敂鈹€鈹樷敂鈹粹敇  鈹€鈹粹敇鈹斺攢鈹樷敂  鈹斺攢鈹樷敶鈹斺攢鈹粹敂鈹€鈹斺攢鈹樷攢鈹粹敇
  89.   //  鈹屸攢    鈹攲鈹€鈹  鈹攢鈹愨攲鈹€鈹愨敩  鈹屸攢鈹愨敩  鈹攲鈹€鈹愨攲鈹愨攲鈹屸敩鈹    鈹€鈹
  90.   //  鈹傗攢鈹€鈹€  鈹傗敎鈹   鈹溾敩鈹樷敎鈹 鈹  鈹溾敜 鈹斺攼鈹屸敇鈹溾攢鈹も攤鈹傗攤 鈹   鈹€鈹€鈹€鈹
  91.   //  鈹斺攢    鈹粹敂    鈹粹敂鈹€鈹斺攢鈹樷敶鈹€鈹樷敂鈹€鈹 鈹斺敇 鈹 鈹粹敇鈹斺敇 鈹     鈹€鈹
  92.   // Return Deferred or pass to adapter
  93.   if (typeof done !== 'function') {
  94.     return new Deferred(WLModel, WLModel.update, {
  95.       method: 'update',
  96.       criteria: criteria,
  97.       valuesToSet: valuesToSet
  98.     });
  99.   }
  100.  
  101.   //  鈻堚枅鈻堚枅鈻堚枅鈻堚晽鈻堚枅鈺  鈻堚枅鈺椻枅鈻堚枅鈻堚枅鈻堚枅鈺 鈻堚枅鈻堚枅鈻堚枅鈺椻枅鈻堚晽   鈻堚枅鈺椻枅鈻堚枅鈻堚枅鈻堚枅鈻堚晽鈻堚枅鈻堚枅鈻堚枅鈻堚晽
  102.   //  鈻堚枅鈺斺晲鈺愨晲鈺愨暆鈺氣枅鈻堚晽鈻堚枅鈺斺暆鈻堚枅鈺斺晲鈺愨晲鈺愨暆鈻堚枅鈺斺晲鈺愨晲鈺愨暆鈻堚枅鈺   鈻堚枅鈺戔暁鈺愨晲鈻堚枅鈺斺晲鈺愨暆鈻堚枅鈺斺晲鈺愨晲鈺愨暆
  103.   //  鈻堚枅鈻堚枅鈻堚晽   鈺氣枅鈻堚枅鈺斺暆 鈻堚枅鈻堚枅鈻堚晽  鈻堚枅鈺     鈻堚枅鈺   鈻堚枅鈺   鈻堚枅鈺   鈻堚枅鈻堚枅鈻堚晽
  104.   //  鈻堚枅鈺斺晲鈺愨暆   鈻堚枅鈺斺枅鈻堚晽 鈻堚枅鈺斺晲鈺愨暆  鈻堚枅鈺     鈻堚枅鈺   鈻堚枅鈺   鈻堚枅鈺   鈻堚枅鈺斺晲鈺愨暆
  105.   //  鈻堚枅鈻堚枅鈻堚枅鈻堚晽鈻堚枅鈺斺暆 鈻堚枅鈺椻枅鈻堚枅鈻堚枅鈻堚枅鈺椻暁鈻堚枅鈻堚枅鈻堚枅鈺椻暁鈻堚枅鈻堚枅鈻堚枅鈺斺暆   鈻堚枅鈺   鈻堚枅鈻堚枅鈻堚枅鈻堚晽
  106.   //  鈺氣晲鈺愨晲鈺愨晲鈺愨暆鈺氣晲鈺  鈺氣晲鈺濃暁鈺愨晲鈺愨晲鈺愨晲鈺 鈺氣晲鈺愨晲鈺愨晲鈺 鈺氣晲鈺愨晲鈺愨晲鈺    鈺氣晲鈺   鈺氣晲鈺愨晲鈺愨晲鈺愨暆
  107.  
  108.   //  鈺斺晲鈺椻晹鈺愨晽鈺︹晲鈺椻晹鈺愨晽鈺斺晲鈺  鈹屸攢鈹愨攲鈹攼鈹屸攢鈹愨攲鈹€鈹愨攲鈹€鈹  鈹屸敩鈹愨敩 鈹攲鈹€鈹  鈹屸攢鈹 鈹 鈹攲鈹€鈹愨敩鈹€鈹愨敩 鈹
  109.   //  鈺犫暎 鈺 鈺戔暊鈺︹暆鈺 鈺︹晳鈺   鈹斺攢鈹 鈹 鈹溾攢鈹も攤 鈹敎鈹    鈹 鈹傗攤鈹傗攤 鈹  鈹傗攢鈹尖攼鈹 鈹傗敎鈹 鈹溾敩鈹樷敂鈹敇
  110.   //  鈺  鈺氣晲鈺濃暕鈺氣晲鈺氣晲鈺濃暁鈺愨暆  鈹斺攢鈹 鈹 鈹 鈹粹敂鈹€鈹樷敂鈹€鈹   鈹 鈹斺敶鈹樷敂鈹€鈹  鈹斺攢鈹樷敂鈹斺攢鈹樷敂鈹€鈹樷敶鈹斺攢 鈹
  111.   //
  112.   // Forge a stage 2 query (aka logical protostatement)
  113.   // This ensures a normalized format.
  114.   var query = {
  115.     method: 'update',
  116.     using: modelIdentity,
  117.     criteria: criteria,
  118.     valuesToSet: valuesToSet,
  119.     meta: metaContainer
  120.   };
  121.  
  122.   try {
  123.     forgeStageTwoQuery(query, orm);
  124.   } catch (e) {
  125.     switch (e.code) {
  126.       case 'E_INVALID_CRITERIA':
  127.         return done(
  128.           flaverr(
  129.             { name: 'UsageError' },
  130.             new Error(
  131.               'Invalid criteria.\n'+
  132.               'Details:\n'+
  133.               '  '+e.details+'\n'
  134.             )
  135.           )
  136.         );
  137.  
  138.       case 'E_INVALID_VALUES_TO_SET':
  139.         return done(
  140.           flaverr(
  141.             { name: 'UsageError' },
  142.             new Error(
  143.               'Cannot perform update with the provided values.\n'+
  144.               'Details:\n'+
  145.               '  '+e.details+'\n'
  146.             )
  147.           )
  148.         );
  149.  
  150.       case 'E_NOOP':
  151.         // Determine the appropriate no-op result.
  152.         // If `fetch` meta key is set, use `[]`-- otherwise use `undefined`.
  153.         //
  154.         // > Note that future versions might simulate output from the raw driver.
  155.         // > (e.g. `{ numRecordsUpdated: 0 }`)
  156.         // >  See: https://github.com/treelinehq/waterline-query-docs/blob/master/docs/results.md#update
  157.         var noopResult = undefined;
  158.         if (query.meta && query.meta.fetch) {
  159.           noopResult = [];
  160.         }//>-
  161.         return done(undefined, noopResult);
  162.  
  163.       default:
  164.         return done(e);
  165.     }
  166.   }
  167.  
  168.  
  169.   //  鈺 鈺︹晹鈺愨晽鈺斺晽鈺斺晹鈺︹晽鈺  鈺斺晲鈺         鈹  鈹攲鈹€鈹愨攲鈹€鈹愨攲鈹€鈹愨敩 鈹攲鈹€鈹愨敩  鈹屸攢鈹  鈹屸攢鈹愨攲鈹€鈹愨敩  鈹  鈹屸攼 鈹屸攢鈹愨攲鈹€鈹愨敩鈹屸攢
  170.   //  鈺犫晲鈺b暊鈺愨暎鈺戔晳鈺 鈺戔晳鈺  鈺戔暎   BEFORE 鈹  鈹傗敎鈹 鈹溾敜 鈹  鈹斺敩鈹樷攤  鈹  鈹溾敜   鈹  鈹溾攢鈹も攤  鈹  鈹溾敶鈹愨敎鈹€鈹も攤  鈹溾敶鈹
  171.   //  鈺 鈺┾暕 鈺┾暆鈺氣暆鈺愨暕鈺濃暕鈺愨暆鈺氣晲鈺         鈹粹攢鈹樷敶鈹  鈹斺攢鈹樷敂鈹€鈹 鈹 鈹斺攢鈹樷敶鈹€鈹樷敂鈹€鈹  鈹斺攢鈹樷敶 鈹粹敶鈹€鈹樷敶鈹€鈹樷敂鈹€鈹樷敶 鈹粹敂鈹€鈹樷敶 鈹
  172.   // Run the "before" lifecycle callback, if appropriate.
  173.   (function(proceed) {
  174.     // If the `skipAllLifecycleCallbacks` meta flag was set, don't run any of
  175.     // the methods.
  176.     if (_.has(query.meta, 'skipAllLifecycleCallbacks') && query.meta.skipAllLifecycleCallbacks) {
  177.       return proceed(undefined, query);
  178.     }
  179.  
  180.     if (!_.has(WLModel._callbacks, 'beforeUpdate')) {
  181.       return proceed(undefined, query);
  182.     }
  183.  
  184.     WLModel._callbacks.beforeUpdate(query.valuesToSet, function(err){
  185.       if (err) { return proceed(err); }
  186.       return proceed(undefined, query);
  187.     });
  188.  
  189.   })(function(err, query) {
  190.     if (err) {
  191.       return done(err);
  192.     }
  193.  
  194.     // ================================================================================
  195.     // FUTURE: potentially bring this back (but also would need the `omit clause`)
  196.     // ================================================================================
  197.     // // Before we get to forging again, save a copy of the stage 2 query's
  198.     // // `select` clause.  We'll need this later on when processing the resulting
  199.     // // records, and if we don't copy it now, it might be damaged by the forging.
  200.     // //
  201.     // // > Note that we don't need a deep clone.
  202.     // // > (That's because the `select` clause is only 1 level deep.)
  203.     // var s2QSelectClause = _.clone(query.criteria.select);
  204.     // ================================================================================
  205.  
  206.  
  207.     //  鈺斺晲鈺椻晹鈺愨晽鈺︹晲鈺椻晹鈺愨晽鈺斺晲鈺  鈹屸攢鈹愨攲鈹攼鈹屸攢鈹愨攲鈹€鈹愨攲鈹€鈹  鈹屸敩鈹愨敩 鈹敩鈹€鈹愨攲鈹€鈹愨攲鈹€鈹  鈹屸攢鈹 鈹 鈹攲鈹€鈹愨敩鈹€鈹愨敩 鈹
  208.     //  鈺犫暎 鈺 鈺戔暊鈺︹暆鈺 鈺︹晳鈺   鈹斺攢鈹 鈹 鈹溾攢鈹も攤 鈹敎鈹    鈹 鈹溾攢鈹も敎鈹敇鈹溾敜 鈹溾敜   鈹傗攢鈹尖攼鈹 鈹傗敎鈹 鈹溾敩鈹樷敂鈹敇
  209.     //  鈺  鈺氣晲鈺濃暕鈺氣晲鈺氣晲鈺濃暁鈺愨暆  鈹斺攢鈹 鈹 鈹 鈹粹敂鈹€鈹樷敂鈹€鈹   鈹 鈹 鈹粹敶鈹斺攢鈹斺攢鈹樷敂鈹€鈹  鈹斺攢鈹樷敂鈹斺攢鈹樷敂鈹€鈹樷敶鈹斺攢 鈹
  210.     // Now, destructively forge this S2Q into a S3Q.
  211.     try {
  212.       query = forgeStageThreeQuery({
  213.         stageTwoQuery: query,
  214.         identity: modelIdentity,
  215.         transformer: WLModel._transformer,
  216.         originalModels: orm.collections
  217.       });
  218.     } catch (e) { return done(e); }
  219.  
  220.  
  221.     //  鈹屸攢鈹愨攲鈹€鈹愨攲鈹愨攲鈹屸敩鈹  鈹屸敩鈹愨攲鈹€鈹  鈺斺晲鈺椻晹鈺︹晽鈺斺晲鈺椻晹鈺愨晽鈺斺暒鈺椻晹鈺愨晽鈺︹晲鈺
  222.     //  鈹斺攢鈹愨敎鈹 鈹傗攤鈹 鈹傗攤   鈹 鈹 鈹  鈺犫晲鈺 鈺戔晳鈺犫晲鈺b暊鈺愨暆 鈺 鈺戔暎 鈺犫暒鈺
  223.     //  鈹斺攢鈹樷敂鈹€鈹樷敇鈹斺敇鈹€鈹粹敇   鈹 鈹斺攢鈹  鈺 鈺┾晲鈺┾暆鈺 鈺┾暕   鈺 鈺氣晲鈺濃暕鈺氣晲
  224.     // Grab the appropriate adapter method and call it.
  225.     var adapter = WLModel._adapter;
  226.     if (!adapter.update) {
  227.       return done(new Error('Cannot complete query: The adapter used by this model (`' + modelIdentity + '`) doesn\'t support the `'+query.method+'` method.'));
  228.     }
  229.  
  230.     adapter.update(WLModel.datastore, query, function _afterTalkingToAdapter(err, rawAdapterResult) {
  231.       if (err) {
  232.         if (!_.isError(err)) {
  233.           return done(new Error(
  234.             'If an error is sent back from the adapter, it should always be an Error instance.  '+
  235.             'But instead, got: '+util.inspect(err, {depth:5})+''
  236.           ));
  237.         }//-鈥
  238.  
  239.         // Attach the identity of this model (for convenience).
  240.         err.modelIdentity = modelIdentity;
  241.  
  242.         // If this is a standardized, uniqueness constraint violation error, then standardize
  243.         // the error, mapping the `footprint.keys` (~=column names) back to attribute names,
  244.         // attaching toJSON(), adjusting the stack trace, etc.
  245.         if (err.footprint && err.footprint.identity === 'notUnique') {
  246.           err = transformUniquenessError(err, omen, modelIdentity, orm);
  247.         }//>-
  248.  
  249.         return done(err);
  250.       }//-鈥
  251.  
  252.  
  253.       //  鈺斺晲鈺椻晹鈺︹晽鈺斺晲鈺椻晹鈺愨晽  鈺斺晽鈺斺晹鈺愨晽鈺 鈺     鈹 鈹攲鈹愨攲鈹  鈹屸攢鈹愨攲鈹€鈹愨攲鈹€鈹  鈺斺晲鈺椻晹鈺愨晽鈺斺暒鈺椻晹鈺愨晽鈺 鈺  鈹屸敩鈹愨攲鈹€鈹愨攲鈹攼鈹屸攢鈹  鈹攲鈹€鈹屸攢鈹愨敩 鈹
  254.       //  鈺氣晲鈺 鈺 鈺 鈺戔暊鈺愨暆  鈺戔晳鈺戔晳 鈺戔晳鈺戔晳     鈹 鈹傗攤鈹傗攤鈹  鈹溾敜 鈹斺攢鈹愨敂鈹€鈹  鈺犫暎 鈺戔暎  鈺 鈺  鈺犫晲鈺  鈹傗攤鈹傗敎鈹  鈹 鈹溾攢鈹  鈹溾敶鈹愨敎鈹 鈹斺敩鈹
  255.       //  鈺氣晲鈺 鈺 鈺氣晲鈺濃暕    鈺濃暁鈺濃暁鈺愨暆鈺氣暕鈺漮oo  鈹斺攢鈹樷敇鈹斺敇鈹粹攢鈹樷敂鈹€鈹樷敂鈹€鈹樷敂鈹€鈹  鈺  鈺氣晲鈺 鈺 鈺氣晲鈺濃暕 鈺  鈹 鈹粹敂鈹€鈹 鈹 鈹 鈹  鈹 鈹粹敂鈹€鈹 鈹
  256.       //  鈹 鈹攲鈹€鈹愨攲鈹€鈹  鈹屸攢鈹愨攲鈹€鈹愨攲鈹攼  鈹屸敩鈹愨攲鈹€鈹  鈹屸敩鈹愨敩鈹€鈹愨敩 鈹攲鈹€鈹
  257.       //  鈹傗攤鈹傗敎鈹€鈹も敂鈹€鈹  鈹斺攢鈹愨敎鈹  鈹    鈹 鈹 鈹   鈹 鈹溾敩鈹樷攤 鈹傗敎鈹
  258.       //  鈹斺敶鈹樷敶 鈹粹敂鈹€鈹  鈹斺攢鈹樷敂鈹€鈹 鈹    鈹 鈹斺攢鈹   鈹 鈹粹敂鈹€鈹斺攢鈹樷敂鈹€鈹
  259.       // If `fetch` was not enabled, return.
  260.       if (!_.has(query.meta, 'fetch') || query.meta.fetch === false) {
  261.  
  262.         if (!_.isUndefined(rawAdapterResult) && _.isArray(rawAdapterResult)) {
  263.           console.warn('\n'+
  264.             'Warning: Unexpected behavior in database adapter:\n'+
  265.             'Since `fetch` is NOT enabled, this adapter (for datastore `'+WLModel.datastore+'`)\n'+
  266.             'should NOT have sent back anything as the 2nd argument when triggering the callback\n'+
  267.             'from its `update` method.  But it did!  And since it\'s an array, displaying this\n'+
  268.             'warning to help avoid confusion and draw attention to the bug.  Specifically, got:\n'+
  269.             util.inspect(rawAdapterResult, {depth:5})+'\n'+
  270.             '(Ignoring it and proceeding anyway...)'+'\n'
  271.           );
  272.         }//>-
  273.  
  274.         return done();
  275.  
  276.       }//-鈥
  277.  
  278.  
  279.       // IWMIH then we know that `fetch: true` meta key was set, and so the
  280.       // adapter should have sent back an array.
  281.  
  282.       // Verify that the raw result from the adapter is an array.
  283.       if (!_.isArray(rawAdapterResult)) {
  284.         return done(new Error(
  285.           'Unexpected behavior in database adapter: Since `fetch: true` was enabled, this adapter '+
  286.           '(for datastore `'+WLModel.datastore+'`) should have sent back an array of records as the 2nd argument when triggering '+
  287.           'the callback from its `update` method.  But instead, got: '+util.inspect(rawAdapterResult, {depth:5})+''
  288.         ));
  289.       }//-鈥
  290.  
  291.       // Unserialize each record
  292.       var transformedRecords;
  293.       try {
  294.         // Attempt to convert the column names in each record back into attribute names.
  295.         transformedRecords = rawAdapterResult.map(function(record) {
  296.           return WLModel._transformer.unserialize(record);
  297.         });
  298.       } catch (e) { return done(e); }
  299.  
  300.  
  301.       // Check the records to verify compliance with the adapter spec,
  302.       // as well as any issues related to stale data that might not have been
  303.       // been migrated to keep up with the logical schema (`type`, etc. in
  304.       // attribute definitions).
  305.       try {
  306.         processAllRecords(transformedRecords, query.meta, modelIdentity, orm);
  307.       } catch (e) { return done(e); }
  308.  
  309.  
  310.       //  鈺斺晲鈺椻晹鈺愨晽鈺斺暒鈺椻晹鈺愨晽鈺︹晲鈺  鈹 鈹攲鈹€鈹愨攲鈹攼鈹屸攢鈹愨攲鈹攼鈹屸攢鈹  鈹屸攢鈹愨攲鈹€鈹愨敩  鈹  鈹屸攼 鈹屸攢鈹愨攲鈹€鈹愨敩鈹屸攢
  311.       //  鈺犫晲鈺b暊鈺  鈺 鈺戔暎 鈺犫暒鈺  鈹 鈹傗敎鈹€鈹 鈹傗攤鈹溾攢鈹 鈹 鈹溾敜   鈹  鈹溾攢鈹も攤  鈹  鈹溾敶鈹愨敎鈹€鈹も攤  鈹溾敶鈹
  312.       //  鈺 鈺┾暁   鈺 鈺氣晲鈺濃暕鈺氣晲  鈹斺攢鈹樷敶  鈹€鈹粹敇鈹 鈹 鈹 鈹斺攢鈹  鈹斺攢鈹樷敶 鈹粹敶鈹€鈹樷敶鈹€鈹樷敂鈹€鈹樷敶 鈹粹敂鈹€鈹樷敶 鈹
  313.       // Run "after" lifecycle callback AGAIN and AGAIN- once for each record.
  314.       // ============================================================
  315.       // FUTURE: look into this
  316.       // (we probably shouldn't call this again and again--
  317.       // plus what if `fetch` is not in use and you want to use an LC?
  318.       // Then again- the right answer isn't immediately clear.  And it
  319.       // probably not worth breaking compatibility until we have a much
  320.       // better solution)
  321.       // ============================================================
  322.       async.each(transformedRecords, function _eachRecord(record, next) {
  323.  
  324.         // If the `skipAllLifecycleCallbacks` meta flag was set, don't run any of
  325.         // the methods.
  326.         if (_.has(query.meta, 'skipAllLifecycleCallbacks') && query.meta.skipAllLifecycleCallbacks) {
  327.           return next();
  328.         }
  329.  
  330.         // Skip "after" lifecycle callback, if not defined.
  331.         if (!_.has(WLModel._callbacks, 'afterUpdate')) {
  332.           return next();
  333.         }
  334.  
  335.         // Otherwise run it.
  336.         WLModel._callbacks.afterUpdate(record, function _afterMaybeRunningAfterUpdateForThisRecord(err) {
  337.           if (err) {
  338.             return next(err);
  339.           }
  340.  
  341.           return next();
  342.         });
  343.  
  344.       },// ~鈭?掳
  345.       function _afterIteratingOverRecords(err) {
  346.         if (err) {
  347.           return done(err);
  348.         }
  349.  
  350.         return done(undefined, transformedRecords);
  351.  
  352.       });//</ async.each() -- ran "after" lifecycle callback on each record >
  353.     });//</ adapter.update() >
  354.   });//</ "before" lifecycle callback >
  355. };
  356.  
downloadupdate.js Source code - Download waterline Source code
Related Source Codes/Software:
notepad-plus-plus - Notepad++ official repository h... 2017-01-10
che - Eclipse Che: Next-generation Eclipse IDE. Open sou... 2017-01-10
Gource - oftware version control visualization ... 2017-01-10
FDFullscreenPopGesture - A UINavigationController's category to enable full... 2017-01-10
node-style-guide - A guide for styling your node.js / JavaScript code... 2017-01-09
Workerman - An asynchronous event driven PHP framework for eas... 2017-01-10
structor - An advanced visual editor for React components ... 2017-01-10
golearn - Machine Learning for Go 2017-01-10
poisontap - Exploits locked/password protected computers over ... 2017-01-10
kcptun - A Simple UDP Tunnel Based On KCP 2017-01-11
GoSublime - A Golang plugin collection for SublimeText **3**, ... 2017-02-19
awesome-emacs - A community driven list of useful Emacs packages, ... 2017-02-19
RKNotificationHub - Make any UIView a full fledged notification center 2017-02-19
vimr - Project VimR - Refined Neovim experience for macOS... 2017-02-19
vue-admin - Vue Admin Panel Framework, Powered by Vue 2.0 and ... 2017-02-19
dev-setup - Mac OS X development environment setup: Easy-to-un... 2017-02-19
CMPopTipView - Custom UIView for iOS that pops up an animated "bu... 2017-02-19
git-recipes - Git for recipes in Chinese. The high quality of Gi... 2017-02-19
CLNDR - 2017-02-19
OptiKey - OptiKey - Full computer control and speech with yo... 2017-02-19

 Back to top