Skip to content

Instantly share code, notes, and snippets.

@jberger
Created October 15, 2013 00:00
Show Gist options
  • Save jberger/6984421 to your computer and use it in GitHub Desktop.
Save jberger/6984421 to your computer and use it in GitHub Desktop.
#!/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