-- list all global variables
SHOW GLOBAL VARIABLES WHERE Variable_name = 'sql_mode'
..get sql_mode
value - remove ONLY_FULL_GROUP_BY
-- save `sql_mode` new value
SET GLOBAL sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
must reconnect to work!
Extended implementation that allows functions to pass a varying number of arguments along.
function waterfall(tasks, cb) {
cb = cb || function() {};
// support for arbitrary # of arguments passed along by functions
var data = Array.prototype.slice.call(arguments, 2);
if (!Array.isArray(tasks)) {
return cb('tasks must be an array');
}
// check if there are functions left
if (!tasks[0]) {
// avoid race condition with
if (data.length > 1) {
cb(null, data);
} else {
cb(null, data[0]);
}
return;
}
// process the next function
var next = tasks[0];
data.push(function(err) {
if (err) {
return cb(err);
}
// build the args for waterfall...
var args = [];
// remaining functions
args.push(tasks.slice(1));
// final waterfall callback
args.push(cb);
// arbitrary # of args for next function
args.push.apply(args, Array.prototype.slice.call(arguments, 1));
process.nextTick(function() {
waterfall.apply(null, args);
});
});
next.apply(null, data);
};
// test
waterfall([
function(next) {
console.log('1st');
setTimeout(next, 1000);
},
function(next) {
console.log('2nd');
setTimeout(next, 1000);
},
function(next) {
console.log('3rd');
setTimeout(next, 1000);
},
function(next) {
console.log('4th');
next(null, 'Hello!');
},
], function(err, res) {
console.log(err, res);
});
function waterfall(arr, cb) {
var fns = arr.slice(1);
if (!arr[0]) {
process.nextTick(function() {
cb(null);
});
return;
}
var first = arr[0];
first(function(err, data) {
if(err) {
return cb(err);
}
waterfall(fns, cb, data);
});
}
waterfall([
function(next) {
console.log('1st');
setTimeout(next, 1000);
},
function(next) {
console.log('2nd');
setTimeout(next, 1000);
},
function(next) {
console.log('3rd');
setTimeout(next, 1000);
},
function(next) {
console.log('4th');
setTimeout(next, 1000);
},
], function(err) {
console.log(err);
});
no nodejs
environment helper
var process = {nextTick:function(fn){ setTimeout(fn); }};
UPDATE: 2021-10-27
/* jshint esversion:6 */
const get = function (url) {
// return new pending promise
return new Promise((resolve, reject) => {
// select http or https module, depending on reqested url
const lib = url.startsWith('https') ? require('https') : require('http');
const request = lib.get(url, (response) => {
// handle http errors
if (response.statusCode < 200 || response.statusCode > 299) {
reject(new Error('Failed to load page, status code: ' + response.statusCode));
}
// temporary data holder
const body = [];
// on every content chunk, push it to the data array
response.on('data', (chunk) => body.push(chunk));
// we are done, resolve promise with those joined chunks
response.on('end', () => resolve(body.join('')));
});
// handle connection errors of the request
request.on('error', (err) => reject(err))
})
};
get('https://httpbin.org/get')
.then((body) => console.log(body))
.catch((err) => console.log(err));