SQL::Abstract::Plugin::InsertMulti
ä½ã£ã¦ã¿ã¾ãããå ãã¿ã¯ MySQLにおけるbulk insert と bulk update - 金利0無利息キャッシング – キャッシングできます - subtech ã§ããbulk insert, bulk update *1 ãåºæ¥ã¾ãã
- SQL-Abstract-Plugin-InsertMulti-0.05 - add mysql bulk insert supports for SQL::Abstract - metacpan.org
- GitHub - zigorou/p5-sql-abstract-plugin-insertmulti: bulk insert and update support for SQL::Abstract
使ãæ¹ã¯é常ã«ç°¡åã§ãt/01_basic.t ã¨ãè¦ã¦é ããã¨ããåãããã¨æãã¾ãããããªæãã§ãã
use strict; use warnings; use Data::Dump qw(dump); use Perl6::Say; use SQL::Abstract; use SQL::Abstract::Plugin::InsertMulti; my $sql = SQL::Abstract->new; my ($stmt, @bind) = $sql->insert_multi( 'app_data', [qw/app_id guid name value created_on updated_on/], [ [1, 1, 'score', 100, \'UNIX_TIMESTAMP()', \'UNIX_TIMESTAMP()'], [1, 1, 'ranking', 3, \'UNIX_TIMESTAMP()', \'UNIX_TIMESTAMP()'], [1, 2, 'score', 200, \'UNIX_TIMESTAMP()', \'UNIX_TIMESTAMP()'], [1, 2, 'ranking', 2, \'UNIX_TIMESTAMP()', \'UNIX_TIMESTAMP()'], [1, 3, 'score', 300, \'UNIX_TIMESTAMP()', \'UNIX_TIMESTAMP()'], [1, 3, 'ranking', 1, \'UNIX_TIMESTAMP()', \'UNIX_TIMESTAMP()'], ], ); say dump($stmt, \@bind);
ã¨ãå®è¡ããã¨ã
( "INSERT INTO app_data ( app_id, guid, name, value, created_on, updated_on ) VALUES ( ?, ?, ?, ?, UNIX_TIMESTAMP(), UNIX_TIMESTAMP() ), ( ?, ?, ?, ?, UNIX_TIMESTAMP(), UNIX_TIMESTAMP() ), ( ?, ?, ?, ?, UNIX_TIMESTAMP(), UNIX_TIMESTAMP() ), ( ?, ?, ?, ?, UNIX_TIMESTAMP(), UNIX_TIMESTAMP() ), ( ?, ?, ?, ?, UNIX_TIMESTAMP(), UNIX_TIMESTAMP() ), ( ?, ?, ?, ?, UNIX_TIMESTAMP(), UNIX_TIMESTAMP() )", [ 1, 1, "score", 100, 1, 1, "ranking", 3, 1, 2, "score", 200, 1, 2, "ranking", 2, 1, 3, "score", 300, 1, 3, "ranking", 1, ], )
ã£ã¦æãã«ãªãã¾ãããã®å¾ããã« DBI ã® do ã«æ¸¡ããæãã§ããªã
å ã® id:mala ããã®å¥´ã®ã³ã¼ãã丸ã£ã¨ãã¯ãäºããå§ãããã§ãããçµå±å ¨é¨æ¸ãç´ãã¦ãã¾ãã¾ããã
- SQL::Abstract ã®å¤ã®å¤æ (ScalarRef ãªããªãã©ã«ã¨ãã¦æ±ãã¨ãããããã®) ãé©ç¨ãããããã«ç´ãã
- ON DUPLICATE KEY UPDATE 以ä¸ã®ãã©ã¡ã¼ã¿ã update() ã®æã®ãã©ã¡ã¼ã¿ã®ããã«è¨å®åºæ¥ãããã«ãã
- update_multi() ã®æã«ãå ã®ãã¼ã¿ã®ãã£ã¼ã«ããå ¨é¨é©ç¨ããã¡ããã®ãã¡ãã£ã¨å«ã ã£ãã®ã§ãé¤å¤æå®åºæ¥ãããã«ãã
- SQL::Abstract::LimitOffset 使ã£ã¦ã¦ããããç¶æ¿ãã¦ã奴ã ãã横æ§å ¥ãã¦é©ç¨åºæ¥ãããã«ãã
ã¨ãã§ãããã
ã¨ãããããã¼ãã«åã app_data ã£ã¦ã®ã«ç¹ã«æå³ã¯ããã¾ãããæªããããã
*1: ON DUPLICATE KEY UPDATE ãå©ç¨ãã INSERT