ä»å㯠Perl ã® O/Rãããã¼ Teng ã触ã£ã¦ã¿ã¾ããç¹ã«è§¦ããªãéãMySQLãå©ç¨ãã¦ããã¨ãããã¨ã«ãã¦ãã³ã¼ãã®ãµã³ãã«ã¯ DBå teng_test / å©ç¨ãããã¼ãã«ã¯ users / ãã®ãã¼ãã«ã¬ã¤ã¢ã¦ã㯠mysql> SHOW FIELDS FROM users; +---------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_
ãã¡ã Yappo ã®æ¥ã§ãããã¾ããã Yappo ã®å·çãã¼ã¹ãè³ãããªãã®ã§ãæ¬æ¥ã社å¡ã®ãªãªãµã¯ã代æã§ãDBIãããORMãã«ã¤ãã¦æ¸ããã¦é ãããã¨æãã¾ãã trigger / hook point insert, update, delete ã¯ã¨ãªã®åå¾å¦çãæ¡å¼µãã¦ãã¬ã³ã¼ãä½ææå»ã®è¨å®ã update æå»ã®æ´æ°ã¯ãã¾ãã¬ã³ã¼ãåé¤æã«åé¤ãã¼ãã«ã¸ã®èªåã³ãã¼çããä¸åº¦ãã¼ã¹ã¯ã©ã¹ä¸ã§å®ç¾©ãã¦ããã°æ°ããä½ããã¼ãã«ã¸ã use parent ããçãã¦ç°¡åã«é©ç¨åºæ¥ããããã«ä¾¿å©ã«ãªãã¾ããããã£ãããã¦ãã¨å¾ç¶ã®éçºè ãããã£ããå¶ç´ãåºã¦ãã¾ãã DBMS ã® trigger ORM ã®æ©è½ã® trigger ãå¤ç¨ãã¦ããã¨ãå¾ç¶ã¯ DBMS æ¬ä½ã® trigger ã使ãäºã«èºèºãã¾ãã使ã£ã¡ããããªãã¨ããããã§ã¯ãªãã§ãããããä¸ã¤ã®ã¯ã¨ãªã«å¯¾ããå¯
perlã§ãã¼ã¿ãã¼ã¹ã使ãæã«èª°ããå¿ ã使ãDBIããã®æ¥ç¶æã«ä½¿ãconnectã¡ã½ããã®ç¬¬4å¼æ°ã«è¨å®ãã¦ãããªãã·ã§ã³ããµã¼ãã¹ã«ããã¾ã¡ã¾ã¡ãªãã ãã©ãã ããéæ¿è¨å®ãæãã¦ãã ããã åã使ãã®ãã my $dbh = DBI->connect($dsn, $user, $password, { AutoCommit => 1, PrintError => 0, RaiseError => 1, ShowErrorStatement => 1, AutoInactiveDestroy => 1, }); ããã å ãã¦ãmysqlã§ããã° mysql_enable_utf8 => 1 mysql_auto_reconnect => 0, SQLiteã 㨠sqlite_unicode => 1 sqlite_use_immediate_transaction => 1 ã追å ã
å®éã°ã°ãã°æ£è§£ã¯ãã£ã±ãåºã¦ãããããã«èªåãã³ã¡ã³ãã§æ¸ãã¦ãããã¦ãã¾ããæ¸ãå¿ è¦ããªãããªã¨æã£ã¦ããã©ä¸å¿èªåã®ããã°ã§ãã¾ã¨ãã¦ããã¨ãããã¨ã§ã ä¸è¬çãªè§£ DBIx::Connectorã¨ãDBIx::Handlerçµç±ã§ããªãã$dbhãåå¾ãã¦ããDBIã使ãã ãããã¯fork-safeãªORM(DBIx::Class, DBIx::Skinny, Teng)ã使ãã DBIãç´æ¥ä½¿ã£ã¦ããå ´å ä¸è¬çãªã³ãã¯ã·ã§ã³ãä¿æããã¯ã©ã¤ã¢ã³ãã¨åæ§ã«DBIãforkããåä¾ã親ã®ã³ãã¯ã·ã§ã³ããã®ã¾ã¾ä½¿ããã¨ã¯ãã°ã®åå ã«ãªãã¾ããç¹ã«ãã©ã³ã¶ã¯ã·ã§ã³ã®å¦ççã§é大ãªåé¡ãèµ·ããå¯è½æ§ãããã 解決çã¯ã DBIã®ã³ãã¯ã·ã§ã³ã親ã§ä½ããªãã§ãåä¾ã§ç¬èªã«ä½ã 親ã§ä½ã£ã¦ãã¾ã£ãã³ãã¯ã·ã§ã³ãåä¾ãå®å ¨ã«DESTROYããåæ¥ç¶ãã ã®ã©ã¡ããã«ãªãã¾ããããã§åé¡ã¯2ã§
ã¡ãã£ã¨åã¾ã§ DBI ã§éåæã¢ã¯ã»ã¹ãªã¨ã³ããªãåæã§ä¸ãã£ã¦ãã¾ãããçããå¦ä½ãéããã§ããããï¼ ãã¦ã¨ãããæ´å²çãªçµç·¯ã¨ãæ´å²çãªçµç·¯ã¨ãã§ç DBI ç¸å½ã使ã£ã¦ãæ¹ããããªãã«ããã§ãããã奥ããã大äºãªäºãªãã§äºåº¦è¨ãã¾ãããï¼ DBI ã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ã£ã¦ã¾ããããªä½¿ããããç©ãããªããã§ããã工夫次第ã§åºæ¥ãäºãããã¾ãã ã¡ãªã¿ã«ãµã³ãã«ãã¼ã¿ãã¼ã¹ã¨ãã¦ãMySQL Documentation - Example Databases ã® world ãã¼ã¿ãã¼ã¹ã使ã£ã¦ãã¾ãã fetchall_arrayref ã§ãã¼ã¿æ´å½¢ ã¾ã以ä¸ã®ããã«ä½¿ã£ã¦ã¿ã¾ãã #!/usr/bin/perl use strict; use warnings; use Data::Dump qw(dump); use DBI; use Perl6::Say; my $dbh =
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}