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)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Dancer + SQL::Translator
by mje (Curate) on Mar 27, 2012 at 14:03 UTC | |
by jeffa (Bishop) on Mar 27, 2012 at 15:31 UTC | |
by mje (Curate) on Mar 28, 2012 at 12:18 UTC | |
by mje (Curate) on Mar 28, 2012 at 16:18 UTC |