Skip to content
Newer
Older
100644 28 lines (22 sloc) 613 Bytes
4cacb2c @tadzik Initial commit
authored
1 use Bailador; Bailador::import;
2 use DBIish;
3
4 my $db = DBIish.connect('SQLite', database => 'blog.db');
5
6 sub get-articles {
7 my $sth = $db.prepare: 'SELECT * FROM articles';
8 $sth.execute;
9 return $sth.fetchall_arrayref.map: {
10 { title => $_[0],
11 pubdate => $_[1],
12 text => $_[2] }
13 };
14 }
15
16 get '/' => sub {
17 template 'index.tt', { articles => get-articles };
18 }
19
20 post '/post' => sub {
21 my $p = request.params;
22 my $sth = $db.prepare: 'INSERT INTO articles VALUES (?, datetime(?), ?)';
23 $sth.execute($p<title>, DateTime.now.posix, $p<text>);
24 "ok, done";
25 }
26
27 baile;
Something went wrong with that request. Please try again.