LstuModel.pm 756 Bytes
Newer Older
Luc Didry's avatar
Luc Didry committed
1
# vim:set sw=4 ts=4 sts=4 ft=perl expandtab:
2
package LstuModel;
Luc Didry's avatar
Luc Didry committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
use Mojolicious;
use FindBin qw($Bin);
use File::Spec::Functions;

BEGIN {
    my $m = Mojolicious->new;
    our $config = $m->plugin('Config' =>
        {
            file    => catfile($Bin, '..' ,'lstu.conf'),
            default => {
                db_path => 'lstu.db'
            }
        }
    );
}
18 19 20

# Create database
use ORLite {
Luc Didry's avatar
Luc Didry committed
21
      file    => $config->{db_path},
22 23 24 25 26 27 28 29 30 31 32
      unicode => 1,
      create  => sub {
          my $dbh = shift;
          $dbh->do(
              'CREATE TABLE lstu (
               short     TEXT PRIMARY KEY,
               url       TEXT,
               counter   INTEGER,
               timestamp INTEGER)'
          );
          return 1;
Luc Didry's avatar
Luc Didry committed
33
     }
34 35 36
};

1;