QBit-Application-Model-DB-mysql
view release on metacpan or search on metacpan
lib/QBit/Application/Model/DB/mysql.pm view on Meta::CPAN
my $e = shift;
$e->{'text'} =~ /^Duplicate entry/
? throw Exception::DB::DuplicateEntry $e
: throw $e;
};
return $res;
}
sub kill_query {
my ($self, $query_id) = @_;
$self->_do("KILL QUERY $query_id");
}
sub _get_table_class {
my ($self, %opts) = @_;
my $table_class;
if (defined($opts{'type'})) {
my $try_class = "QBit::Application::Model::DB::mysql::Table::$opts{'type'}";
$table_class = $try_class if eval("require $try_class");
throw gettext('Unknown table class "%s"', $opts{'type'}) unless defined($table_class);
} else {
$table_class = 'QBit::Application::Model::DB::mysql::Table';
}
return $table_class;
}
sub _create_sql_db {
my ($self) = @_;
return
'CREATE DATABASE '
. $self->{'__DBH__'}{$$}->quote_identifier($self->get_option('database'))
. "\nDEFAULT CHARACTER SET UTF8;\n" . 'USE '
. $self->{'__DBH__'}{$$}->quote_identifier($self->get_option('database')) . ";\n\n";
}
sub _connect {
my ($self) = @_;
unless (defined($self->{'__DBH__'}{$$})) {
my $dsn = 'DBI:mysql:'
. join(
';', map {$_ . '=' . $self->get_option($_)}
grep {defined($self->get_option($_))} qw(database host port)
);
$self->{'__DBH__'}{$$} = DBI->connect(
$dsn,
$self->get_option('user', ''),
$self->get_option('password', ''),
{
PrintError => 0,
RaiseError => 0,
AutoCommit => 1,
mysql_auto_reconnect => 1,
mysql_enable_utf8 => 1,
},
) || throw DBI::errstr();
}
}
sub _is_connection_error {
my ($self, $code) = @_;
return in_array($code || 0, [2006, 2013]);
}
TRUE;
__END__
=encoding utf8
=head1 Name
QBit::Application::Model::DB::mysql - Class for working with MySQL DB.
=head1 Description
Class for working with MySQL DB. It's not ORM.
=head1 GitHub
https://github.com/QBitFramework/QBit-Application-Model-DB-mysql
=head1 Install
=over
=item *
cpanm QBit::Application::Model::DB::mysql
=item *
apt-get install libqbit-application-model-db-mysql-perl (http://perlhub.ru/)
=back
=head1 Package methods
=head2 filter
B<Arguments:>
=over
=item *
B<$filter> - filter (perl variables)
=item *
B<%opts> - additional options
=over
( run in 3.884 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )