Create a gist now

Instantly share code, notes, and snippets.

#!/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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment