biblesearch / lib / Biblesearch.pm /
Newer Older
41 lines | 0.719kb
add files
Yuki Kimoto authored on 2014-03-26
1
package Biblesearch;
2

            
3
our $VERSION = '0.01';
4

            
5
use Mojo::Base 'Mojolicious';
6
use DBIx::Custom;
7

            
8
has 'dbi';
9

            
10
sub startup {
11
  my $self = shift;
12
  
13
  # DBI
14
  my $db_file = $self->home->rel_file('db/bible.db');
15
  my $dbi = DBIx::Custom->connect(
16
    dsn =>  "dbi:SQLite:dbname=$db_file",
17
    option => {sqlite_unicode => 1},
18
    connector => 1
19
  );
20
  $self->dbi($dbi);
21
  
22
  # Models
23
  my $models = [
24
    {
25
      table => 'book',
26
      primary_key => 'id'
27
    },
28
    {
29
      table => 'section',
30
      primary_key => [qw/book_id chapter section/]
31
    }
32
  ];
33
  $dbi->create_model($_) for @$models;
34
  
35
  # Route
36
  my $r = $self->routes;
37
  $r->get('/')->to(template => 'index');
38
  $r->get('/test')->to(template => 'test');
39
}
40

            
41
1;