line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::ProxyHunter::Model::Schema::Pg; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1779
|
use Mo; |
|
1
|
|
|
|
|
508
|
|
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
1160
|
use Teng::Schema::Declare; |
|
1
|
|
|
|
|
48249
|
|
|
1
|
|
|
|
|
106
|
|
5
|
1
|
|
|
1
|
|
994
|
use DateTime::Format::Pg; |
|
1
|
|
|
|
|
217122
|
|
|
1
|
|
|
|
|
10
|
|
6
|
1
|
|
|
1
|
|
499
|
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
|
|
|
|
|
|
|
DateTime::Format::Pg->format_datetime($_[0]); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub sql_datetime_to_perl { |
18
|
|
|
|
|
|
|
return unless defined $_[0]; |
19
|
|
|
|
|
|
|
DateTime::Format::Pg->parse_datetime($_[0])->set_time_zone(TZ); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub perl_bool_to_sql { |
23
|
|
|
|
|
|
|
if (ref $_[0]) { |
24
|
|
|
|
|
|
|
return ${$_[0]} ? 't' : 'f'; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$_[0] ? 't' : 'f'; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
table { |
31
|
|
|
|
|
|
|
name 'proxy'; |
32
|
|
|
|
|
|
|
pk 'id'; |
33
|
|
|
|
|
|
|
columns qw( |
34
|
|
|
|
|
|
|
id |
35
|
|
|
|
|
|
|
host |
36
|
|
|
|
|
|
|
port |
37
|
|
|
|
|
|
|
checked |
38
|
|
|
|
|
|
|
success_total |
39
|
|
|
|
|
|
|
fails_total |
40
|
|
|
|
|
|
|
insertdate |
41
|
|
|
|
|
|
|
checkdate |
42
|
|
|
|
|
|
|
speed_checkdate |
43
|
|
|
|
|
|
|
fails |
44
|
|
|
|
|
|
|
type |
45
|
|
|
|
|
|
|
in_progress |
46
|
|
|
|
|
|
|
conn_time |
47
|
|
|
|
|
|
|
speed |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
inflate type => \&proxy_name_to_type; |
51
|
|
|
|
|
|
|
deflate type => \&proxy_type_to_name; |
52
|
|
|
|
|
|
|
deflate in_progress => \&perl_bool_to_sql; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
for (qw/insertdate checkdate speed_checkdate/) { |
55
|
|
|
|
|
|
|
inflate $_ => \&sql_datetime_to_perl; |
56
|
|
|
|
|
|
|
deflate $_ => \&perl_datetime_to_sql; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
}; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=pod |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 NAME |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
App::ProxyHunter::Model::Schema::Pg - PostgreSQL schema for App::ProxyHunter |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 SYNOPSIS |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# just edit proxyhunter's config |
71
|
|
|
|
|
|
|
db = { |
72
|
|
|
|
|
|
|
driver: "Pg" |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 DESCRIPTION |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
You need to create database yourself, then use C<proxyhunter --create-schema> to create tables structure |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 SEE ALSO |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
L<App::ProxyHunter> |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 AUTHOR |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Oleg G, E<lt>oleg@cpan.orgE<gt> |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
90
|
|
|
|
|
|
|
it under the same terms as Perl itself |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__DATA__ |
95
|
|
|
|
|
|
|
CREATE TYPE proxy_type AS ENUM ('HTTPS_PROXY','HTTP_PROXY','CONNECT_PROXY','SOCKS4_PROXY','SOCKS5_PROXY','DEAD_PROXY'); |
96
|
|
|
|
|
|
|
CREATE TABLE proxy |
97
|
|
|
|
|
|
|
( |
98
|
|
|
|
|
|
|
id serial NOT NULL, |
99
|
|
|
|
|
|
|
host character varying(15) NOT NULL, |
100
|
|
|
|
|
|
|
port integer NOT NULL, |
101
|
|
|
|
|
|
|
checked boolean NOT NULL DEFAULT false, |
102
|
|
|
|
|
|
|
success_total integer NOT NULL DEFAULT 0, |
103
|
|
|
|
|
|
|
fails_total integer NOT NULL DEFAULT 0, |
104
|
|
|
|
|
|
|
insertdate timestamp without time zone NOT NULL, |
105
|
|
|
|
|
|
|
checkdate timestamp without time zone NOT NULL DEFAULT '1980-01-01 00:00:00'::timestamp without time zone, |
106
|
|
|
|
|
|
|
speed_checkdate timestamp without time zone NOT NULL DEFAULT '1980-01-01 00:00:00'::timestamp without time zone, |
107
|
|
|
|
|
|
|
fails smallint NOT NULL DEFAULT 0, |
108
|
|
|
|
|
|
|
type proxy_type NOT NULL DEFAULT 'DEAD_PROXY'::proxy_type, |
109
|
|
|
|
|
|
|
in_progress boolean NOT NULL DEFAULT false, |
110
|
|
|
|
|
|
|
conn_time integer DEFAULT NULL, |
111
|
|
|
|
|
|
|
speed integer NOT NULL DEFAULT 0, |
112
|
|
|
|
|
|
|
CONSTRAINT proxy_pk PRIMARY KEY (id), |
113
|
|
|
|
|
|
|
CONSTRAINT proxy_uniq UNIQUE (host, port) |
114
|
|
|
|
|
|
|
); |
115
|
|
|
|
|
|
|
CREATE INDEX sort_idx |
116
|
|
|
|
|
|
|
ON proxy |
117
|
|
|
|
|
|
|
USING btree |
118
|
|
|
|
|
|
|
(checked, checkdate); |
119
|
|
|
|
|
|
|
CREATE INDEX type_idx |
120
|
|
|
|
|
|
|
ON proxy |
121
|
|
|
|
|
|
|
USING btree |
122
|
|
|
|
|
|
|
(type); |