UNPKG

sql-client

Version:

A dirt-simple SQL client abstraction (currently) supporting PostgreSQL, MySQL and SQLite.

96 lines (87 loc) 2.58 kB
// Generated by CoffeeScript 2.6.0 (function() { var Util; Util = class Util { constructor() { this.merge = this.merge.bind(this); //----------------------------------------------------------------------------# this.handle_error = this.handle_error.bind(this); //----------------------------------------------------------------------------# this.for_async = this.for_async.bind(this); this.for_each_async = this.for_each_async.bind(this); } merge(...objs) { var j, len, obj, result; result = {}; for (j = 0, len = objs.length; j < len; j++) { obj = objs[j]; result = Object.assign(result, obj); } return result; } handle_error(err, callback, throw_when_no_callback = true) { if (throw_when_no_callback == null) { throw_when_no_callback = true; } if (err != null) { if (callback != null) { callback(err); return true; } else if (throw_when_no_callback) { throw err; } else { return console.error("ERROR", err); } } else { return false; } } for_async(initialize, condition, action, increment, options, whendone) { var looper, results, timeout; if (typeof options === "function" && (whendone == null)) { whendone = options; options = void 0; } timeout = options != null ? options.timeout : void 0; results = []; looper = function() { if (condition()) { return action(function(...response) { results.push(response); increment(); return looper(); }); } else { if (whendone != null) { return whendone(void 0, results); } } }; initialize(); return looper(); } for_each_async(list, action, options, whendone) { var act, cond, i, incr, init; if (typeof options === "function" && (whendone == null)) { whendone = options; options = void 0; } i = null; init = function() { return i = 0; }; cond = function() { return i < list.length; }; incr = function() { return i += 1; }; act = function(next) { return action(list[i], i, list, next); }; return this.for_async(init, cond, act, incr, whendone); } }; //----------------------------------------------------------------------------# module.exports.Util = new Util(); }).call(this);