I have recently discovered a fairly new project, Dancer and a fairly old one, SQL::Translator. The following code details a Dancer handler which, with the proper credentials supplied will translate the given database into either a text file which contains the create definitions to create a schema or a PNG file that contains an ER diagram of the schema. MySQL is the target database, but others should work as well.
use Dancer ':syntax'; use SQL::Translator; get '/render' => sub { my $db = params->{db}; my $format = params->{format} || 'text'; my $translator = SQL::Translator->new( from => 'DBI', to => 'MySQL', parser_args => { dsn => "dbi:mysql:$db", db_user => '', db_password => '', }, ); my $sql = $translator->translate( data => '' ); if ($format eq 'text') { content_type 'text'; return $sql; } elsif ($format eq 'png') { content_type 'png'; my $translator = SQL::Translator->new( from => 'MySQL', to => 'GraphViz', producer_args => { output_type => 'png', natural_join => 1, }, ); return $translator->translate( data => $sql ); } };
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
In reply to Dancer + SQL::Translator by jeffa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |