NAME
Mojo::MySQL5::Database - Database
SYNOPSIS
use Mojo::MySQL5::Database;
my $db = Mojo::MySQL5::Database->new(mysql => $mysql, connection => Mojo::MySQL5::Connection->new);
DESCRIPTION
Mojo::MySQL5::Database is a container for connections used by Mojo::MySQL5. Mojo::MySQL5::Database is based on Mojo::MySQL5::Database.
ATTRIBUTES
Mojo::MySQL5::Database implements the following attributes.
connection
my $c = $db->connection;
$db = $db->connection(Mojo::MySQL5::Connection->new);
Database connection used for all queries.
mysql
Mojo::MySQL5 object this database belongs to.
METHODS
Mojo::MySQL5::Database inherits all methods from Mojo::MySQL5::Database and implements the following ones.
backlog
my $num = $db->backlog;
Number of waiting non-blocking queries.
begin
my $tx = $db->begin;
Begin transaction and return Mojo::MySQL5::Transaction object, which will automatically roll back the transaction unless "commit" in Mojo::MySQL5::Transaction bas been called before it is destroyed.
my $tx = $db->begin;
$db->query('insert into names values (?)', 'Baerbel');
$db->query('insert into names values (?)', 'Wolfgang');
$tx->commit;
connect
$db->connect(Mojo::MySQL5::URL->new('mysql://user:password@host/db'));
Connect to MySQL server.
disconnect
$db->disconnect;
Disconnect database connection and prevent it from getting cached again.
pid
my $pid = $db->pid;
Return the connection id of the backend server process.
ping
my $bool = $db->ping;
Check database connection.
query
my $results = $db->query('select * from foo');
my $results = $db->query('insert into foo values (?, ?, ?)', @values);
Execute a blocking statement and return a Mojo::MySQL5::Results object with the results. You can also append a callback to perform operation non-blocking.
$db->query('select * from foo' => sub {
my ($db, $err, $results) = @_;
...
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;