lib/dataset/actions.js
function (columns, values, opts, cb) {
            if (isFunction(opts)) {
                cb = opts;
                opts = null;
            }
            opts = opts || {};
            var ret, self = this;
            if (isInstanceOf(values, Dataset)) {
                ret = this.db.transaction(function () {
                    return self.insert(columns, values);
                });
            } else {

                if (!values.length) {
                    ret = new Promise().callback();
                } else if (!columns.length) {
                    throw new QueryError("Invalid columns in import");
                }

                var sliceSize = opts.commitEvery || opts.slice, result = [];
                if (sliceSize) {
                    ret = asyncArray(partition(values, sliceSize)).forEach(function (entries, offset) {
                        offset = (offset * sliceSize);
                        return self.db.transaction(opts, function () {
                            return when(self.multiInsertSql(columns, entries).map(function (st, index) {
                                return self.executeDui(st).chain(function (res) {
                                    result[offset + index] = res;
                                });
                            }));
                        });
                    }, 1);
                } else {
                    var statements = this.multiInsertSql(columns, values);
                    ret = this.db.transaction(function () {
                        return when(statements.map(function (st, index) {
                            return self.executeDui(st).chain(function (res) {
                                result[index] = res;
                            });
                        }));
                    });
                }
            }
            return ret.chain(function () {
                return flatten(result);
            }).classic(cb).promise();
        }
function (columns, values, opts, cb) {
            if (isFunction(opts)) {
                cb = opts;
                opts = null;
            }
            opts = opts || {};
            var ret, self = this;
            if (isInstanceOf(values, Dataset)) {
                ret = this.db.transaction(function () {
                    return self.insert(columns, values);
                });
            } else {

                if (!values.length) {
                    ret = new Promise().callback();
                } else if (!columns.length) {
                    throw new QueryError("Invalid columns in import");
                }

                var sliceSize = opts.commitEvery || opts.slice, result = [];
                if (sliceSize) {
                    ret = asyncArray(partition(values, sliceSize)).forEach(function (entries, offset) {
                        offset = (offset * sliceSize);
                        return self.db.transaction(opts, function () {
                            return when(self.multiInsertSql(columns, entries).map(function (st, index) {
                                return self.executeDui(st).chain(function (res) {
                                    result[offset + index] = res;
                                });
                            }));
                        });
                    }, 1);
                } else {
                    var statements = this.multiInsertSql(columns, values);
                    ret = this.db.transaction(function () {
                        return when(statements.map(function (st, index) {
                            return self.executeDui(st).chain(function (res) {
                                result[index] = res;
                            });
                        }));
                    });
                }
            }
            return ret.chain(function () {
                return flatten(result);
            }).classic(cb).promise();
        }
function ( columns , values , opts , cb ) { if ( isFunction ( opts ) ) { cb = opts ; opts = null ; } opts = opts || { } ; var ret , self = this ; if ( isInstanceOf ( values , Dataset ) ) { ret = this . db . transaction ( function ( ) { return self . insert ( columns , values ) ; } ) ; } else { if ( ! values . length ) { ret = new Promise ( ) . callback ( ) ; } else if ( ! columns . length ) { throw new QueryError ( "Invalid columns in import" ) ; } var sliceSize = opts . commitEvery || opts . slice , result = [ ] ; if ( sliceSize ) { ret = asyncArray ( partition ( values , sliceSize ) ) . forEach ( function ( entries , offset ) { offset = ( offset * sliceSize ) ; return self . db . transaction ( opts , function ( ) { return when ( self . multiInsertSql ( columns , entries ) . map ( function ( st , index ) { return self . executeDui ( st ) . chain ( function ( res ) { result [ offset + index ] = res ; } ) ; } ) ) ; } ) ; } , 1 ) ; } else { var statements = this . multiInsertSql ( columns , values ) ; ret = this . db . transaction ( function ( ) { return when ( statements . map ( function ( st , index ) { return self . executeDui ( st ) . chain ( function ( res ) { result [ index ] = res ; } ) ; } ) ) ; } ) ; } } return ret . chain ( function ( ) { return flatten ( result ) ; } ) . classic ( cb ) . promise ( ) ; }
Inserts multiple records into the associated table. This method can be
used to efficiently insert a large number of records into a table in a
single query if the database supports it. Inserts
are automatically wrapped in a transaction.

This method is called with a columns array and an array of value arrays:
<pre class="code">
// INSERT INTO table (x, y) VALUES (1, 2)
// INSERT INTO table (x, y) VALUES (3, 4)
DB.from("table").import(["x", "y"], [[1, 2], [3, 4]]).
</pre>

This method also accepts a dataset instead of an array of value arrays:

<pre class="code">
// INSERT INTO table (x, y) SELECT a, b FROM table2
DB.from("table").import(["x", "y"], DB.from("table2").select("a", "b"));
</pre>

The method also accepts a commitEvery option that specifies
the number of records to insert per transaction. This is useful especially
when inserting a large number of records, e.g.:

<pre class="code">
// this will commit every 50 records
DB.from("table").import(["x", "y"], [[1, 2], [3, 4], ...], {commitEvery : 50});
</pre>

@param {Array} columns The columns to insert values for.
This array will be used as the base for each values item in the values array.
@param {Array[Array]} values Array of arrays of values to insert into the columns.
@param {Object} [opts] options
@param {Number} [opts.commitEvery] the number of records to insert per transaction.
@param {Function} [cb] the callback to invoke when the action is done.

@return {comb.Promise} a promise that is resolved once all records have been inserted.
Inserts multiple records into the associated table . This method can be used to efficiently insert a large number of records into a table in a single query if the database supports it . Inserts are automatically wrapped in a transaction .