/*** Generated by streamline 0.10.17 (callbacks) - DO NOT EDIT ***/ var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename, false),__func=__rt.__func,__cb=__rt.__cb,__catch=__rt.__catch,__tryCatch=__rt.__tryCatch; require("../lib/fakes");


function execWithin(query, tx, _) { var __frame = { name: "execWithin", line: 4 }; return __func(_, this, arguments, execWithin, 2, __frame, function __$execWithin() {
    return query.execWithin(tx, __cb(_, __frame, 1, 17, _, true)); });};


module.exports = function upload(stream, idOrPath, tag, _) { var queries, tx, i, len; var __frame = { name: "upload", line: 8 }; return __func(_, this, arguments, upload, 3, __frame, function __$upload() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$upload() {

          queries = new Array(global.parallelQueries);
          tx = db.begin();

          for (i = 0, len = queries.length; (i < len); ++i) {
            queries[i] = execWithin(FileVersion.insert({ index: i }), tx, false); };


          i = 0; len = queries.length; var __2 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$upload() { __more = false; if (__2) { ++i; } else { __2 = true; } ; var __1 = (i < len); if (__1) {
                return queries[i](__cb(_, __frame, 10, 12, function __$upload() { while (__more) { __loop(); }; __more = true; }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$upload() {


            tx.commit(); __then(); }); }); })(function ___(err, __result) { __catch(function __$upload() { if (err) {

            tx.rollback();
            return _(err); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$upload() { _(); }); }); });};
