public
Created

  • Download Gist
geochart.pl
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#!/usr/bin/env perl
 
use Mojolicious::Lite;
use DBIx::Connector;
 
helper db => sub {
state $db = DBIx::Connector->connect("dbi:mysql:host=localhost;db=testdb", 'testuser', 'xxxsecret')
};
 
helper get_data => sub {
my $db = shift->db;
my $query = "SELECT country_name, count(id) as total from geo_data group by country_name";
my $data = $db->selectall_arrayref($query);
$_->[1] = int($_->[1]) foreach @$data;
unshift(@$data, ['Country', 'Attacks']);
return $data;
};
 
any '/' => sub {
my $c = shift;
my $data = $c->get_data;
$c->render( json => $data );
};
 
app->start;

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.