src/batoh.js
function(storeName, value, key, cb) {
    // For usage of out-of-line keys a `key` argument have to be specified,
    // otherwise the `request` will be made assuming in-line key or key generator.
    // For detailed possibilities see what you can't do in `DataError` section here:
    // `https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore.add#Exceptions`
    var data = {};
    if (arguments.length === 4) {
      if (!Array.isArray(key)) {
        data.key = [key];
      } else {
        data.key = key;
      }
    }
    if (arguments.length === 3) {
      cb = key;
      key = null;
    }
    if (!Array.isArray(value)) {
      data.value = [value];
    } else {
      data.value = value;
    }

    var result = [];
    var transaction = this.transaction(storeName, MODE.READ_WRITE, result, cb);
    var store = this.store(storeName, transaction, cb);
    var _add = function(value, key) {
      var request;
      try {
        request = store.add(value, key);
      } catch (err) {
        if (isFunction(cb)) return cb(err);
      }
      request.onsuccess = function(event) {
        result.push(event.target.result);
      };
      request.onerror = function(event) {
        if (isFunction(cb)) return cb(event.target.error);
      };
    };
    for (var i = 0, l = data.value.length; i < l ; i++) {
      // In-line key
      if (!data.key) {
        _add(data.value[i]);
      // Out-of-line key
      } else {
        _add(data.value[i], data.key[i]);
      }
    }
  }
function(storeName, value, key, cb) {
    // For usage of out-of-line keys a `key` argument have to be specified,
    // otherwise the `request` will be made assuming in-line key or key generator.
    // For detailed possibilities see what you can't do in `DataError` section here:
    // `https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore.add#Exceptions`
    var data = {};
    if (arguments.length === 4) {
      if (!Array.isArray(key)) {
        data.key = [key];
      } else {
        data.key = key;
      }
    }
    if (arguments.length === 3) {
      cb = key;
      key = null;
    }
    if (!Array.isArray(value)) {
      data.value = [value];
    } else {
      data.value = value;
    }

    var result = [];
    var transaction = this.transaction(storeName, MODE.READ_WRITE, result, cb);
    var store = this.store(storeName, transaction, cb);
    var _add = function(value, key) {
      var request;
      try {
        request = store.add(value, key);
      } catch (err) {
        if (isFunction(cb)) return cb(err);
      }
      request.onsuccess = function(event) {
        result.push(event.target.result);
      };
      request.onerror = function(event) {
        if (isFunction(cb)) return cb(event.target.error);
      };
    };
    for (var i = 0, l = data.value.length; i < l ; i++) {
      // In-line key
      if (!data.key) {
        _add(data.value[i]);
      // Out-of-line key
      } else {
        _add(data.value[i], data.key[i]);
      }
    }
  }
function ( storeName , value , key , cb ) { // For usage of out-of-line keys a `key` argument have to be specified, // otherwise the `request` will be made assuming in-line key or key generator. // For detailed possibilities see what you can't do in `DataError` section here: // `https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore.add#Exceptions` var data = { } ; if ( arguments . length === 4 ) { if ( ! Array . isArray ( key ) ) { data . key = [ key ] ; } else { data . key = key ; } } if ( arguments . length === 3 ) { cb = key ; key = null ; } if ( ! Array . isArray ( value ) ) { data . value = [ value ] ; } else { data . value = value ; } var result = [ ] ; var transaction = this . transaction ( storeName , MODE . READ_WRITE , result , cb ) ; var store = this . store ( storeName , transaction , cb ) ; var _add = function ( value , key ) { var request ; try { request = store . add ( value , key ) ; } catch ( err ) { if ( isFunction ( cb ) ) return cb ( err ) ; } request . onsuccess = function ( event ) { result . push ( event . target . result ) ; } ; request . onerror = function ( event ) { if ( isFunction ( cb ) ) return cb ( event . target . error ) ; } ; } ; for ( var i = 0 , l = data . value . length ; i < l ; i ++ ) { // In-line key if ( ! data . key ) { _add ( data . value [ i ] ) ; // Out-of-line key } else { _add ( data . value [ i ] , data . key [ i ] ) ; } } }
Add one or more records. If record already exist in object store,
returns an Error.

@param {String} storeName - name of the object store to use.
@param {Object|Object[]} value - Object or Array of objects to store.
@param {String|String[]} [key] - String or an Array of strings,
as a keys for the values.
If an Array is passed indexes have to be corresponding to the
indexes in values Array.
@param {Function} callback - gets two arguments `(err, result)`,
if there is no Error `err` is `null`. `result` is always an Array of keys
for the values added.
Add one or more records . If record already exist in object store returns an Error .