Skip to content

@jberger /geochart.pl
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#!/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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.