SQL::Translator ã® parser, producer ãç´æ¥ä½¿ã
ä½ãé »ç¹ã«ä½¿ãã¢ã¸ã¥ã¼ã«ã§ã¯ç¡ãã®ã§ã¡ã¢ã£ã¨ãã
#/usr/bin/perl use strict; use warnings; use Data::Dump qw(dump); use Perl6::Say; use SQL::Translator; my $dbh = DBI->connect("dbi:mysql:world", "root", ""); my $table = $dbh->selectrow_arrayref("show create table City;")->[1] . ";\n\n"; my $tr = SQL::Translator->new; $tr->parser("SQL::Translator::Parser::MySQL"); $tr->producer("SQL::Translator::Producer::YAML"); my $parser_output; eval { $parser_output = $tr->parser->($tr, $table); }; if ($@ || !$parser_output) { die(@_ || "no results"); } say dump($tr->schema); my $producer_output = $tr->producer->($tr); say $producer_output;
- show create table ã§å¾ãããçµæã« ";\n\n" ã¤ããªã㨠parse ã失æãã
- ãã以å¤ã¯ SQL::Translator->translate ã®å®è£ ãåèã«ãã
ã¨ãããããparse ããå¾ã«ã¯æåãã¦ãã° schema ãªãã¸ã§ã¯ãã«å±éãããã¹ãã¼ããã¼ã¿ãå«ã¾ãã¾ããproducer ã«éã㨠YAML 表ç¾ã«ãªãã¾ãã