Skip to content

Commit

Permalink
For kritika.io
Browse files Browse the repository at this point in the history
  • Loading branch information
vanyabrovary committed Aug 2, 2017
1 parent 8ff95e8 commit fdffe8c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
4 changes: 3 additions & 1 deletion DB.pm
Expand Up @@ -11,7 +11,9 @@ BEGIN {
our @ISA = qw( Exporter );
our @EXPORT = qw( $db );
our $db = DBI->connect(
'DBI:mysql:database=' . $cfg->{DB}->{database_name} . ';hostname=' . $cfg->{DB}->{database_host},
'DBI:mysql:database=' .
$cfg->{DB}->{database_name} . ';hostname=' .
$cfg->{DB}->{database_host},
$cfg->{DB}->{database_user},
$cfg->{DB}->{database_pass}
);
Expand Down
23 changes: 16 additions & 7 deletions Model.pm
Expand Up @@ -41,7 +41,8 @@ sub list {

require $module;

my $h = $db->prepare( "SELECT " . $class->_id . " FROM " . $class->db_table() );
my $h = $db->prepare( "SELECT " . $class->_id .
" FROM " . $class->db_table() );
$h->execute();
my @b = ();

Expand All @@ -61,7 +62,10 @@ sub list_where {

require $module;

my $h = $db->prepare( "SELECT " . $class->_id . " FROM " . $class->db_table() . " WHERE $col = ?" );
my $h =
$db->prepare( "SELECT " . $class->_id .
" FROM " . $class->db_table() .
" WHERE $col = ?" );
$h->execute($val);
my @b = ();

Expand Down Expand Up @@ -109,7 +113,9 @@ sub _fetch_from_db {
my ( $cls, $col, $val ) = @_;

my $h = $db->prepare(
'SELECT ' . join( ',', $cls->db_columns() ) . ' FROM ' . $cls->db_table() . ' WHERE ' . $col . ' = ? ' );
'SELECT ' . join( ',', $cls->db_columns() ) .
' FROM ' . $cls->db_table() .
' WHERE ' . $col . ' = ? ' );
$h->execute($val);
my $obj = $h->fetchrow_hashref();

Expand Down Expand Up @@ -146,13 +152,16 @@ sub _store_in_db {

if ( $self->{ $self->_id } ) {

$q = 'UPDATE ' . $self->db_table . ' SET ' . join( ',', @keys ) . ' WHERE ' . $self->_id . ' = ?';
$q = 'UPDATE ' . $self->db_table .
' SET ' . join( ',', @keys ) .
' WHERE ' . $self->_id . ' = ?';
push @binds, $self->{ $self->_id };

}
else {

$q = 'INSERT ' . $self->db_table . ' SET ' . join( ',', @keys ) . ' ';
$q = 'INSERT ' . $self->db_table .
' SET ' . join( ',', @keys ) . ' ';

}

Expand Down Expand Up @@ -219,7 +228,7 @@ print $_->{some_field} foreach ( @{ Model::FeedFileStat->list() } )
=item * Read inner list.
foreach ( @{ Model::FeedFileStat->list() } ){
print Dumper($_) foreach ( @{ $_->gaps() } ); # if this method is implemented each row contain Model::FeedFileStatGaps
print Dumper($_) foreach ( @{ $_->gaps() } );
}
=item * Delete.
Expand All @@ -237,7 +246,7 @@ newid - return bad for MySQL.
=over 4
=item * _id
=item * _id
To finish smarter. It's fast fixme now
Expand Down
3 changes: 2 additions & 1 deletion Model/FeedFile.pm
Expand Up @@ -53,7 +53,8 @@ mobitrade.ua
=head1 COPYRIGHT AND LICENSE
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=head1 HISTORY
Expand Down
6 changes: 4 additions & 2 deletions Model/FeedFileStat.pm
Expand Up @@ -20,7 +20,8 @@ sub feed_file_stat_gaps() {
my $self = shift;

use Model::FeedFileStatGaps;
$self->{feed_file_stat_gaps} ||= Model::FeedFileStatGaps->list_where( $self->{id}, 'feed_file_stat_id' );
$self->{feed_file_stat_gaps}
||= Model::FeedFileStatGaps->list_where( $self->{id}, 'feed_file_stat_id' );
}

sub is_exists() {
Expand Down Expand Up @@ -68,7 +69,8 @@ mobitrade.ua
=head1 COPYRIGHT AND LICENSE
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
This is free software; you can redistribute it and/or modify
it under the same terms as the Perl 5 programming language system itself.
=head1 HISTORY
Expand Down
3 changes: 2 additions & 1 deletion Model/FeedFileStatGaps.pm
Expand Up @@ -54,7 +54,8 @@ mobitrade.ua
=head1 COPYRIGHT AND LICENSE
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=head1 HISTORY
Expand Down

0 comments on commit fdffe8c

Please sign in to comment.