App-ProxyHunter-Model-Schema-Pg
view release on metacpan or search on metacpan
lib/App/ProxyHunter/Model/Schema/Pg.pm view on Meta::CPAN
package App::ProxyHunter::Model::Schema::Pg;
use Mo;
use Teng::Schema::Declare;
use DateTime::Format::Pg;
use App::ProxyHunter::Constants;
use App::ProxyHunter::Model::SchemaUtils qw'proxy_name_to_type proxy_type_to_name';
extends 'App::ProxyHunter::Model::Schema';
our $VERSION = '0.01';
sub perl_datetime_to_sql {
return unless defined $_[0];
DateTime::Format::Pg->format_datetime($_[0]);
}
sub sql_datetime_to_perl {
return unless defined $_[0];
DateTime::Format::Pg->parse_datetime($_[0])->set_time_zone(TZ);
}
sub perl_bool_to_sql {
if (ref $_[0]) {
return ${$_[0]} ? 't' : 'f';
}
$_[0] ? 't' : 'f';
}
table {
name 'proxy';
pk 'id';
columns qw(
id
host
port
checked
success_total
fails_total
insertdate
checkdate
speed_checkdate
fails
type
in_progress
conn_time
speed
);
inflate type => \&proxy_name_to_type;
deflate type => \&proxy_type_to_name;
deflate in_progress => \&perl_bool_to_sql;
for (qw/insertdate checkdate speed_checkdate/) {
inflate $_ => \&sql_datetime_to_perl;
deflate $_ => \&perl_datetime_to_sql;
}
};
1;
=pod
=head1 NAME
App::ProxyHunter::Model::Schema::Pg - PostgreSQL schema for App::ProxyHunter
=head1 SYNOPSIS
# just edit proxyhunter's config
db = {
driver: "Pg"
}
=head1 DESCRIPTION
You need to create database yourself, then use C<proxyhunter --create-schema> to create tables structure
=head1 SEE ALSO
( run in 1.010 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )