Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 28 lines (22 sloc) 0.613 kb
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 26 27
use Bailador; Bailador::import;
use DBIish;

my $db = DBIish.connect('SQLite', database => 'blog.db');

sub get-articles {
    my $sth = $db.prepare: 'SELECT * FROM articles';
    $sth.execute;
    return $sth.fetchall_arrayref.map: {
        { title => $_[0],
          pubdate => $_[1],
          text => $_[2] }
    };
}

get '/' => sub {
    template 'index.tt', { articles => get-articles };
}

post '/post' => sub {
    my $p = request.params;
    my $sth = $db.prepare: 'INSERT INTO articles VALUES (?, datetime(?), ?)';
    $sth.execute($p<title>, DateTime.now.posix, $p<text>);
    "ok, done";
}

baile;
Something went wrong with that request. Please try again.