File Coverage

blib/lib/App/ProxyHunter/Model/Schema/SQLite.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package App::ProxyHunter::Model::Schema::SQLite;
2              
3 1     1   1935 use Mo;
  1         508  
  1         7  
4 1     1   1080 use Teng::Schema::Declare;
  1         57818  
  1         103  
5 1     1   3555 use DateTime;
  1         204927  
  1         35  
6 1     1   455 use App::ProxyHunter::Constants;
  0            
  0            
7             use App::ProxyHunter::Model::SchemaUtils qw'proxy_name_to_type proxy_type_to_name';
8             extends 'App::ProxyHunter::Model::Schema';
9              
10             our $VERSION = '0.01';
11              
12             sub perl_datetime_to_sql {
13             return unless defined $_[0];
14             $_[0]->epoch;
15             }
16              
17             sub sql_datetime_to_perl {
18             return unless defined $_[0];
19             DateTime->from_epoch(epoch => $_[0], time_zone => TZ);
20             }
21              
22             table {
23             name 'proxy';
24             pk 'id';
25             columns qw(
26             id
27             host
28             port
29             checked
30             success_total
31             fails_total
32             insertdate
33             checkdate
34             speed_checkdate
35             fails
36             type
37             in_progress
38             conn_time
39             speed
40             );
41            
42             inflate type => \&proxy_name_to_type;
43             deflate type => \&proxy_type_to_name;
44            
45             for (qw/insertdate checkdate speed_checkdate/) {
46             inflate $_ => \&sql_datetime_to_perl;
47             deflate $_ => \&perl_datetime_to_sql;
48             }
49             };
50              
51             1;
52              
53             =pod
54              
55             =head1 NAME
56              
57             App::ProxyHunter::Schema::Model::mysql - SQLite schema for App::ProxyHunter
58              
59             =head1 SYNOPSIS
60              
61             # just edit proxyhunter's config
62             db = {
63             driver: "SQLite"
64             }
65              
66             =head1 DESCRIPTION
67              
68             Use C<proxyhunter --create-schema> to create database and tables structure
69              
70             =head1 SEE ALSO
71              
72             L<App::ProxyHunter>
73              
74             =head1 AUTHOR
75              
76             Oleg G, E<lt>oleg@cpan.orgE<gt>
77              
78             =head1 COPYRIGHT AND LICENSE
79              
80             This library is free software; you can redistribute it and/or modify
81             it under the same terms as Perl itself
82              
83             =cut
84              
85             __DATA__
86             CREATE TABLE "proxy" (
87             "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
88             "host" TEXT NOT NULL,
89             "port" INTEGER NOT NULL,
90             "checked" INTEGER NOT NULL DEFAULT (0),
91             "success_total" INTEGER NOT NULL DEFAULT (0),
92             "fails_total" INTEGER NOT NULL DEFAULT (0),
93             "insertdate" INTEGER NOT NULL,
94             "checkdate" INTEGER NOT NULL DEFAULT (0),
95             "speed_checkdate" INTEGER NOT NULL DEFAULT (0),
96             "fails" INTEGER NOT NULL DEFAULT (0),
97             "type" TEXT NOT NULL DEFAULT ('DEAD_PROXY'),
98             "in_progress" INTEGER NOT NULL DEFAULT (0),
99             "conn_time" INTEGER DEFAULT ('NULL'),
100             "speed" INTEGER NOT NULL DEFAULT (0)
101             );
102             CREATE UNIQUE INDEX "proxy_uniq_idx" on proxy (host ASC, port ASC);
103             CREATE INDEX "type_idx" on proxy (type ASC);
104             CREATE INDEX "sort_idx" on proxy (checked ASC, checkdate ASC);