SQL::Maker::Plugin::InsertMulti - insert multiple rows at once on MySQL
use SQL::Maker;
SQL::Maker->load_plugin('InsertMulti');
my $table = 'foo';
my @rows = ( +{ bar => 'baz', john => 'man' }, +{ bar => 'bee', john => 'row' } );
my $builder = SQL::Maker->new( driver => 'mysql' );
my ($sql, @binds);
### INSERT INTO `foo` (`bar`, `john`) VALUES (?, ?), (?, ?)
( $sql, @binds ) = $builder->insert_multi($table, \@rows);
( $sql, @binds ) = $builder->insert_multi($table, [qw/bar john/], [ map { @$_{qw/bar john/} } @rows ]);
### INSERT IGNORE `foo` (`bar`, `john`) VALUES (?, ?), (?, ?)
( $sql, @binds ) = $builder->insert_multi($table, [qw/bar john/], [ map { @$_{qw/bar john/} } @rows ], +{ prefix => 'INSERT IGNORE' });
### INSERT INTO `foo` (`bar`. `john`) VALUES (?, ?), (?, ?) ON DUPLICATE KEY UPDATE `bar` => ?
( $sql, @binds ) = $builder->insert_multi($table, \@rows, +{ update => +{ bar => 'updated' } });
( $sql, @binds ) = $builder->insert_multi($table, [qw/bar john/], [ map { @$_{qw/bar john/} } @rows ], +{ update => +{ bar => 'updated' } });
This is a plugin to generate MySQL's INSERT-multi statement.